New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

mobx-state-tree

Package Overview
Dependencies
Maintainers
3
Versions
129
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mobx-state-tree - npm Package Compare versions

Comparing version 3.2.4 to 3.3.0

4

dist/core/type/type-checker.d.ts

@@ -1,2 +0,2 @@

import { IAnyType } from "../../internal";
import { IAnyType, IType } from "../../internal";
export interface IContextEntry {

@@ -22,2 +22,2 @@ path: string;

*/
export declare function typecheck(type: IAnyType, value: any): void;
export declare function typecheck<C, S, T>(type: IType<C, S, T>, value: C | S | T): void;

@@ -19,2 +19,3 @@ import { IContext, IValidationResult, IStateTreeNode, ModelPrimitive } from "../../internal";

export interface IComplexType<C, S, T> extends IType<C, S, T> {
readonly $complexType: undefined;
create(snapshot?: C, environment?: any): TAndInterface<T, {

@@ -21,0 +22,0 @@ toJSON?(): S;

@@ -1,1 +0,1 @@

!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("mobx")):"function"==typeof define&&define.amd?define(["exports","mobx"],e):e(t.mobxStateTree={},t.mobx)}(this,function(t,l){"use strict";var r=function(t,e){return(r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(t,e)};function a(t,e){function n(){this.constructor=t}r(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}var i=function(){return(i=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var i in e=arguments[n])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t}).apply(this,arguments)};function n(t,e,n,r){var i,o=arguments.length,a=o<3?e:null===r?r=Object.getOwnPropertyDescriptor(e,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(t,e,n,r);else for(var s=t.length-1;0<=s;s--)(i=t[s])&&(a=(o<3?i(a):3<o?i(e,n,a):i(e,n))||a);return 3<o&&a&&Object.defineProperty(e,n,a),a}function u(t){return J(t).type}function o(t,e){return J(t).onPatch(e)}function s(t,e){J(t).applyPatches(ot(e))}function p(t,e){return J(t).applySnapshot(e)}function c(t){return J(t).root.storedValue}function h(t,e){var n=B(J(t),e,!1);if(void 0!==n)try{return n.value}catch(t){return}}function f(t,e){var n=J(t);n.getChildren().forEach(function(t){W(t.storedValue)&&f(t.storedValue,e)}),e(n.storedValue)}var d=function(){function t(t,e,n,r,i){this.parent=null,this.subpath="",this.state=F.INITIALIZING,this._environment=void 0,this._initialSnapshot=i,this.type=t,this.parent=e,this.subpath=n;var o=!0;try{this.storedValue=t.createNewInstance(this,{},i),this.state=F.CREATED,o=!1}finally{o&&(this.state=F.DEAD)}}return Object.defineProperty(t.prototype,"path",{get:function(){return this.parent?this.parent.path+"/"+yt(this.subpath):""},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"isRoot",{get:function(){return null===this.parent},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"root",{get:function(){return this.parent?this.parent.root:et("This scalar node is not part of a tree")},enumerable:!0,configurable:!0}),t.prototype.setParent=function(t,e){if(void 0===e&&(e=null),this.parent!==t||this.subpath!==e)if(this.parent&&!t)this.die();else{var n=null===e?"":e;this.subpath!==n&&(this.subpath=n),t&&t!==this.parent&&(this.parent=t)}},Object.defineProperty(t.prototype,"value",{get:function(){return this.type.getValue(this)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"snapshot",{get:function(){return pt(this.getSnapshot())},enumerable:!0,configurable:!0}),t.prototype.getSnapshot=function(){return this.type.getSnapshot(this)},Object.defineProperty(t.prototype,"isAlive",{get:function(){return this.state!==F.DEAD},enumerable:!0,configurable:!0}),t.prototype.toString=function(){return this.type.name+"@"+(this.path||"<root>")+(this.isAlive?"":"[dead]")},t.prototype.die=function(){this.state=F.DEAD},t}(),y=1,e="warn";var v,b,g={onError:function(t){throw t}},m=function(){function r(t,e,n,r,i){this.nodeId=++y,this.subpathAtom=l.createAtom("path"),this.subpath="",this.parent=null,this.state=F.INITIALIZING,this.isProtectionEnabled=!0,this.middlewares=null,this._autoUnbox=!0,this._environment=void 0,this._isRunningAction=!1,this._hasSnapshotReaction=!1,this._disposers=null,this._patchSubscribers=null,this._snapshotSubscribers=null,this._observableInstanceCreated=!1,this._cachedInitialSnapshot=null,this._environment=r,this._initialSnapshot=pt(i),this.type=t,this.parent=e,this.subpath=n,this.escapedSubpath=yt(this.subpath),this.identifierAttribute=t.identifierAttribute,this.identifier=this.identifierAttribute&&this._initialSnapshot?""+this._initialSnapshot[this.identifierAttribute]:null,e||(this.identifierCache=new H),this._childNodes=t.initializeChildNodes(this,this._initialSnapshot),e?e.root.identifierCache.addNodeToCache(this):this.identifierCache.addNodeToCache(this)}return r.prototype.applyPatches=function(t){this._observableInstanceCreated||this._createObservableInstance(),this.applyPatches(t)},r.prototype.applySnapshot=function(t){this._observableInstanceCreated||this._createObservableInstance(),this.applySnapshot(t)},r.prototype._createObservableInstance=function(){var t=this.type;this.storedValue=t.createNewInstance(this,this._childNodes,this._initialSnapshot),this.preboot();var e,n,r=!0;this._observableInstanceCreated=!0;try{this._isRunningAction=!0,t.finalizeNewInstance(this,this.storedValue),this._isRunningAction=!1,this.fireHook("afterCreate"),this.state=F.CREATED,r=!1}finally{r&&(this.state=F.DEAD)}e=this,n="snapshot",l.getAtom(e,n).trackAndCompute(),this.isRoot&&this._addSnapshotReaction(),this.finalizeCreation(),this._childNodes=X},Object.defineProperty(r.prototype,"path",{get:function(){return this.subpathAtom.reportObserved(),this.parent?this.parent.path+"/"+this.escapedSubpath:""},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"root",{get:function(){var t=this.parent;return t?t.root:this},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"isRoot",{get:function(){return null===this.parent},enumerable:!0,configurable:!0}),r.prototype.setParent=function(t,e){if(void 0===e&&(e=null),this.parent!==t||this.subpath!==e)if(this.parent&&!t)this.die();else{var n=null===e?"":e;this.subpath!==n&&(this.subpath=n,this.escapedSubpath=yt(this.subpath),this.subpathAtom.reportChanged()),t&&t!==this.parent&&(t.root.identifierCache.mergeCache(this),this.parent=t,this.subpathAtom.reportChanged(),this.fireHook("afterAttach"))}},r.prototype.fireHook=function(t){var e=this.storedValue&&"object"==typeof this.storedValue&&this.storedValue[t];"function"==typeof e&&e.apply(this.storedValue)},Object.defineProperty(r.prototype,"value",{get:function(){if(this._observableInstanceCreated||this._createObservableInstance(),this.isAlive)return this.type.getValue(this)},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"snapshot",{get:function(){if(this.isAlive)return pt(this.getSnapshot())},enumerable:!0,configurable:!0}),r.prototype.getSnapshot=function(){if(this.isAlive)return this._observableInstanceCreated?this._getActualSnapshot():this._getInitialSnapshot()},r.prototype._getActualSnapshot=function(){return this.type.getSnapshot(this)},r.prototype._getInitialSnapshot=function(){if(this.isAlive){if(!this._initialSnapshot)return this._initialSnapshot;if(this._cachedInitialSnapshot)return this._cachedInitialSnapshot;var t=this.type,e=this._childNodes,n=this._initialSnapshot;return this._cachedInitialSnapshot=t.processInitialSnapshot(e,n),this._cachedInitialSnapshot}},r.prototype.isRunningAction=function(){return!!this._isRunningAction||!this.isRoot&&this.parent.isRunningAction()},Object.defineProperty(r.prototype,"isAlive",{get:function(){return this.state!==F.DEAD},enumerable:!0,configurable:!0}),r.prototype.assertAlive=function(){if(!this.isAlive){var t="[mobx-state-tree][error] You are trying to read or write to an object that is no longer part of a state tree. (Object type was '"+this.type.name+"'). Either detach nodes first, or don't use objects after removing / replacing them in the tree.";switch(e){case"error":throw new Error(t);case"warn":console.warn(t+' Use setLivelynessChecking("error") to simplify debugging this error.')}}},r.prototype.getChildNode=function(t){this.assertAlive(),this._autoUnbox=!1;try{return this._observableInstanceCreated?this.type.getChildNode(this,t):this._childNodes[t]}finally{this._autoUnbox=!0}},r.prototype.getChildren=function(){this.assertAlive(),this._autoUnbox=!1;try{return this._observableInstanceCreated?this.type.getChildren(this):q(this._childNodes)}finally{this._autoUnbox=!0}},r.prototype.getChildType=function(t){return this.type.getChildType(t)},Object.defineProperty(r.prototype,"isProtected",{get:function(){return this.root.isProtectionEnabled},enumerable:!0,configurable:!0}),r.prototype.assertWritable=function(){this.assertAlive(),!this.isRunningAction()&&this.isProtected&&et("Cannot modify '"+this+"', the object is protected and can only be modified by using an action.")},r.prototype.removeChild=function(t){this.type.removeChild(this,t)},r.prototype.unbox=function(t){return t&&t.parent&&t.parent.assertAlive(),t&&t.parent&&t.parent._autoUnbox?t.value:t},r.prototype.toString=function(){var t=this.identifier?"(id: "+this.identifier+")":"";return this.type.name+"@"+(this.path||"<root>")+t+(this.isAlive?"":"[dead]")},r.prototype.finalizeCreation=function(){if(this.state===F.CREATED){if(this.parent){if(this.parent.state!==F.FINALIZED)return;this.fireHook("afterAttach")}this.state=F.FINALIZED;for(var t=0,e=this.getChildren();t<e.length;t++){var n=e[t];n instanceof r&&n.finalizeCreation()}}},r.prototype.detach=function(){this.isAlive||et("Error while detaching, node is not alive."),this.isRoot||(this.fireHook("beforeDetach"),this._environment=this.root._environment,this.state=F.DETACHING,this.identifierCache=this.root.identifierCache.splitCache(this),this.parent.removeChild(this.subpath),this.parent=null,this.subpath=this.escapedSubpath="",this.subpathAtom.reportChanged(),this.state=F.FINALIZED)},r.prototype.preboot=function(){var n=this;this.applyPatches=O(this.storedValue,"@APPLY_PATCHES",function(t){t.forEach(function(t){var e=gt(t.path);K(n,e.slice(0,-1)).applyPatchLocally(e[e.length-1],t)})}),this.applySnapshot=O(this.storedValue,"@APPLY_SNAPSHOT",function(t){if(t!==n.snapshot)return n.type.applySnapshot(n,t)}),ct(this.storedValue,"$treenode",this),ct(this.storedValue,"toJSON",Y)},r.prototype.die=function(){this.state!==F.DETACHING&&W(this.storedValue)&&(f(this.storedValue,function(t){var e=J(t);e instanceof r&&e.aboutToDie()}),f(this.storedValue,function(t){var e=J(t);e instanceof r&&e.finalizeDeath()}))},r.prototype.aboutToDie=function(){this._disposers&&(this._disposers.forEach(function(t){return t()}),this._disposers=null),this.fireHook("beforeDestroy")},r.prototype.finalizeDeath=function(){var t,e,n;this.root.identifierCache.notifyDied(this),e="snapshot",n=(t=this).snapshot,Object.defineProperty(t,e,{enumerable:!0,writable:!1,configurable:!0,value:n}),this._patchSubscribers&&(this._patchSubscribers=null),this._snapshotSubscribers&&(this._snapshotSubscribers=null),this.state=F.DEAD,this.subpath=this.escapedSubpath="",this.parent=null,this.subpathAtom.reportChanged()},r.prototype.onSnapshot=function(t){return this._addSnapshotReaction(),this._snapshotSubscribers||(this._snapshotSubscribers=[]),lt(this._snapshotSubscribers,t)},r.prototype.emitSnapshot=function(e){this._snapshotSubscribers&&this._snapshotSubscribers.forEach(function(t){return t(e)})},r.prototype.onPatch=function(t){return this._patchSubscribers||(this._patchSubscribers=[]),lt(this._patchSubscribers,t)},r.prototype.emitPatch=function(t,e){var n=this._patchSubscribers;if(n&&n.length){var r=function(t){"oldValue"in t||et("Patches without `oldValue` field cannot be inversed");return[function(t){switch(t.op){case"add":return{op:"add",path:t.path,value:t.value};case"remove":return{op:"remove",path:t.path};case"replace":return{op:"replace",path:t.path,value:t.value}}}(t),function(t){switch(t.op){case"add":return{op:"remove",path:t.path};case"remove":return{op:"add",path:t.path,value:t.oldValue};case"replace":return{op:"replace",path:t.path,value:t.oldValue}}}(t)]}(function(t){for(var e=[],n=1;n<arguments.length;n++)e[n-1]=arguments[n];for(var r=0;r<e.length;r++){var i=e[r];for(var o in i)t[o]=i[o]}return t}({},t,{path:e.path.substr(this.path.length)+"/"+t.path})),i=r[0],o=r[1];n.forEach(function(t){return t(i,o)})}this.parent&&this.parent.emitPatch(t,e)},r.prototype.addDisposer=function(t){this._disposers?this._disposers.unshift(t):this._disposers=[t]},r.prototype.removeMiddleware=function(e){this.middlewares&&(this.middlewares=this.middlewares.filter(function(t){return t.handler!==e}))},r.prototype.addMiddleWare=function(t,e){var n=this;return void 0===e&&(e=!0),this.middlewares?this.middlewares.push({handler:t,includeHooks:e}):this.middlewares=[{handler:t,includeHooks:e}],function(){n.removeMiddleware(t)}},r.prototype.applyPatchLocally=function(t,e){this.assertWritable(),this._observableInstanceCreated||this._createObservableInstance(),this.type.applyPatchLocally(this,t,e)},r.prototype._addSnapshotReaction=function(){var e=this;if(!this._hasSnapshotReaction){var t=l.reaction(function(){return e.snapshot},function(t){return e.emitSnapshot(t)},g);this.addDisposer(t),this._hasSnapshotReaction=!0}},n([l.action],r.prototype,"_createObservableInstance",null),n([l.computed],r.prototype,"snapshot",null),n([l.action],r.prototype,"detach",null),n([l.action],r.prototype,"die",null),r}();(b=v||(v={}))[b.String=1]="String",b[b.Number=2]="Number",b[b.Boolean=4]="Boolean",b[b.Date=8]="Date",b[b.Literal=16]="Literal",b[b.Array=32]="Array",b[b.Map=64]="Map",b[b.Object=128]="Object",b[b.Frozen=256]="Frozen",b[b.Optional=512]="Optional",b[b.Reference=1024]="Reference",b[b.Identifier=2048]="Identifier",b[b.Late=4096]="Late",b[b.Refinement=8192]="Refinement",b[b.Union=16384]="Union",b[b.Null=32768]="Null",b[b.Undefined=65536]="Undefined",b[b.Integer=131072]="Integer";var A=function(){function t(t){this.isType=!0,this.name=t}return t.prototype.create=function(t,e){return void 0===t&&(t=this.getDefaultSnapshot()),this.instantiate(null,"",e,t).value},t.prototype.initializeChildNodes=function(t,e){return X},t.prototype.createNewInstance=function(t,e,n){return n},t.prototype.finalizeNewInstance=function(t,e){},t.prototype.processInitialSnapshot=function(t,e){return e},t.prototype.isAssignableFrom=function(t){return t===this},t.prototype.validate=function(t,e){return W(t)?u(t)===this||this.isAssignableFrom(u(t))?k():z(e,t):this.isValidSnapshot(t,e)},t.prototype.is=function(t){return 0===this.validate(t,[{path:"",type:this}]).length},t.prototype.reconcile=function(t,e){if(t.snapshot===e)return t;if(W(e)&&J(e)===t)return t;if(t.type===this&&st(e)&&!W(e)&&(!t.identifierAttribute||t.identifier===""+e[t.identifierAttribute]))return t.applySnapshot(e),t;var n=t.parent,r=t.subpath;if(t.die(),W(e)&&this.isAssignableFrom(u(e))){var i=J(e);return i.setParent(n,r),i}return this.instantiate(n,r,t._environment,e)},Object.defineProperty(t.prototype,"Type",{get:function(){return et("Factory.Type should not be actually called. It is just a Type signature that can be used at compile time with Typescript, by using `typeof type.Type`")},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"SnapshotType",{get:function(){return et("Factory.SnapshotType should not be actually called. It is just a Type signature that can be used at compile time with Typescript, by using `typeof type.SnapshotType`")},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"CreationType",{get:function(){return et("Factory.CreationType should not be actually called. It is just a Type signature that can be used at compile time with Typescript, by using `typeof type.CreationType`")},enumerable:!0,configurable:!0}),n([l.action],t.prototype,"create",null),t}(),w=function(e){function t(t){return e.call(this,t)||this}return a(t,e),t.prototype.getValue=function(t){return t.storedValue},t.prototype.getSnapshot=function(t){return t.storedValue},t.prototype.getDefaultSnapshot=function(){},t.prototype.applySnapshot=function(t,e){et("Immutable types do not support applying snapshots")},t.prototype.applyPatchLocally=function(t,e,n){et("Immutable types do not support applying patches")},t.prototype.getChildren=function(t){return Q},t.prototype.getChildNode=function(t,e){return et("No child '"+e+"' available in type: "+this.name)},t.prototype.getChildType=function(t){return et("No child '"+t+"' available in type: "+this.name)},t.prototype.reconcile=function(t,e){if(t.type===this&&t.storedValue===e)return t;var n=this.instantiate(t.parent,t.subpath,t._environment,e);return t.die(),n},t.prototype.removeChild=function(t,e){return et("No child '"+e+"' available in type: "+this.name)},t}(A);function S(t){return"object"==typeof t&&t&&!0===t.isType}var P=new Map;function V(t){return{$MST_UNSERIALIZABLE:!0,type:t}}function _(e,t){l.runInAction(function(){ot(t).forEach(function(t){return function(t,e){var n=h(t,e.path||"");if(!n)return et("Invalid action path: "+(e.path||""));var r=J(n);if("@APPLY_PATCHES"===e.name)return s.call(null,n,e.args[0]);if("@APPLY_SNAPSHOT"===e.name)return p.call(null,n,e.args[0]);"function"!=typeof n[e.name]&&et("Action '"+e.name+"' does not exist in '"+r.path+"'");return n[e.name].apply(n,e.args?e.args.map(function(t){return(e=t)&&"object"==typeof e&&"$MST_DATE"in e?new Date(e.$MST_DATE):e;var e}):[])}(e,t)})})}function T(o,a,s){return void 0===s&&(s=!1),E(o,function(n,t){if("action"===n.type&&n.id===n.rootId){var e=J(n.context),r={name:n.name,path:G(J(o),e),args:n.args.map(function(t,e){return function(t,e,n,r){if(r instanceof Date)return{$MST_DATE:r.getTime()};if(ut(r))return r;if(W(r))return V("[MSTNode: "+u(r).name+"]");if("function"==typeof r)return V("[function]");if("object"==typeof r&&!at(r)&&!it(r))return V("[object "+(r&&r.constructor&&r.constructor.name||"Complex Object")+"]");try{return JSON.stringify(r),r}catch(t){return V(""+t)}}(0,n.name,0,t)})};if(s){var i=t(n);return a(r),i}return a(r),t(n)}return t(n)})}var N=1,C=null;function I(){return N++}function j(t,e){var n=J(t.context),r=n._isRunningAction,i=C;"action"===t.type&&n.assertAlive(),n._isRunningAction=!0,C=t;try{return function(t,e,s){var u=function(t,e,n){var r=n.$mst_middleware||Q,i=t;for(;i;)i.middlewares&&(r=r.concat(i.middlewares)),i=i.parent;return r}(t,0,s);if(!u.length)return l.action(s).apply(null,e.args);var p=0,c=null;return function n(t){var e=u[p++];var r=e&&e.handler;function i(t,e){c=e?e(n(t)||c):n(t)}function o(t){c=t}var a=function(){return r(t,i,o),c};return r&&e.includeHooks?a():r&&!e.includeHooks?Ct[t.name]?n(t):a():l.action(s).apply(null,t.args)}(e)}(n,t,e)}finally{C=i,n._isRunningAction=r}}function O(e,n,r){var t=function(){var t=I();return j({type:"action",name:n,id:t,args:ht(arguments),context:e,tree:c(e),rootId:C?C.rootId:t,parentId:C?C.id:0},r)};return t._isMSTAction=!0,t}function E(t,e,n){return void 0===n&&(n=!0),J(t).addMiddleWare(e,n)}function D(t){return"function"==typeof t?"<function"+(t.name?" "+t.name:"")+">":W(t)?"<"+t+">":"`"+function(t){try{return JSON.stringify(t)}catch(t){return"<Unserializable: "+t+">"}}(t)+"`"}function x(t){var e=t.value,n=t.context[t.context.length-1].type,r=t.context.map(function(t){return t.path}).filter(function(t){return 0<t.length}).join("/"),i=0<r.length?'at path "/'+r+'" ':"",o=W(e)?"value of type "+J(e).type.name+":":ut(e)?"value":"snapshot",a=n&&W(e)&&n.is(J(e).snapshot);return""+i+o+" "+D(e)+" is not assignable "+(n?"to type: `"+n.name+"`":"")+(t.message?" ("+t.message+")":"")+(n?Jt(n)||ut(e)?".":", expected an instance of `"+n.name+"` or a snapshot like `"+n.describe()+"` instead."+(a?" (Note that a snapshot of the provided value is compatible with the targeted type)":""):".")}function R(t,e,n){return t.concat([{path:e,type:n}])}function k(){return Q}function z(t,e,n){return[{context:t,value:e,message:n}]}function M(t){return t.reduce(function(t,e){return t.concat(e)},[])}function L(t,e){var n,r=t.validate(e,[{path:"",type:t}]);0<r.length&&et("Error while converting "+((n=D(e)).length<280?n:n.substring(0,272)+"......"+n.substring(n.length-8))+" to `"+t.name+"`:\n\n "+r.map(x).join("\n "))}var F,U,H=function(){function e(){this.cache=l.observable.map()}return e.prototype.addNodeToCache=function(t){if(t.identifierAttribute){var e=t.identifier;this.cache.has(e)||this.cache.set(e,l.observable.array([],tt));var n=this.cache.get(e);-1!==n.indexOf(t)&&et("Already registered"),n.push(t)}return this},e.prototype.mergeCache=function(t){var e=this;l.values(t.identifierCache.cache).forEach(function(t){return t.forEach(function(t){e.addNodeToCache(t)})})},e.prototype.notifyDied=function(t){if(t.identifierAttribute){var e=this.cache.get(t.identifier);e&&e.remove(t)}},e.prototype.splitCache=function(t){var n=new e,r=t.path;return l.values(this.cache).forEach(function(t){for(var e=t.length-1;0<=e;e--)0===t[e].path.indexOf(r)&&(n.addNodeToCache(t[e]),t.splice(e,1))}),n},e.prototype.resolve=function(e,t){var n=this.cache.get(""+t);if(!n)return null;var r=n.filter(function(t){return e.isAssignableFrom(t.type)});switch(r.length){case 0:return null;case 1:return r[0];default:return et("Cannot resolve a reference to type '"+e.name+"' with id: '"+t+"' unambigously, there are multiple candidates: "+r.map(function(t){return t.path}).join(", "))}},e}();function $(t,e,n,r,i){var o,a=(o=i)&&o.$treenode||null;if(a){if(a.isRoot)return a.setParent(e,n),a;et("Cannot add an object to a state tree if it is already part of the same or another state tree. Tried to assign an object to '"+(e?e.path:"")+"/"+n+"', but it lives already at '"+a.path+"'")}return new(t.shouldAttachNode?m:d)(t,e,n,r,i)}function W(t){return!(!t||!t.$treenode)}function J(t){return W(t)?t.$treenode:et("Value "+t+" is no MST Node")}function Y(){return J(this).snapshot}(U=F||(F={}))[U.INITIALIZING=0]="INITIALIZING",U[U.CREATED=1]="CREATED",U[U.FINALIZED=2]="FINALIZED",U[U.DETACHING=3]="DETACHING",U[U.DEAD=4]="DEAD";var Z=function(t){return".."};function G(t,e){t.root!==e.root&&et("Cannot calculate relative path: objects '"+t+"' and '"+e+"' are not part of the same object tree");for(var n=gt(t.path),r=gt(e.path),i=0;i<n.length&&n[i]===r[i];i++);return n.slice(i).map(Z).join("/")+bt(r.slice(i))}function B(t,e,n){return void 0===n&&(n=!0),K(t,gt(e),n)}function K(t,e,n){void 0===n&&(n=!0);for(var r=t,i=0;i<e.length;i++){var o=e[i];if(""!==o){if(".."===o){if(r=r.parent)continue}else{if("."===o||""===o)continue;if(r){if(r instanceof d)try{var a=r.value;W(a)&&(r=J(a))}catch(t){if(!n)return;throw t}if(r instanceof m)if(r.getChildType(o)&&(r=r.getChildNode(o)))continue}}return n?et("Could not resolve '"+o+"' in path '"+(bt(e.slice(0,i))||"/")+"' while resolving '"+bt(e)+"'"):void 0}r=r.root}return r}function q(n){if(!n)return Q;var t=Object.keys(n);if(!t.length)return Q;var r=new Array(t.length);return t.forEach(function(t,e){r[e]=n[t]}),r}var Q=Object.freeze([]),X=Object.freeze({}),tt="string"==typeof l.$mobx?{deep:!1}:{deep:!1,proxy:!1};function et(t){throw void 0===t&&(t="Illegal state"),new Error("[mobx-state-tree] "+t)}function nt(t){return t}Object.freeze(tt);var rt=Number.isInteger||function(t){return"number"==typeof t&&isFinite(t)&&Math.floor(t)===t};function it(t){return!(!Array.isArray(t)&&!l.isObservableArray(t))}function ot(t){return t?it(t)?t:[t]:Q}function at(t){if(null===t||"object"!=typeof t)return!1;var e=Object.getPrototypeOf(t);return e===Object.prototype||null===e}function st(t){return!(null===t||"object"!=typeof t||t instanceof Date||t instanceof RegExp)}function ut(t){return null==t||("string"==typeof t||"number"==typeof t||"boolean"==typeof t||t instanceof Date)}function pt(t){return t}function ct(t,e,n){Object.defineProperty(t,e,{enumerable:!1,writable:!1,configurable:!0,value:n})}function lt(r,i){return r.push(i),function(){var t,e,n;e=i,-1!==(n=(t=r).indexOf(e))&&t.splice(n,1)}}function ht(t){for(var e=new Array(t.length),n=0;n<t.length;n++)e[n]=t[n];return e}var ft=function(t,e){};function dt(t){return l=t.name,h=t,f=function(){var s=I(),u=C||et("Not running an action!"),p=arguments;function c(t,e,n){t.$mst_middleware=f.$mst_middleware,j({name:l,type:e,id:s,args:[n],tree:u.tree,context:u.context,parentId:u.id,rootId:u.rootId},t)}return new Promise(function(e,n){var r,t=function(){r=h.apply(null,arguments),i(void 0)};function i(t){var e;try{c(function(t){e=r.next(t)},"flow_resume",t)}catch(e){return void setImmediate(function(){c(function(t){n(e)},"flow_throw",e)})}a(e)}function o(t){var e;try{c(function(t){e=r.throw(t)},"flow_resume_error",t)}catch(e){return void setImmediate(function(){c(function(t){n(e)},"flow_throw",e)})}a(e)}function a(t){if(!t.done)return t.value&&"function"==typeof t.value.then||et("Only promises can be yielded to `async`, got: "+t),t.value.then(i,o);setImmediate(function(){c(function(t){e(t)},"flow_return",t.value)})}t.$mst_middleware=f.$mst_middleware,j({name:l,type:"flow_spawn",id:s,args:ht(p),tree:u.tree,context:u.context,parentId:u.id,rootId:u.rootId},t)})};var l,h,f}function yt(t){return!0==("number"==typeof t)?""+t:t.replace(/~/g,"~1").replace(/\//g,"~0")}function vt(t){return t.replace(/~0/g,"/").replace(/~1/g,"~")}function bt(t){return 0===t.length?"":"/"+t.map(yt).join("/")}function gt(t){var e=t.split("/").map(vt);return""===e[0]?e.slice(1):e}ft.ids={};var mt,At,wt="Map.put can only be used to store complex values that have an identifier type attribute";(At=mt||(mt={}))[At.UNKNOWN=0]="UNKNOWN",At[At.YES=1]="YES",At[At.NO=2]="NO";var St=function(n){function t(t){return n.call(this,t,l.observable.ref.enhancer)||this}return a(t,n),t.prototype.get=function(t){return n.prototype.get.call(this,""+t)},t.prototype.has=function(t){return n.prototype.has.call(this,""+t)},t.prototype.delete=function(t){return n.prototype.delete.call(this,""+t)},t.prototype.set=function(t,e){return n.prototype.set.call(this,""+t,e)},t.prototype.put=function(t){if(t||et("Map.put cannot be used to set empty values"),W(t)){var e=J(t),n=e.identifier;return this.set(n,e.value),e.value}if(st(t)){n=void 0;var r=J(this).type;return r.identifierMode===mt.NO?et(wt):r.identifierMode===mt.YES?(n=""+t[r.identifierAttribute],this.set(n,t),this.get(n)):et(wt)}return et("Map.put can only be used to store complex values")},t}(l.ObservableMap),Pt=function(r){function t(t,e){var n=r.call(this,t)||this;return n.shouldAttachNode=!0,n.identifierMode=mt.UNKNOWN,n.identifierAttribute=void 0,n.flags=v.Map,n.subType=e,n._determineIdentifierMode(),n}return a(t,r),t.prototype.instantiate=function(t,e,n,r){return this.identifierMode===mt.UNKNOWN&&this._determineIdentifierMode(),$(this,t,e,n,r)},t.prototype._determineIdentifierMode=function(){var t=[];if(function t(e,n){if(e instanceof Rt)n.push(e);else if(e instanceof qt){if(!t(e.type,n))return!1}else if(e instanceof Bt){for(var r=0;r<e.types.length;r++)if(!t(e.types[r],n))return!1}else if(e instanceof ee){var i=e.getSubType(!1);if(!i)return!1;t(i,n)}return!0}(this.subType,t)){var e=void 0;t.forEach(function(t){t.identifierAttribute&&(e&&e!==t.identifierAttribute&&et("The objects in a map should all have the same identifier attribute, expected '"+e+"', but child of type '"+t.name+"' declared attribute '"+t.identifierAttribute+"' as identifier"),e=t.identifierAttribute)}),e?(this.identifierMode=mt.YES,this.identifierAttribute=e):this.identifierMode=mt.NO}},t.prototype.initializeChildNodes=function(e,n){void 0===n&&(n={});var r=e.type.subType,i=e._environment,o={};return Object.keys(n).forEach(function(t){o[t]=r.instantiate(e,t,i,n[t])}),o},t.prototype.createNewInstance=function(t,e,n){return new St(e)},t.prototype.finalizeNewInstance=function(t,e){l._interceptReads(e,t.unbox),l.intercept(e,this.willChange),l.observe(e,this.didChange)},t.prototype.describe=function(){return"Map<string, "+this.subType.describe()+">"},t.prototype.getChildren=function(t){return l.values(t.storedValue)},t.prototype.getChildNode=function(t,e){var n=t.storedValue.get(""+e);return n||et("Not a child "+e),n},t.prototype.willChange=function(t){var e=J(t.object),n=t.name;e.assertWritable();var r=e.type,i=r.subType;switch(t.type){case"update":var o=t.newValue;if(o===t.object.get(n))return null;t.newValue=i.reconcile(e.getChildNode(n),t.newValue),r.processIdentifier(n,t.newValue);break;case"add":t.newValue,t.newValue=i.instantiate(e,n,void 0,t.newValue),r.processIdentifier(n,t.newValue)}return t},t.prototype.processIdentifier=function(t,e){if(this.identifierMode===mt.YES&&e instanceof m){var n=e.identifier;n!==t&&et("A map of objects containing an identifier should always store the object under their own identifier. Trying to store key '"+n+"', but expected: '"+t+"'")}},t.prototype.getValue=function(t){return t.storedValue},t.prototype.getSnapshot=function(t){var e={};return t.getChildren().forEach(function(t){e[t.subpath]=t.snapshot}),e},t.prototype.processInitialSnapshot=function(e,t){var n={};return Object.keys(e).forEach(function(t){n[t]=e[t].getSnapshot()}),n},t.prototype.didChange=function(t){var e=J(t.object);switch(t.type){case"update":return void e.emitPatch({op:"replace",path:yt(t.name),value:t.newValue.snapshot,oldValue:t.oldValue?t.oldValue.snapshot:void 0},e);case"add":return void e.emitPatch({op:"add",path:yt(t.name),value:t.newValue.snapshot,oldValue:void 0},e);case"delete":var n=t.oldValue.snapshot;return t.oldValue.die(),void e.emitPatch({op:"remove",path:yt(t.name),oldValue:n},e)}},t.prototype.applyPatchLocally=function(t,e,n){var r=t.storedValue;switch(n.op){case"add":case"replace":r.set(e,n.value);break;case"remove":r.delete(e)}},t.prototype.applySnapshot=function(t,e){var n=t.storedValue,r={};for(var i in Array.from(n.keys()).forEach(function(t){r[t]=!1}),e)n.set(i,e[i]),r[""+i]=!0;Object.keys(r).forEach(function(t){!1===r[t]&&n.delete(t)})},t.prototype.getChildType=function(t){return this.subType},t.prototype.isValidSnapshot=function(e,n){var r=this;return at(e)?M(Object.keys(e).map(function(t){return r.subType.validate(e[t],R(n,t,r.subType))})):z(n,e,"Value is not a plain object")},t.prototype.getDefaultSnapshot=function(){return X},t.prototype.removeChild=function(t,e){t.storedValue.delete(e)},n([l.action],t.prototype,"applySnapshot",null),t}(A);var Vt=function(r){function t(t,e){var n=r.call(this,t)||this;return n.shouldAttachNode=!0,n.flags=v.Array,n.subType=e,n}return a(t,r),t.prototype.instantiate=function(t,e,n,r){return $(this,t,e,n,r)},t.prototype.initializeChildNodes=function(r,t){void 0===t&&(t=[]);var i=r.type.subType,o=r._environment,a={};return t.forEach(function(t,e){var n=""+e;a[n]=i.instantiate(r,n,o,t)}),a},t.prototype.createNewInstance=function(t,e,n){return l.observable.array(q(e),tt)},t.prototype.finalizeNewInstance=function(t,e){l._getAdministration(e).dehancer=t.unbox,l.intercept(e,this.willChange),l.observe(e,this.didChange)},t.prototype.describe=function(){return this.subType.describe()+"[]"},t.prototype.getChildren=function(t){return t.storedValue.slice()},t.prototype.getChildNode=function(t,e){var n=parseInt(e,10);return n<t.storedValue.length?t.storedValue[n]:et("Not a child: "+e)},t.prototype.willChange=function(t){var e=J(t.object);e.assertWritable();var n=e.type.subType,r=e.getChildren(),i=null;switch(t.type){case"update":if(t.newValue===t.object[t.index])return null;if(!(i=_t(e,n,[r[t.index]],[t.newValue],[t.index])))return null;t.newValue=i[0];break;case"splice":var o=t.index,a=t.removedCount,s=t.added;if(!(i=_t(e,n,r.slice(o,o+a),s,s.map(function(t,e){return o+e}))))return null;t.added=i;for(var u=o+a;u<r.length;u++)r[u].setParent(e,""+(u+s.length-a))}return t},t.prototype.getValue=function(t){return t.storedValue},t.prototype.getSnapshot=function(t){return t.getChildren().map(function(t){return t.snapshot})},t.prototype.processInitialSnapshot=function(e,t){var n=[];return Object.keys(e).forEach(function(t){n.push(e[t].getSnapshot())}),n},t.prototype.didChange=function(t){var e=J(t.object);switch(t.type){case"update":return void e.emitPatch({op:"replace",path:""+t.index,value:t.newValue.snapshot,oldValue:t.oldValue?t.oldValue.snapshot:void 0},e);case"splice":for(var n=t.removedCount-1;0<=n;n--)e.emitPatch({op:"remove",path:""+(t.index+n),oldValue:t.removed[n].snapshot},e);for(n=0;n<t.addedCount;n++)e.emitPatch({op:"add",path:""+(t.index+n),value:e.getChildNode(""+(t.index+n)).snapshot,oldValue:void 0},e);return}},t.prototype.applyPatchLocally=function(t,e,n){var r=t.storedValue,i="-"===e?r.length:parseInt(e);switch(n.op){case"replace":r[i]=n.value;break;case"add":r.splice(i,0,n.value);break;case"remove":r.splice(i,1)}},t.prototype.applySnapshot=function(t,e){t.storedValue.replace(e)},t.prototype.getChildType=function(t){return this.subType},t.prototype.isValidSnapshot=function(t,n){var r=this;return it(t)?M(t.map(function(t,e){return r.subType.validate(t,R(n,""+e,r.subType))})):z(n,t,"Value is not an array")},t.prototype.getDefaultSnapshot=function(){return Q},t.prototype.removeChild=function(t,e){t.storedValue.splice(parseInt(e,10),1)},n([l.action],t.prototype,"applySnapshot",null),t}(A);function _t(t,e,n,r,i){for(var o,a,s,u=!1,p=void 0,c=!0,l=0;u=l<=r.length-1,o=n[l],a=u?r[l]:void 0,((s=a)instanceof d||s instanceof m)&&(a=a.storedValue),o||u;l++)if(u)if(o)if(Nt(o,a))n[l]=Tt(e,t,""+i[l],a,o);else{p=void 0;for(var h=l;h<n.length;h++)if(Nt(n[h],a)){p=n.splice(h,1)[0];break}n.splice(l,0,Tt(e,t,""+i[l],a,p)),c=!1}else W(a)&&J(a).parent===t&&et("Cannot add an object to a state tree if it is already part of the same or another state tree. Tried to assign an object to '"+t.path+"/"+i[l]+"', but it lives already at '"+J(a).path+"'"),n.splice(l,0,Tt(e,t,""+i[l],a)),c=!1;else o.die(),n.splice(l,1),l--,c=!1;return c?null:n}function Tt(t,e,n,r,i){var o;if(W(r)&&((o=J(r)).assertAlive(),null!==o.parent&&o.parent===e))return o.setParent(e,n),i&&i!==o&&i.die(),o;return i?((o=t.reconcile(i,r)).setParent(e,n),o):t.instantiate(e,n,e._environment,r)}function Nt(t,e){return W(e)?J(e)===t:t.snapshot===e||!!(t instanceof m&&null!==t.identifier&&t.identifierAttribute&&at(e)&&t.identifier===""+e[t.identifierAttribute])}var Ct,It,jt="preProcessSnapshot",Ot="postProcessSnapshot";function Et(){return J(this).toString()}(It=Ct||(Ct={})).afterCreate="afterCreate",It.afterAttach="afterAttach",It.beforeDetach="beforeDetach",It.beforeDestroy="beforeDestroy";var Dt={name:"AnonymousModel",properties:{},initializers:Q};function xt(t){return Object.keys(t).reduce(function(t,e){var n,r,i;if(e in Ct)return et("Hook '"+e+"' was defined as property. Hooks should be defined as part of the actions");var o=Object.getOwnPropertyDescriptor(t,e);"get"in o&&et("Getters are not supported as properties. Please use views instead");var a=o.value;if(null==a)et("The default value of an attribute cannot be null or undefined as the type cannot be inferred. Did you mean `types.maybe(someType)`?");else{if(ut(a))return Object.assign({},t,((n={})[e]=Qt(function(t){switch(typeof t){case"string":return Mt;case"number":return Lt;case"boolean":return Ut;case"object":if(t instanceof Date)return Wt}return et("Cannot determine primitive type from value "+t)}(a),a),n));if(a instanceof Pt)return Object.assign({},t,((r={})[e]=Qt(a,{}),r));if(a instanceof Vt)return Object.assign({},t,((i={})[e]=Qt(a,[]),i));if(S(a))return t;et("Invalid type definition for property '"+e+"', cannot infer a type from a value like '"+a+"' ("+typeof a+")")}},t)}var Rt=function(r){function e(t){var e=r.call(this,t.name||Dt.name)||this;e.flags=v.Object,e.shouldAttachNode=!0;var n=t.name||Dt.name;return/^\w[\w\d_]*$/.test(n)||et("Typename should be a valid identifier: "+n),Object.assign(e,Dt,t),e.properties=xt(e.properties),pt(e.properties),e.propertyNames=Object.keys(e.properties),e.identifierAttribute=e._getIdentifierAttribute(),e}return a(e,r),e.prototype._getIdentifierAttribute=function(){var n=void 0;return this.forAllProps(function(t,e){e.flags&v.Identifier&&(n&&et("Cannot define property '"+t+"' as object identifier, property '"+n+"' is already defined as identifier property"),n=t)}),n},e.prototype.cloneAndEnhance=function(t){return new e({name:t.name||this.name,properties:Object.assign({},this.properties,t.properties),initializers:this.initializers.concat(t.initializers||[]),preProcessor:t.preProcessor||this.preProcessor,postProcessor:t.postProcessor||this.postProcessor})},e.prototype.actions=function(e){var n=this;return this.cloneAndEnhance({initializers:[function(t){return n.instantiateActions(t,e(t)),t}]})},e.prototype.instantiateActions=function(i,o){at(o)||et("actions initializer should return a plain object containing actions"),Object.keys(o).forEach(function(t){t===jt&&et("Cannot define action '"+jt+"', it should be defined using 'type.preProcessSnapshot(fn)' instead"),t===Ot&&et("Cannot define action '"+Ot+"', it should be defined using 'type.postProcessSnapshot(fn)' instead");var e=o[t],n=i[t];if(t in Ct&&n){var r=e;e=function(){n.apply(null,arguments),r.apply(null,arguments)}}ct(i,t,O(i,t,e))})},e.prototype.named=function(t){return this.cloneAndEnhance({name:t})},e.prototype.props=function(t){return this.cloneAndEnhance({properties:t})},e.prototype.volatile=function(e){var n=this;return this.cloneAndEnhance({initializers:[function(t){return n.instantiateVolatileState(t,e(t)),t}]})},e.prototype.instantiateVolatileState=function(t,e){at(e)||et("volatile state initializer should return a plain object containing state"),l.set(t,e)},e.prototype.extend=function(s){var u=this;return this.cloneAndEnhance({initializers:[function(t){var e=s(t),n=e.actions,r=e.views,i=e.state,o=function(t,e){var n={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(r=Object.getOwnPropertySymbols(t);i<r.length;i++)e.indexOf(r[i])<0&&(n[r[i]]=t[r[i]])}return n}(e,["actions","views","state"]);for(var a in o)et("The `extend` function should return an object with a subset of the fields 'actions', 'views' and 'state'. Found invalid key '"+a+"'");return i&&u.instantiateVolatileState(t,i),r&&u.instantiateViews(t,r),n&&u.instantiateActions(t,n),t}]})},e.prototype.views=function(e){var n=this;return this.cloneAndEnhance({initializers:[function(t){return n.instantiateViews(t,e(t)),t}]})},e.prototype.instantiateViews=function(i,o){at(o)||et("views initializer should return a plain object containing views"),Object.keys(o).forEach(function(t){var e=Object.getOwnPropertyDescriptor(o,t),n=e.value;if("get"in e)if(l.isComputedProp(i,t)){var r=l._getAdministration(i,t);r.derivation=e.get,r.scope=i,e.set&&(r.setter=l.action(r.name+"-setter",e.set))}else l.computed(i,t,e,!0);else"function"==typeof n?ct(i,t,n):et("A view member should either be a function or getter based property")})},e.prototype.preProcessSnapshot=function(e){var n=this.preProcessor;return n?this.cloneAndEnhance({preProcessor:function(t){return n(e(t))}}):this.cloneAndEnhance({preProcessor:e})},e.prototype.postProcessSnapshot=function(e){var n=this.postProcessor;return n?this.cloneAndEnhance({postProcessor:function(t){return e(n(t))}}):this.cloneAndEnhance({postProcessor:e})},e.prototype.instantiate=function(t,e,n,r){return $(this,t,e,n,W(r)?r:this.applySnapshotPreProcessor(r))},e.prototype.initializeChildNodes=function(n,r){void 0===r&&(r={});var t=n.type,i={};return t.forAllProps(function(t,e){i[t]=e.instantiate(n,t,n._environment,r[t])}),i},e.prototype.createNewInstance=function(t,e,n){return l.observable.object(e,X,tt)},e.prototype.finalizeNewInstance=function(e,n){ct(n,"toString",Et),this.forAllProps(function(t){l._interceptReads(n,t,e.unbox)}),this.initializers.reduce(function(t,e){return e(t)},n),l.intercept(n,this.willChange),l.observe(n,this.didChange)},e.prototype.willChange=function(t){var e=J(t.object);e.assertWritable();var n=e.type.properties[t.name];return n&&(t.newValue,t.newValue=n.reconcile(e.getChildNode(t.name),t.newValue)),t},e.prototype.didChange=function(t){var e=J(t.object);if(e.type.properties[t.name]){var n=t.oldValue?t.oldValue.snapshot:void 0;e.emitPatch({op:"replace",path:yt(t.name),value:t.newValue.snapshot,oldValue:n},e)}},e.prototype.getChildren=function(n){var r=this,i=[];return this.forAllProps(function(t,e){i.push(r.getChildNode(n,t))}),i},e.prototype.getChildNode=function(t,e){if(!(e in this.properties))return et("Not a value property: "+e);var n=l._getAdministration(t.storedValue,e).value;return n||et("Node not available for property "+e)},e.prototype.getValue=function(t){return t.storedValue},e.prototype.getSnapshot=function(n,t){var r=this;void 0===t&&(t=!0);var i={};return this.forAllProps(function(t,e){l.getAtom(n.storedValue,t).reportObserved(),i[t]=r.getChildNode(n,t).snapshot}),t?this.applySnapshotPostProcessor(i):i},e.prototype.processInitialSnapshot=function(e,t){var n={};return Object.keys(e).forEach(function(t){n[t]=e[t].getSnapshot()}),this.applySnapshotPostProcessor(this.applyOptionalValuesToSnapshot(n))},e.prototype.applyPatchLocally=function(t,e,n){"replace"!==n.op&&"add"!==n.op&&et("object does not support operation "+n.op),t.storedValue[e]=n.value},e.prototype.applySnapshot=function(n,t){var r=this.applySnapshotPreProcessor(t);this.forAllProps(function(t,e){n.storedValue[t]=r[t]})},e.prototype.applySnapshotPreProcessor=function(t){var e=this.preProcessor;return e?e.call(null,t):t},e.prototype.applyOptionalValuesToSnapshot=function(r){return r&&(r=Object.assign({},r),this.forAllProps(function(t,e){if(!(t in r)){var n=kt(e);n&&(r[t]=n.getDefaultValueSnapshot())}})),r},e.prototype.applySnapshotPostProcessor=function(t){var e=this.postProcessor;return e?e.call(null,t):t},e.prototype.getChildType=function(t){return this.properties[t]},e.prototype.isValidSnapshot=function(t,e){var n=this,r=this.applySnapshotPreProcessor(t);return at(r)?M(this.propertyNames.map(function(t){return n.properties[t].validate(r[t],R(e,t,n.properties[t]))})):z(e,r,"Value is not a plain object")},e.prototype.forAllProps=function(e){var n=this;this.propertyNames.forEach(function(t){return e(t,n.properties[t])})},e.prototype.describe=function(){var e=this;return"{ "+this.propertyNames.map(function(t){return t+": "+e.properties[t].describe()}).join("; ")+" }"},e.prototype.getDefaultSnapshot=function(){return X},e.prototype.removeChild=function(t,e){t.storedValue[e]=void 0},n([l.action],e.prototype,"applySnapshot",null),e}(A);function kt(t){if(t)return t.flags&v.Union&&t.types?t.types.find(kt):t.flags&v.Late&&t.getSubType&&t.getSubType(!1)?kt(t.subType):t.flags&v.Optional?t:void 0}var zt=function(o){function t(t,e,n,r){void 0===r&&(r=nt);var i=o.call(this,t)||this;return i.shouldAttachNode=!1,i.flags=e,i.checker=n,i.initializer=r,i}return a(t,o),t.prototype.describe=function(){return this.name},t.prototype.instantiate=function(t,e,n,r){return $(this,t,e,n,r)},t.prototype.createNewInstance=function(t,e,n){return this.initializer(n)},t.prototype.isValidSnapshot=function(t,e){return ut(t)&&this.checker(t)?k():z(e,t,"Value is not a "+("Date"===this.name?"Date or a unix milliseconds timestamp":this.name))},t}(w),Mt=new zt("string",v.String,function(t){return"string"==typeof t}),Lt=new zt("number",v.Number,function(t){return"number"==typeof t}),Ft=new zt("integer",v.Integer,function(t){return rt(t)}),Ut=new zt("boolean",v.Boolean,function(t){return"boolean"==typeof t}),Ht=new zt("null",v.Null,function(t){return null===t}),$t=new zt("undefined",v.Undefined,function(t){return void 0===t}),Wt=new zt("Date",v.Date,function(t){return"number"==typeof t||t instanceof Date},function(t){return t instanceof Date?t:new Date(t)});function Jt(t){return S(t)&&0<(t.flags&(v.String|v.Number|v.Integer|v.Boolean|v.Date))}Wt.getSnapshot=function(t){return t.storedValue.getTime()};var Yt=function(n){function t(t){var e=n.call(this,JSON.stringify(t))||this;return e.shouldAttachNode=!1,e.flags=v.Literal,e.value=t,e}return a(t,n),t.prototype.instantiate=function(t,e,n,r){return $(this,t,e,n,r)},t.prototype.describe=function(){return JSON.stringify(this.value)},t.prototype.isValidSnapshot=function(t,e){return ut(t)&&t===this.value?k():z(e,t,"Value is not a literal "+JSON.stringify(this.value))},t}(w);function Zt(t){return new Yt(t)}var Gt=function(o){function t(t,e,n,r){var i=o.call(this,t)||this;return i.type=e,i.predicate=n,i.message=r,i}return a(t,o),Object.defineProperty(t.prototype,"flags",{get:function(){return this.type.flags|v.Refinement},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"shouldAttachNode",{get:function(){return this.type.shouldAttachNode},enumerable:!0,configurable:!0}),t.prototype.describe=function(){return this.name},t.prototype.instantiate=function(t,e,n,r){return this.type.instantiate(t,e,n,r)},t.prototype.isAssignableFrom=function(t){return this.type.isAssignableFrom(t)},t.prototype.isValidSnapshot=function(t,e){var n=this.type.validate(t,e);if(0<n.length)return n;var r=W(t)?J(t).snapshot:t;return this.predicate(r)?k():z(e,t,this.message(t))},t}(w);var Bt=function(i){function t(t,e,n){var r=i.call(this,t)||this;return r.eager=!0,r.dispatcher=n&&n.dispatcher,n&&!n.eager&&(r.eager=!1),r.types=e,r}return a(t,i),Object.defineProperty(t.prototype,"flags",{get:function(){var e=v.Union;return this.types.forEach(function(t){e|=t.flags}),e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"shouldAttachNode",{get:function(){return this.types.some(function(t){return t.shouldAttachNode})},enumerable:!0,configurable:!0}),t.prototype.isAssignableFrom=function(e){return this.types.some(function(t){return t.isAssignableFrom(e)})},t.prototype.describe=function(){return"("+this.types.map(function(t){return t.describe()}).join(" | ")+")"},t.prototype.instantiate=function(t,e,n,r){var i=this.determineType(r);return i?i.instantiate(t,e,n,r):et("No matching type for union "+this.describe())},t.prototype.reconcile=function(t,e){var n=this.determineType(e);return n?n.reconcile(t,e):et("No matching type for union "+this.describe())},t.prototype.determineType=function(e){return this.dispatcher?this.dispatcher(e):this.types.find(function(t){return t.is(e)})},t.prototype.isValidSnapshot=function(t,e){if(this.dispatcher)return this.dispatcher(t).validate(t,e);for(var n=[],r=0,i=0;i<this.types.length;i++){var o=this.types[i].validate(t,e);if(0===o.length){if(this.eager)return k();r++}else n.push(o)}return 1===r?k():z(e,t,"No type is applicable for the union").concat(M(n))},t}(w);function Kt(t){for(var e=[],n=1;n<arguments.length;n++)e[n-1]=arguments[n];var r=S(t)?void 0:t,i=S(t)?[t].concat(e):e,o="("+i.map(function(t){return t.name}).join(" | ")+")";return new Bt(o,i,r)}var qt=function(r){function t(t,e){var n=r.call(this,t.name)||this;return n.type=t,n.defaultValue=e,n}return a(t,r),Object.defineProperty(t.prototype,"flags",{get:function(){return this.type.flags|v.Optional},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"shouldAttachNode",{get:function(){return this.type.shouldAttachNode},enumerable:!0,configurable:!0}),t.prototype.describe=function(){return this.type.describe()+"?"},t.prototype.instantiate=function(t,e,n,r){if(void 0===r){var i=this.getDefaultValueSnapshot();return this.type.instantiate(t,e,n,i)}return this.type.instantiate(t,e,n,r)},t.prototype.reconcile=function(t,e){return this.type.reconcile(t,this.type.is(e)&&void 0!==e?e:this.getDefaultValue())},t.prototype.getDefaultValue=function(){var t="function"==typeof this.defaultValue?this.defaultValue():this.defaultValue;return this.defaultValue,t},t.prototype.getDefaultValueSnapshot=function(){var t=this.getDefaultValue();return W(t)?J(t).snapshot:t},t.prototype.isValidSnapshot=function(t,e){return void 0===t?k():this.type.validate(t,e)},t.prototype.isAssignableFrom=function(t){return this.type.isAssignableFrom(t)},t}(w);function Qt(t,e){return new qt(t,e)}var Xt=Qt($t,void 0),te=Qt(Ht,null);var ee=function(r){function t(t,e){var n=r.call(this,t)||this;return n._subType=null,n.definition=e,n}return a(t,r),Object.defineProperty(t.prototype,"flags",{get:function(){return(this._subType?this._subType.flags:0)|v.Late},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"shouldAttachNode",{get:function(){return this.getSubType(!0).shouldAttachNode},enumerable:!0,configurable:!0}),t.prototype.getSubType=function(t){if(null===this._subType){var e=void 0;try{e=this.definition()}catch(t){if(!(t instanceof ReferenceError))throw t;e=void 0}if(t&&void 0===e&&et("Late type seems to be used too early, the definition (still) returns undefined"),e)return this._subType=e}return this._subType},t.prototype.instantiate=function(t,e,n,r){return this.getSubType(!0).instantiate(t,e,n,r)},t.prototype.reconcile=function(t,e){return this.getSubType(!0).reconcile(t,e)},t.prototype.describe=function(){var t=this.getSubType(!1);return t?t.name:"<uknown late type>"},t.prototype.isValidSnapshot=function(t,e){var n=this.getSubType(!1);return n?n.validate(t,e):k()},t.prototype.isAssignableFrom=function(t){var e=this.getSubType(!1);return!!e&&e.isAssignableFrom(t)},t}(w);var ne=function(n){function t(t){var e=n.call(this,t?"frozen("+t.name+")":"frozen")||this;return e.subType=t,e.shouldAttachNode=!1,e.flags=v.Frozen,e}return a(t,n),t.prototype.describe=function(){return"<any immutable value>"},t.prototype.instantiate=function(t,e,n,r){return $(this,t,e,n,r)},t.prototype.isValidSnapshot=function(t,e){return"function"==typeof t?z(e,t,"Value is not serializable and cannot be frozen"):this.subType?this.subType.validate(t,e):k()},t}(w),re=new ne;var ie=function(){function t(t,e,n){if(this.mode=t,this.value=e,this.targetType=n,"object"===t){if(!W(e))return et("Can only store references to tree nodes, got: '"+e+"'");if(!J(e).identifierAttribute)return et("Can only store references with a defined identifier attribute.")}}return Object.defineProperty(t.prototype,"resolvedValue",{get:function(){var t=this.node,e=this.targetType,n=t.root.identifierCache.resolve(e,this.value);return n?n.value:et("Failed to resolve reference '"+this.value+"' to type '"+this.targetType.name+"' (from node: "+t.path+")")},enumerable:!0,configurable:!0}),n([l.computed],t.prototype,"resolvedValue",null),t}(),oe=function(n){function t(t){var e=n.call(this,"reference("+t.name+")")||this;return e.targetType=t,e.shouldAttachNode=!1,e.flags=v.Reference,e}return a(t,n),t.prototype.describe=function(){return this.name},t.prototype.isAssignableFrom=function(t){return this.targetType.isAssignableFrom(t)},t.prototype.isValidSnapshot=function(t,e){return"string"==typeof t||"number"==typeof t?k():z(e,t,"Value is not a valid identifier, which is a string or a number")},t}(w),ae=function(e){function t(t){return e.call(this,t)||this}return a(t,e),t.prototype.getValue=function(t){if(t.isAlive){var e=t.storedValue;return"object"===e.mode?e.value:e.resolvedValue}},t.prototype.getSnapshot=function(t){var e=t.storedValue;switch(e.mode){case"identifier":return e.value;case"object":return e.value[J(e.value).identifierAttribute]}},t.prototype.instantiate=function(t,e,n,r){var i,o=W(r)?"object":"identifier",a=$(this,t,e,n,i=new ie(o,r,this.targetType));return i.node=a},t.prototype.reconcile=function(t,e){if(t.type===this){var n=W(e)?"object":"identifier",r=t.storedValue;if(n===r.mode&&r.value===e)return t}var i=this.instantiate(t.parent,t.subpath,t._environment,e);return t.die(),i},t}(oe),se=function(r){function t(t,e){var n=r.call(this,t)||this;return n.options=e,n}return a(t,r),t.prototype.getValue=function(t){if(t.isAlive)return this.options.get(t.storedValue,t.parent?t.parent.storedValue:null)},t.prototype.getSnapshot=function(t){return t.storedValue},t.prototype.instantiate=function(t,e,n,r){return $(this,t,e,n,W(r)?this.options.set(r,t?t.storedValue:null):r)},t.prototype.reconcile=function(t,e){var n=W(e)?this.options.set(e,t?t.storedValue:null):e;if(t.type===this&&t.storedValue===n)return t;var r=this.instantiate(t.parent,t.subpath,t._environment,n);return t.die(),r},t}(oe);var ue=function(e){function t(){var t=e.call(this,"identifier")||this;return t.shouldAttachNode=!1,t.flags=v.Identifier,t}return a(t,e),t.prototype.instantiate=function(t,e,n,r){return t&&t.type instanceof Rt||et("Identifier types can only be instantiated as direct child of a model type"),$(this,t,e,n,r)},t.prototype.reconcile=function(t,e){return t.storedValue!==e?et("Tried to change identifier from '"+t.storedValue+"' to '"+e+"'. Changing identifiers is not allowed."):t},t.prototype.describe=function(){return"identifier"},t.prototype.isValidSnapshot=function(t,e){return"string"!=typeof t?z(e,t,"Value is not a valid identifier, expected a string"):k()},t}(w),pe=function(i){function t(){var t=i.call(this)||this;return t.name="identifierNumber",t}return a(t,i),t.prototype.instantiate=function(t,e,n,r){return i.prototype.instantiate.call(this,t,e,n,r)},t.prototype.isValidSnapshot=function(t,e){return"number"==typeof t?k():z(e,t,"Value is not a valid identifierNumber, expected a number")},t.prototype.reconcile=function(t,e){return i.prototype.reconcile.call(this,t,e)},t.prototype.getSnapshot=function(t){return t.storedValue},t.prototype.describe=function(){return"identifierNumber"},t}(ue),ce=new ue,le=new pe;var he=function(n){function t(t){var e=n.call(this,t.name)||this;return e.options=t,e.flags=v.Reference,e.shouldAttachNode=!1,e}return a(t,n),t.prototype.describe=function(){return this.name},t.prototype.isAssignableFrom=function(t){return t===this},t.prototype.isValidSnapshot=function(t,e){if(this.options.isTargetType(t))return k();var n=this.options.getValidationMessage(t);return n?z(e,t,"Invalid value for type '"+this.name+"': "+n):k()},t.prototype.getValue=function(t){if(t.isAlive)return t.storedValue},t.prototype.getSnapshot=function(t){return this.options.toSnapshot(t.storedValue)},t.prototype.instantiate=function(t,e,n,r){return $(this,t,e,n,this.options.isTargetType(r)?r:this.options.fromSnapshot(r))},t.prototype.reconcile=function(t,e){var n=!this.options.isTargetType(e);if(t.type===this&&(n?e===t.snapshot:e===t.storedValue))return t;var r=n?this.options.fromSnapshot(e):e,i=this.instantiate(t.parent,t.subpath,t._environment,r);return t.die(),i},t}(w),fe={enumeration:function(t,e){var n=Kt.apply(void 0,("string"==typeof t?e:t).map(function(t){return Zt(""+t)}));return"string"==typeof t&&(n.name=t),n},model:function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n="string"==typeof t[0]?t.shift():"AnonymousModel",r=t.shift()||{};return new Rt({name:n,properties:r})},compose:function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n="string"==typeof t[0]?t.shift():"AnonymousModel";return t.reduce(function(t,e){return t.cloneAndEnhance({name:t.name+"_"+e.name,properties:e.properties,initializers:e.initializers})}).named(n)},custom:function(t){return new he(t)},reference:function(t,e){return e?new se(t,e):new ae(t)},union:Kt,optional:Qt,literal:Zt,maybe:function(t){return Kt(t,Xt)},maybeNull:function(t){return Kt(t,te)},refinement:function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n="string"==typeof t[0]?t.shift():S(t[0])?t[0].name:null,r=t[0],i=t[1],o=t[2]?t[2]:function(t){return"Value does not respect the refinement predicate"};return new Gt(n,r,i,o)},string:Mt,boolean:Ut,number:Lt,integer:Ft,Date:Wt,map:function(t){return new Pt("map<string, "+t.name+">",t)},array:function(t){return new Vt(t.name+"[]",t)},frozen:function(t){return 0===arguments.length?re:S(t)?new ne(t):Qt(re,t)},identifier:ce,identifierNumber:le,late:function(t,e){var n="string"==typeof t?t:"late("+t.toString()+")";return new ee(n,"string"==typeof t?e:t)},undefined:$t,null:Ht};t.types=fe,t.typecheck=L,t.escapeJsonPath=yt,t.unescapeJsonPath=vt,t.joinJsonPath=bt,t.splitJsonPath=gt,t.decorate=function(t,e){var n={handler:t,includeHooks:!0};return e.$mst_middleware&&e.$mst_middleware.push(n),e.$mst_middleware=[n],e},t.addMiddleware=E,t.process=function(t){return ft("process","`process()` has been renamed to `flow()`. See https://github.com/mobxjs/mobx-state-tree/issues/399 for more information. Note that the middleware event types starting with `process` now start with `flow`."),dt(t)},t.isStateTreeNode=W,t.flow=dt,t.applyAction=_,t.onAction=T,t.recordActions=function(t){var e={actions:[],stop:function(){return n()},replay:function(t){_(t,e.actions)}},n=T(t,e.actions.push.bind(e.actions));return e},t.createActionTrackingMiddleware=function(a){return function(e,t,n){switch(e.type){case"action":if(a.filter&&!0!==a.filter(e))return t(e);var r=a.onStart(e);a.onResume(e,r),P.set(e.id,{call:e,context:r,async:!1});try{var i=t(e);return a.onSuspend(e,r),!1===P.get(e.id).async&&(P.delete(e.id),a.onSuccess(e,r,i)),i}catch(t){throw P.delete(e.id),a.onFail(e,r,t),t}case"flow_spawn":return(o=P.get(e.rootId)).async=!0,t(e);case"flow_resume":case"flow_resume_error":var o=P.get(e.rootId);a.onResume(e,o.context);try{return t(e)}finally{a.onSuspend(e,o.context)}case"flow_throw":return o=P.get(e.rootId),P.delete(e.id),a.onFail(e,o.context,e.args[0]),t(e);case"flow_return":return o=P.get(e.rootId),P.delete(e.id),a.onSuccess(e,o.context,e.args[0]),t(e)}}},t.setLivelynessChecking=function(t){e=t},t.getType=u,t.getChildType=function(t,e){return J(t).getChildType(e)},t.onPatch=o,t.onSnapshot=function(t,e){return J(t).onSnapshot(e)},t.applyPatch=s,t.recordPatches=function(e){var t=null;function n(){t||(t=o(e,function(t,e){r.rawPatches.push([t,e])}))}var r={rawPatches:[],get patches(){return this.rawPatches.map(function(t){return t[0]})},get inversePatches(){return this.rawPatches.map(function(t){return t[0],t[1]})},stop:function(){t&&t(),t=null},resume:n,replay:function(t){s(t||e,r.patches)},undo:function(t){s(t||e,r.inversePatches.slice().reverse())}};return n(),r},t.protect=function(t){var e=J(t);e.isRoot||et("`protect` can only be invoked on root nodes"),e.isProtectionEnabled=!0},t.unprotect=function(t){var e=J(t);e.isRoot||et("`unprotect` can only be invoked on root nodes"),e.isProtectionEnabled=!1},t.isProtected=function(t){return J(t).isProtected},t.applySnapshot=p,t.getSnapshot=function(t,e){void 0===e&&(e=!0);var n=J(t);return e?n.snapshot:pt(n.type.getSnapshot(n,!1))},t.hasParent=function(t,e){void 0===e&&(e=1);for(var n=J(t).parent;n;){if(0==--e)return!0;n=n.parent}return!1},t.getParent=function(t,e){void 0===e&&(e=1);for(var n=e,r=J(t).parent;r;){if(0==--n)return r.storedValue;r=r.parent}return et("Failed to find the parent of "+J(t)+" at depth "+e)},t.hasParentOfType=function(t,e){for(var n=J(t).parent;n;){if(e.is(n.storedValue))return!0;n=n.parent}return!1},t.getParentOfType=function(t,e){for(var n=J(t).parent;n;){if(e.is(n.storedValue))return n.storedValue;n=n.parent}return et("Failed to find the parent of "+J(t)+" of a given type")},t.getRoot=c,t.getPath=function(t){return J(t).path},t.getPathParts=function(t){return gt(J(t).path)},t.isRoot=function(t){return J(t).isRoot},t.resolvePath=function(t,e){var n=B(J(t),e);return n?n.value:void 0},t.resolveIdentifier=function(t,e,n){var r=J(e).root.identifierCache.resolve(t,""+n);return r?r.value:void 0},t.getIdentifier=function(t){return J(t).identifier},t.tryResolve=h,t.getRelativePath=function(t,e){return G(J(t),J(e))},t.clone=function(t,e){void 0===e&&(e=!0);var n=J(t);return n.type.create(n.snapshot,!0===e?n.root._environment:!1===e?void 0:e)},t.detach=function(t){return J(t).detach(),t},t.destroy=function(t){var e=J(t);e.isRoot?e.die():e.parent.removeChild(e.subpath)},t.isAlive=function(t){return J(t).isAlive},t.addDisposer=function(t,e){J(t).addDisposer(e)},t.getEnv=function(t){var e=J(t).root._environment;return e||X},t.walk=f,t.getMembers=function(n){var t=J(n).type,e=Object.getOwnPropertyNames(n),r={name:t.name,properties:i({},t.properties),actions:[],volatile:[],views:[]};return e.forEach(function(t){if(!(t in r.properties)){var e=Object.getOwnPropertyDescriptor(n,t);e.get?l.isComputedProp(n,t)?r.views.push(t):r.volatile.push(t):!0===e.value._isMSTAction?r.actions.push(t):l.isObservableProp(n,t)?r.volatile.push(t):r.views.push(t)}}),r},t.cast=function(t){return t},t.isType=S,t.isArrayType=function(t){return S(t)&&0<(t.flags&v.Array)},t.isFrozenType=function(t){return S(t)&&0<(t.flags&v.Frozen)},t.isIdentifierType=function(t){return S(t)&&0<(t.flags&v.Identifier)},t.isLateType=function(t){return S(t)&&0<(t.flags&v.Late)},t.isLiteralType=function(t){return S(t)&&0<(t.flags&v.Literal)},t.isMapType=function(t){return S(t)&&0<(t.flags&v.Map)},t.isModelType=function(t){return S(t)&&0<(t.flags&v.Object)},t.isOptionalType=function(t){return S(t)&&0<(t.flags&v.Optional)},t.isPrimitiveType=Jt,t.isReferenceType=function(t){return 0<(t.flags&v.Reference)},t.isRefinementType=function(t){return 0<(t.flags&v.Refinement)},t.isUnionType=function(t){return 0<(t.flags&v.Union)},Object.defineProperty(t,"__esModule",{value:!0})});
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("mobx")):"function"==typeof define&&define.amd?define(["exports","mobx"],e):e(t.mobxStateTree={},t.mobx)}(this,function(t,l){"use strict";var r=function(t,e){return(r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(t,e)};function a(t,e){function n(){this.constructor=t}r(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}var i=function(){return(i=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var i in e=arguments[n])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t}).apply(this,arguments)};function n(t,e,n,r){var i,o=arguments.length,a=o<3?e:null===r?r=Object.getOwnPropertyDescriptor(e,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(t,e,n,r);else for(var s=t.length-1;0<=s;s--)(i=t[s])&&(a=(o<3?i(a):3<o?i(e,n,a):i(e,n))||a);return 3<o&&a&&Object.defineProperty(e,n,a),a}function u(t){return J(t).type}function o(t,e){return J(t).onPatch(e)}function s(t,e){J(t).applyPatches(ot(e))}function p(t,e){return J(t).applySnapshot(e)}function c(t){return J(t).root.storedValue}function h(t,e){var n=B(J(t),e,!1);if(void 0!==n)try{return n.value}catch(t){return}}function f(t,e){var n=J(t);n.getChildren().forEach(function(t){W(t.storedValue)&&f(t.storedValue,e)}),e(n.storedValue)}var d=function(){function t(t,e,n,r,i){this.parent=null,this.subpath="",this.state=F.INITIALIZING,this._environment=void 0,this._initialSnapshot=i,this.type=t,this.parent=e,this.subpath=n;var o=!0;try{this.storedValue=t.createNewInstance(this,{},i),this.state=F.CREATED,o=!1}finally{o&&(this.state=F.DEAD)}}return Object.defineProperty(t.prototype,"path",{get:function(){return this.parent?this.parent.path+"/"+yt(this.subpath):""},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"isRoot",{get:function(){return null===this.parent},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"root",{get:function(){return this.parent?this.parent.root:et("This scalar node is not part of a tree")},enumerable:!0,configurable:!0}),t.prototype.setParent=function(t,e){if(void 0===e&&(e=null),this.parent!==t||this.subpath!==e)if(this.parent&&!t)this.die();else{var n=null===e?"":e;this.subpath!==n&&(this.subpath=n),t&&t!==this.parent&&(this.parent=t)}},Object.defineProperty(t.prototype,"value",{get:function(){return this.type.getValue(this)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"snapshot",{get:function(){return pt(this.getSnapshot())},enumerable:!0,configurable:!0}),t.prototype.getSnapshot=function(){return this.type.getSnapshot(this)},Object.defineProperty(t.prototype,"isAlive",{get:function(){return this.state!==F.DEAD},enumerable:!0,configurable:!0}),t.prototype.toString=function(){return this.type.name+"@"+(this.path||"<root>")+(this.isAlive?"":"[dead]")},t.prototype.die=function(){this.state=F.DEAD},t}(),y=1,e="warn";var v,b,g={onError:function(t){throw t}},m=function(){function r(t,e,n,r,i){this.nodeId=++y,this.subpathAtom=l.createAtom("path"),this.subpath="",this.parent=null,this.state=F.INITIALIZING,this.isProtectionEnabled=!0,this.middlewares=null,this._autoUnbox=!0,this._environment=void 0,this._isRunningAction=!1,this._hasSnapshotReaction=!1,this._disposers=null,this._patchSubscribers=null,this._snapshotSubscribers=null,this._observableInstanceCreated=!1,this._cachedInitialSnapshot=null,this._environment=r,this._initialSnapshot=pt(i),this.type=t,this.parent=e,this.subpath=n,this.escapedSubpath=yt(this.subpath),this.identifierAttribute=t.identifierAttribute,this.identifier=this.identifierAttribute&&this._initialSnapshot?""+this._initialSnapshot[this.identifierAttribute]:null,e||(this.identifierCache=new H),this._childNodes=t.initializeChildNodes(this,this._initialSnapshot),e?e.root.identifierCache.addNodeToCache(this):this.identifierCache.addNodeToCache(this)}return r.prototype.applyPatches=function(t){this._observableInstanceCreated||this._createObservableInstance(),this.applyPatches(t)},r.prototype.applySnapshot=function(t){this._observableInstanceCreated||this._createObservableInstance(),this.applySnapshot(t)},r.prototype._createObservableInstance=function(){var t=this.type;this.storedValue=t.createNewInstance(this,this._childNodes,this._initialSnapshot),this.preboot();var e,n,r=!0;this._observableInstanceCreated=!0;try{this._isRunningAction=!0,t.finalizeNewInstance(this,this.storedValue),this._isRunningAction=!1,this.fireHook("afterCreate"),this.state=F.CREATED,r=!1}finally{r&&(this.state=F.DEAD)}e=this,n="snapshot",l.getAtom(e,n).trackAndCompute(),this.isRoot&&this._addSnapshotReaction(),this.finalizeCreation(),this._childNodes=X},Object.defineProperty(r.prototype,"path",{get:function(){return this.subpathAtom.reportObserved(),this.parent?this.parent.path+"/"+this.escapedSubpath:""},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"root",{get:function(){var t=this.parent;return t?t.root:this},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"isRoot",{get:function(){return null===this.parent},enumerable:!0,configurable:!0}),r.prototype.setParent=function(t,e){if(void 0===e&&(e=null),this.parent!==t||this.subpath!==e)if(this.parent&&!t)this.die();else{var n=null===e?"":e;this.subpath!==n&&(this.subpath=n,this.escapedSubpath=yt(this.subpath),this.subpathAtom.reportChanged()),t&&t!==this.parent&&(t.root.identifierCache.mergeCache(this),this.parent=t,this.subpathAtom.reportChanged(),this.fireHook("afterAttach"))}},r.prototype.fireHook=function(t){var e=this.storedValue&&"object"==typeof this.storedValue&&this.storedValue[t];"function"==typeof e&&e.apply(this.storedValue)},r.prototype.createObservableInstanceIfNeeded=function(){this._observableInstanceCreated||this._createObservableInstance()},Object.defineProperty(r.prototype,"isObservableInstanceCreated",{get:function(){return this._observableInstanceCreated},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"value",{get:function(){if(this.createObservableInstanceIfNeeded(),this.isAlive)return this.type.getValue(this)},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"snapshot",{get:function(){if(this.isAlive)return pt(this.getSnapshot())},enumerable:!0,configurable:!0}),r.prototype.getSnapshot=function(){if(this.isAlive)return this._observableInstanceCreated?this._getActualSnapshot():this._getInitialSnapshot()},r.prototype._getActualSnapshot=function(){return this.type.getSnapshot(this)},r.prototype._getInitialSnapshot=function(){if(this.isAlive){if(!this._initialSnapshot)return this._initialSnapshot;if(this._cachedInitialSnapshot)return this._cachedInitialSnapshot;var t=this.type,e=this._childNodes,n=this._initialSnapshot;return this._cachedInitialSnapshot=t.processInitialSnapshot(e,n),this._cachedInitialSnapshot}},r.prototype.isRunningAction=function(){return!!this._isRunningAction||!this.isRoot&&this.parent.isRunningAction()},Object.defineProperty(r.prototype,"isAlive",{get:function(){return this.state!==F.DEAD},enumerable:!0,configurable:!0}),r.prototype.assertAlive=function(){if(!this.isAlive){var t="[mobx-state-tree][error] You are trying to read or write to an object that is no longer part of a state tree. (Object type was '"+this.type.name+"'). Either detach nodes first, or don't use objects after removing / replacing them in the tree.";switch(e){case"error":throw new Error(t);case"warn":console.warn(t+' Use setLivelynessChecking("error") to simplify debugging this error.')}}},r.prototype.getChildNode=function(t){this.assertAlive(),this._autoUnbox=!1;try{return this._observableInstanceCreated?this.type.getChildNode(this,t):this._childNodes[t]}finally{this._autoUnbox=!0}},r.prototype.getChildren=function(){this.assertAlive(),this._autoUnbox=!1;try{return this._observableInstanceCreated?this.type.getChildren(this):q(this._childNodes)}finally{this._autoUnbox=!0}},r.prototype.getChildType=function(t){return this.type.getChildType(t)},Object.defineProperty(r.prototype,"isProtected",{get:function(){return this.root.isProtectionEnabled},enumerable:!0,configurable:!0}),r.prototype.assertWritable=function(){this.assertAlive(),!this.isRunningAction()&&this.isProtected&&et("Cannot modify '"+this+"', the object is protected and can only be modified by using an action.")},r.prototype.removeChild=function(t){this.type.removeChild(this,t)},r.prototype.unbox=function(t){return t&&t.parent&&t.parent.assertAlive(),t&&t.parent&&t.parent._autoUnbox?t.value:t},r.prototype.toString=function(){var t=this.identifier?"(id: "+this.identifier+")":"";return this.type.name+"@"+(this.path||"<root>")+t+(this.isAlive?"":"[dead]")},r.prototype.finalizeCreation=function(){if(this.state===F.CREATED){if(this.parent){if(this.parent.state!==F.FINALIZED)return;this.fireHook("afterAttach")}this.state=F.FINALIZED;for(var t=0,e=this.getChildren();t<e.length;t++){var n=e[t];n instanceof r&&n.finalizeCreation()}}},r.prototype.detach=function(){this.isAlive||et("Error while detaching, node is not alive."),this.isRoot||(this.fireHook("beforeDetach"),this._environment=this.root._environment,this.state=F.DETACHING,this.identifierCache=this.root.identifierCache.splitCache(this),this.parent.removeChild(this.subpath),this.parent=null,this.subpath=this.escapedSubpath="",this.subpathAtom.reportChanged(),this.state=F.FINALIZED)},r.prototype.preboot=function(){var n=this;this.applyPatches=j(this.storedValue,"@APPLY_PATCHES",function(t){t.forEach(function(t){var e=gt(t.path);K(n,e.slice(0,-1)).applyPatchLocally(e[e.length-1],t)})}),this.applySnapshot=j(this.storedValue,"@APPLY_SNAPSHOT",function(t){if(t!==n.snapshot)return n.type.applySnapshot(n,t)}),ct(this.storedValue,"$treenode",this),ct(this.storedValue,"toJSON",Y)},r.prototype.die=function(){this.state!==F.DETACHING&&W(this.storedValue)&&(f(this.storedValue,function(t){var e=J(t);e instanceof r&&e.aboutToDie()}),f(this.storedValue,function(t){var e=J(t);e instanceof r&&e.finalizeDeath()}))},r.prototype.aboutToDie=function(){this._disposers&&(this._disposers.forEach(function(t){return t()}),this._disposers=null),this.fireHook("beforeDestroy")},r.prototype.finalizeDeath=function(){var t,e,n;this.root.identifierCache.notifyDied(this),e="snapshot",n=(t=this).snapshot,Object.defineProperty(t,e,{enumerable:!0,writable:!1,configurable:!0,value:n}),this._patchSubscribers&&(this._patchSubscribers=null),this._snapshotSubscribers&&(this._snapshotSubscribers=null),this.state=F.DEAD,this.subpath=this.escapedSubpath="",this.parent=null,this.subpathAtom.reportChanged()},r.prototype.onSnapshot=function(t){return this._addSnapshotReaction(),this._snapshotSubscribers||(this._snapshotSubscribers=[]),lt(this._snapshotSubscribers,t)},r.prototype.emitSnapshot=function(e){this._snapshotSubscribers&&this._snapshotSubscribers.forEach(function(t){return t(e)})},r.prototype.onPatch=function(t){return this._patchSubscribers||(this._patchSubscribers=[]),lt(this._patchSubscribers,t)},r.prototype.emitPatch=function(t,e){var n=this._patchSubscribers;if(n&&n.length){var r=function(t){"oldValue"in t||et("Patches without `oldValue` field cannot be inversed");return[function(t){switch(t.op){case"add":return{op:"add",path:t.path,value:t.value};case"remove":return{op:"remove",path:t.path};case"replace":return{op:"replace",path:t.path,value:t.value}}}(t),function(t){switch(t.op){case"add":return{op:"remove",path:t.path};case"remove":return{op:"add",path:t.path,value:t.oldValue};case"replace":return{op:"replace",path:t.path,value:t.oldValue}}}(t)]}(function(t){for(var e=[],n=1;n<arguments.length;n++)e[n-1]=arguments[n];for(var r=0;r<e.length;r++){var i=e[r];for(var o in i)t[o]=i[o]}return t}({},t,{path:e.path.substr(this.path.length)+"/"+t.path})),i=r[0],o=r[1];n.forEach(function(t){return t(i,o)})}this.parent&&this.parent.emitPatch(t,e)},r.prototype.addDisposer=function(t){this._disposers?this._disposers.unshift(t):this._disposers=[t]},r.prototype.removeMiddleware=function(e){this.middlewares&&(this.middlewares=this.middlewares.filter(function(t){return t.handler!==e}))},r.prototype.addMiddleWare=function(t,e){var n=this;return void 0===e&&(e=!0),this.middlewares?this.middlewares.push({handler:t,includeHooks:e}):this.middlewares=[{handler:t,includeHooks:e}],function(){n.removeMiddleware(t)}},r.prototype.applyPatchLocally=function(t,e){this.assertWritable(),this._observableInstanceCreated||this._createObservableInstance(),this.type.applyPatchLocally(this,t,e)},r.prototype._addSnapshotReaction=function(){var e=this;if(!this._hasSnapshotReaction){var t=l.reaction(function(){return e.snapshot},function(t){return e.emitSnapshot(t)},g);this.addDisposer(t),this._hasSnapshotReaction=!0}},n([l.action],r.prototype,"_createObservableInstance",null),n([l.computed],r.prototype,"snapshot",null),n([l.action],r.prototype,"detach",null),n([l.action],r.prototype,"die",null),r}();(b=v||(v={}))[b.String=1]="String",b[b.Number=2]="Number",b[b.Boolean=4]="Boolean",b[b.Date=8]="Date",b[b.Literal=16]="Literal",b[b.Array=32]="Array",b[b.Map=64]="Map",b[b.Object=128]="Object",b[b.Frozen=256]="Frozen",b[b.Optional=512]="Optional",b[b.Reference=1024]="Reference",b[b.Identifier=2048]="Identifier",b[b.Late=4096]="Late",b[b.Refinement=8192]="Refinement",b[b.Union=16384]="Union",b[b.Null=32768]="Null",b[b.Undefined=65536]="Undefined",b[b.Integer=131072]="Integer";var A=function(){function t(t){this.$complexType=void 0,this.isType=!0,this.name=t}return t.prototype.create=function(t,e){return void 0===t&&(t=this.getDefaultSnapshot()),this.instantiate(null,"",e,t).value},t.prototype.initializeChildNodes=function(t,e){return X},t.prototype.createNewInstance=function(t,e,n){return n},t.prototype.finalizeNewInstance=function(t,e){},t.prototype.processInitialSnapshot=function(t,e){return e},t.prototype.isAssignableFrom=function(t){return t===this},t.prototype.validate=function(t,e){return W(t)?u(t)===this||this.isAssignableFrom(u(t))?k():z(e,t):this.isValidSnapshot(t,e)},t.prototype.is=function(t){return 0===this.validate(t,[{path:"",type:this}]).length},t.prototype.reconcile=function(t,e){if(t.snapshot===e)return t;if(W(e)&&J(e)===t)return t;if(t.type===this&&st(e)&&!W(e)&&(!t.identifierAttribute||t.identifier===""+e[t.identifierAttribute]))return t.applySnapshot(e),t;var n=t.parent,r=t.subpath;if(t.die(),W(e)&&this.isAssignableFrom(u(e))){var i=J(e);return i.setParent(n,r),i}return this.instantiate(n,r,t._environment,e)},Object.defineProperty(t.prototype,"Type",{get:function(){return et("Factory.Type should not be actually called. It is just a Type signature that can be used at compile time with Typescript, by using `typeof type.Type`")},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"SnapshotType",{get:function(){return et("Factory.SnapshotType should not be actually called. It is just a Type signature that can be used at compile time with Typescript, by using `typeof type.SnapshotType`")},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"CreationType",{get:function(){return et("Factory.CreationType should not be actually called. It is just a Type signature that can be used at compile time with Typescript, by using `typeof type.CreationType`")},enumerable:!0,configurable:!0}),n([l.action],t.prototype,"create",null),t}(),S=function(e){function t(t){return e.call(this,t)||this}return a(t,e),t.prototype.getValue=function(t){return t.storedValue},t.prototype.getSnapshot=function(t){return t.storedValue},t.prototype.getDefaultSnapshot=function(){},t.prototype.applySnapshot=function(t,e){et("Immutable types do not support applying snapshots")},t.prototype.applyPatchLocally=function(t,e,n){et("Immutable types do not support applying patches")},t.prototype.getChildren=function(t){return Q},t.prototype.getChildNode=function(t,e){return et("No child '"+e+"' available in type: "+this.name)},t.prototype.getChildType=function(t){return et("No child '"+t+"' available in type: "+this.name)},t.prototype.reconcile=function(t,e){if(t.type===this&&t.storedValue===e)return t;var n=this.instantiate(t.parent,t.subpath,t._environment,e);return t.die(),n},t.prototype.removeChild=function(t,e){return et("No child '"+e+"' available in type: "+this.name)},t}(A);function w(t){return"object"==typeof t&&t&&!0===t.isType}var P=new Map;function _(t){return{$MST_UNSERIALIZABLE:!0,type:t}}function V(e,t){l.runInAction(function(){ot(t).forEach(function(t){return function(t,e){var n=h(t,e.path||"");if(!n)return et("Invalid action path: "+(e.path||""));var r=J(n);if("@APPLY_PATCHES"===e.name)return s.call(null,n,e.args[0]);if("@APPLY_SNAPSHOT"===e.name)return p.call(null,n,e.args[0]);"function"!=typeof n[e.name]&&et("Action '"+e.name+"' does not exist in '"+r.path+"'");return n[e.name].apply(n,e.args?e.args.map(function(t){return(e=t)&&"object"==typeof e&&"$MST_DATE"in e?new Date(e.$MST_DATE):e;var e}):[])}(e,t)})})}function T(o,a,s){return void 0===s&&(s=!1),E(o,function(n,t){if("action"===n.type&&n.id===n.rootId){var e=J(n.context),r={name:n.name,path:G(J(o),e),args:n.args.map(function(t,e){return function(t,e,n,r){if(r instanceof Date)return{$MST_DATE:r.getTime()};if(ut(r))return r;if(W(r))return _("[MSTNode: "+u(r).name+"]");if("function"==typeof r)return _("[function]");if("object"==typeof r&&!at(r)&&!it(r))return _("[object "+(r&&r.constructor&&r.constructor.name||"Complex Object")+"]");try{return JSON.stringify(r),r}catch(t){return _(""+t)}}(0,n.name,0,t)})};if(s){var i=t(n);return a(r),i}return a(r),t(n)}return t(n)})}var I=1,N=null;function C(){return I++}function O(t,e){var n=J(t.context),r=n._isRunningAction,i=N;"action"===t.type&&n.assertAlive(),n._isRunningAction=!0,N=t;try{return function(t,e,s){var u=function(t,e,n){var r=n.$mst_middleware||Q,i=t;for(;i;)i.middlewares&&(r=r.concat(i.middlewares)),i=i.parent;return r}(t,0,s);if(!u.length)return l.action(s).apply(null,e.args);var p=0,c=null;return function n(t){var e=u[p++];var r=e&&e.handler;function i(t,e){c=e?e(n(t)||c):n(t)}function o(t){c=t}var a=function(){return r(t,i,o),c};return r&&e.includeHooks?a():r&&!e.includeHooks?Nt[t.name]?n(t):a():l.action(s).apply(null,t.args)}(e)}(n,t,e)}finally{N=i,n._isRunningAction=r}}function j(e,n,r){var t=function(){var t=C();return O({type:"action",name:n,id:t,args:ht(arguments),context:e,tree:c(e),rootId:N?N.rootId:t,parentId:N?N.id:0},r)};return t._isMSTAction=!0,t}function E(t,e,n){return void 0===n&&(n=!0),J(t).addMiddleWare(e,n)}function D(t){return"function"==typeof t?"<function"+(t.name?" "+t.name:"")+">":W(t)?"<"+t+">":"`"+function(t){try{return JSON.stringify(t)}catch(t){return"<Unserializable: "+t+">"}}(t)+"`"}function x(t){var e=t.value,n=t.context[t.context.length-1].type,r=t.context.map(function(t){return t.path}).filter(function(t){return 0<t.length}).join("/"),i=0<r.length?'at path "/'+r+'" ':"",o=W(e)?"value of type "+J(e).type.name+":":ut(e)?"value":"snapshot",a=n&&W(e)&&n.is(J(e).snapshot);return""+i+o+" "+D(e)+" is not assignable "+(n?"to type: `"+n.name+"`":"")+(t.message?" ("+t.message+")":"")+(n?Jt(n)||ut(e)?".":", expected an instance of `"+n.name+"` or a snapshot like `"+n.describe()+"` instead."+(a?" (Note that a snapshot of the provided value is compatible with the targeted type)":""):".")}function R(t,e,n){return t.concat([{path:e,type:n}])}function k(){return Q}function z(t,e,n){return[{context:t,value:e,message:n}]}function M(t){return t.reduce(function(t,e){return t.concat(e)},[])}function L(t,e){var n,r=t.validate(e,[{path:"",type:t}]);0<r.length&&et("Error while converting "+((n=D(e)).length<280?n:n.substring(0,272)+"......"+n.substring(n.length-8))+" to `"+t.name+"`:\n\n "+r.map(x).join("\n "))}var F,U,H=function(){function e(){this.cache=l.observable.map()}return e.prototype.addNodeToCache=function(t){if(t.identifierAttribute){var e=t.identifier;this.cache.has(e)||this.cache.set(e,l.observable.array([],tt));var n=this.cache.get(e);-1!==n.indexOf(t)&&et("Already registered"),n.push(t)}return this},e.prototype.mergeCache=function(t){var e=this;l.values(t.identifierCache.cache).forEach(function(t){return t.forEach(function(t){e.addNodeToCache(t)})})},e.prototype.notifyDied=function(t){if(t.identifierAttribute){var e=this.cache.get(t.identifier);e&&e.remove(t)}},e.prototype.splitCache=function(t){var n=new e,r=t.path;return l.values(this.cache).forEach(function(t){for(var e=t.length-1;0<=e;e--)0===t[e].path.indexOf(r)&&(n.addNodeToCache(t[e]),t.splice(e,1))}),n},e.prototype.resolve=function(e,t){var n=this.cache.get(""+t);if(!n)return null;var r=n.filter(function(t){return e.isAssignableFrom(t.type)});switch(r.length){case 0:return null;case 1:var i=r[0];if(i){for(var o=[],a=i.parent;a&&!a.isObservableInstanceCreated;)o.unshift(a),a=a.parent;for(var s=0,u=o;s<u.length;s++){u[s].createObservableInstanceIfNeeded()}}return i;default:return et("Cannot resolve a reference to type '"+e.name+"' with id: '"+t+"' unambigously, there are multiple candidates: "+r.map(function(t){return t.path}).join(", "))}},e}();function $(t,e,n,r,i){var o,a=(o=i)&&o.$treenode||null;if(a){if(a.isRoot)return a.setParent(e,n),a;et("Cannot add an object to a state tree if it is already part of the same or another state tree. Tried to assign an object to '"+(e?e.path:"")+"/"+n+"', but it lives already at '"+a.path+"'")}return new(t.shouldAttachNode?m:d)(t,e,n,r,i)}function W(t){return!(!t||!t.$treenode)}function J(t){return W(t)?t.$treenode:et("Value "+t+" is no MST Node")}function Y(){return J(this).snapshot}(U=F||(F={}))[U.INITIALIZING=0]="INITIALIZING",U[U.CREATED=1]="CREATED",U[U.FINALIZED=2]="FINALIZED",U[U.DETACHING=3]="DETACHING",U[U.DEAD=4]="DEAD";var Z=function(t){return".."};function G(t,e){t.root!==e.root&&et("Cannot calculate relative path: objects '"+t+"' and '"+e+"' are not part of the same object tree");for(var n=gt(t.path),r=gt(e.path),i=0;i<n.length&&n[i]===r[i];i++);return n.slice(i).map(Z).join("/")+bt(r.slice(i))}function B(t,e,n){return void 0===n&&(n=!0),K(t,gt(e),n)}function K(t,e,n){void 0===n&&(n=!0);for(var r=t,i=0;i<e.length;i++){var o=e[i];if(""!==o){if(".."===o){if(r=r.parent)continue}else{if("."===o||""===o)continue;if(r){if(r instanceof d)try{var a=r.value;W(a)&&(r=J(a))}catch(t){if(!n)return;throw t}if(r instanceof m)if(r.getChildType(o)&&(r=r.getChildNode(o)))continue}}return n?et("Could not resolve '"+o+"' in path '"+(bt(e.slice(0,i))||"/")+"' while resolving '"+bt(e)+"'"):void 0}r=r.root}return r}function q(n){if(!n)return Q;var t=Object.keys(n);if(!t.length)return Q;var r=new Array(t.length);return t.forEach(function(t,e){r[e]=n[t]}),r}var Q=Object.freeze([]),X=Object.freeze({}),tt="string"==typeof l.$mobx?{deep:!1}:{deep:!1,proxy:!1};function et(t){throw void 0===t&&(t="Illegal state"),new Error("[mobx-state-tree] "+t)}function nt(t){return t}Object.freeze(tt);var rt=Number.isInteger||function(t){return"number"==typeof t&&isFinite(t)&&Math.floor(t)===t};function it(t){return!(!Array.isArray(t)&&!l.isObservableArray(t))}function ot(t){return t?it(t)?t:[t]:Q}function at(t){if(null===t||"object"!=typeof t)return!1;var e=Object.getPrototypeOf(t);return e===Object.prototype||null===e}function st(t){return!(null===t||"object"!=typeof t||t instanceof Date||t instanceof RegExp)}function ut(t){return null==t||("string"==typeof t||"number"==typeof t||"boolean"==typeof t||t instanceof Date)}function pt(t){return t}function ct(t,e,n){Object.defineProperty(t,e,{enumerable:!1,writable:!1,configurable:!0,value:n})}function lt(r,i){return r.push(i),function(){var t,e,n;e=i,-1!==(n=(t=r).indexOf(e))&&t.splice(n,1)}}function ht(t){for(var e=new Array(t.length),n=0;n<t.length;n++)e[n]=t[n];return e}var ft=function(t,e){};function dt(t){return l=t.name,h=t,f=function(){var s=C(),u=N||et("Not running an action!"),p=arguments;function c(t,e,n){t.$mst_middleware=f.$mst_middleware,O({name:l,type:e,id:s,args:[n],tree:u.tree,context:u.context,parentId:u.id,rootId:u.rootId},t)}return new Promise(function(e,n){var r,t=function(){r=h.apply(null,arguments),i(void 0)};function i(t){var e;try{c(function(t){e=r.next(t)},"flow_resume",t)}catch(e){return void setImmediate(function(){c(function(t){n(e)},"flow_throw",e)})}a(e)}function o(t){var e;try{c(function(t){e=r.throw(t)},"flow_resume_error",t)}catch(e){return void setImmediate(function(){c(function(t){n(e)},"flow_throw",e)})}a(e)}function a(t){if(!t.done)return t.value&&"function"==typeof t.value.then||et("Only promises can be yielded to `async`, got: "+t),t.value.then(i,o);setImmediate(function(){c(function(t){e(t)},"flow_return",t.value)})}t.$mst_middleware=f.$mst_middleware,O({name:l,type:"flow_spawn",id:s,args:ht(p),tree:u.tree,context:u.context,parentId:u.id,rootId:u.rootId},t)})};var l,h,f}function yt(t){return!0==("number"==typeof t)?""+t:t.replace(/~/g,"~1").replace(/\//g,"~0")}function vt(t){return t.replace(/~0/g,"/").replace(/~1/g,"~")}function bt(t){return 0===t.length?"":"/"+t.map(yt).join("/")}function gt(t){var e=t.split("/").map(vt);return""===e[0]?e.slice(1):e}ft.ids={};var mt,At,St="Map.put can only be used to store complex values that have an identifier type attribute";(At=mt||(mt={}))[At.UNKNOWN=0]="UNKNOWN",At[At.YES=1]="YES",At[At.NO=2]="NO";var wt=function(n){function t(t){return n.call(this,t,l.observable.ref.enhancer)||this}return a(t,n),t.prototype.get=function(t){return n.prototype.get.call(this,""+t)},t.prototype.has=function(t){return n.prototype.has.call(this,""+t)},t.prototype.delete=function(t){return n.prototype.delete.call(this,""+t)},t.prototype.set=function(t,e){return n.prototype.set.call(this,""+t,e)},t.prototype.put=function(t){if(t||et("Map.put cannot be used to set empty values"),W(t)){var e=J(t),n=e.identifier;return this.set(n,e.value),e.value}if(st(t)){n=void 0;var r=J(this).type;return r.identifierMode===mt.NO?et(St):r.identifierMode===mt.YES?(n=""+t[r.identifierAttribute],this.set(n,t),this.get(n)):et(St)}return et("Map.put can only be used to store complex values")},t}(l.ObservableMap),Pt=function(r){function t(t,e){var n=r.call(this,t)||this;return n.shouldAttachNode=!0,n.identifierMode=mt.UNKNOWN,n.identifierAttribute=void 0,n.flags=v.Map,n.subType=e,n._determineIdentifierMode(),n}return a(t,r),t.prototype.instantiate=function(t,e,n,r){return this.identifierMode===mt.UNKNOWN&&this._determineIdentifierMode(),$(this,t,e,n,r)},t.prototype._determineIdentifierMode=function(){var t=[];if(function t(e,n){if(e instanceof Rt)n.push(e);else if(e instanceof qt){if(!t(e.type,n))return!1}else if(e instanceof Bt){for(var r=0;r<e.types.length;r++)if(!t(e.types[r],n))return!1}else if(e instanceof ee){var i=e.getSubType(!1);if(!i)return!1;t(i,n)}return!0}(this.subType,t)){var e=void 0;t.forEach(function(t){t.identifierAttribute&&(e&&e!==t.identifierAttribute&&et("The objects in a map should all have the same identifier attribute, expected '"+e+"', but child of type '"+t.name+"' declared attribute '"+t.identifierAttribute+"' as identifier"),e=t.identifierAttribute)}),e?(this.identifierMode=mt.YES,this.identifierAttribute=e):this.identifierMode=mt.NO}},t.prototype.initializeChildNodes=function(e,n){void 0===n&&(n={});var r=e.type.subType,i=e._environment,o={};return Object.keys(n).forEach(function(t){o[t]=r.instantiate(e,t,i,n[t])}),o},t.prototype.createNewInstance=function(t,e,n){return new wt(e)},t.prototype.finalizeNewInstance=function(t,e){l._interceptReads(e,t.unbox),l.intercept(e,this.willChange),l.observe(e,this.didChange)},t.prototype.describe=function(){return"Map<string, "+this.subType.describe()+">"},t.prototype.getChildren=function(t){return l.values(t.storedValue)},t.prototype.getChildNode=function(t,e){var n=t.storedValue.get(""+e);return n||et("Not a child "+e),n},t.prototype.willChange=function(t){var e=J(t.object),n=t.name;e.assertWritable();var r=e.type,i=r.subType;switch(t.type){case"update":var o=t.newValue;if(o===t.object.get(n))return null;t.newValue=i.reconcile(e.getChildNode(n),t.newValue),r.processIdentifier(n,t.newValue);break;case"add":t.newValue,t.newValue=i.instantiate(e,n,void 0,t.newValue),r.processIdentifier(n,t.newValue)}return t},t.prototype.processIdentifier=function(t,e){if(this.identifierMode===mt.YES&&e instanceof m){var n=e.identifier;n!==t&&et("A map of objects containing an identifier should always store the object under their own identifier. Trying to store key '"+n+"', but expected: '"+t+"'")}},t.prototype.getValue=function(t){return t.storedValue},t.prototype.getSnapshot=function(t){var e={};return t.getChildren().forEach(function(t){e[t.subpath]=t.snapshot}),e},t.prototype.processInitialSnapshot=function(e,t){var n={};return Object.keys(e).forEach(function(t){n[t]=e[t].getSnapshot()}),n},t.prototype.didChange=function(t){var e=J(t.object);switch(t.type){case"update":return void e.emitPatch({op:"replace",path:yt(t.name),value:t.newValue.snapshot,oldValue:t.oldValue?t.oldValue.snapshot:void 0},e);case"add":return void e.emitPatch({op:"add",path:yt(t.name),value:t.newValue.snapshot,oldValue:void 0},e);case"delete":var n=t.oldValue.snapshot;return t.oldValue.die(),void e.emitPatch({op:"remove",path:yt(t.name),oldValue:n},e)}},t.prototype.applyPatchLocally=function(t,e,n){var r=t.storedValue;switch(n.op){case"add":case"replace":r.set(e,n.value);break;case"remove":r.delete(e)}},t.prototype.applySnapshot=function(t,e){var n=t.storedValue,r={};for(var i in Array.from(n.keys()).forEach(function(t){r[t]=!1}),e)n.set(i,e[i]),r[""+i]=!0;Object.keys(r).forEach(function(t){!1===r[t]&&n.delete(t)})},t.prototype.getChildType=function(t){return this.subType},t.prototype.isValidSnapshot=function(e,n){var r=this;return at(e)?M(Object.keys(e).map(function(t){return r.subType.validate(e[t],R(n,t,r.subType))})):z(n,e,"Value is not a plain object")},t.prototype.getDefaultSnapshot=function(){return X},t.prototype.removeChild=function(t,e){t.storedValue.delete(e)},n([l.action],t.prototype,"applySnapshot",null),t}(A);var _t=function(r){function t(t,e){var n=r.call(this,t)||this;return n.shouldAttachNode=!0,n.flags=v.Array,n.subType=e,n}return a(t,r),t.prototype.instantiate=function(t,e,n,r){return $(this,t,e,n,r)},t.prototype.initializeChildNodes=function(r,t){void 0===t&&(t=[]);var i=r.type.subType,o=r._environment,a={};return t.forEach(function(t,e){var n=""+e;a[n]=i.instantiate(r,n,o,t)}),a},t.prototype.createNewInstance=function(t,e,n){return l.observable.array(q(e),tt)},t.prototype.finalizeNewInstance=function(t,e){l._getAdministration(e).dehancer=t.unbox,l.intercept(e,this.willChange),l.observe(e,this.didChange)},t.prototype.describe=function(){return this.subType.describe()+"[]"},t.prototype.getChildren=function(t){return t.storedValue.slice()},t.prototype.getChildNode=function(t,e){var n=parseInt(e,10);return n<t.storedValue.length?t.storedValue[n]:et("Not a child: "+e)},t.prototype.willChange=function(t){var e=J(t.object);e.assertWritable();var n=e.type.subType,r=e.getChildren(),i=null;switch(t.type){case"update":if(t.newValue===t.object[t.index])return null;if(!(i=Vt(e,n,[r[t.index]],[t.newValue],[t.index])))return null;t.newValue=i[0];break;case"splice":var o=t.index,a=t.removedCount,s=t.added;if(!(i=Vt(e,n,r.slice(o,o+a),s,s.map(function(t,e){return o+e}))))return null;t.added=i;for(var u=o+a;u<r.length;u++)r[u].setParent(e,""+(u+s.length-a))}return t},t.prototype.getValue=function(t){return t.storedValue},t.prototype.getSnapshot=function(t){return t.getChildren().map(function(t){return t.snapshot})},t.prototype.processInitialSnapshot=function(e,t){var n=[];return Object.keys(e).forEach(function(t){n.push(e[t].getSnapshot())}),n},t.prototype.didChange=function(t){var e=J(t.object);switch(t.type){case"update":return void e.emitPatch({op:"replace",path:""+t.index,value:t.newValue.snapshot,oldValue:t.oldValue?t.oldValue.snapshot:void 0},e);case"splice":for(var n=t.removedCount-1;0<=n;n--)e.emitPatch({op:"remove",path:""+(t.index+n),oldValue:t.removed[n].snapshot},e);for(n=0;n<t.addedCount;n++)e.emitPatch({op:"add",path:""+(t.index+n),value:e.getChildNode(""+(t.index+n)).snapshot,oldValue:void 0},e);return}},t.prototype.applyPatchLocally=function(t,e,n){var r=t.storedValue,i="-"===e?r.length:parseInt(e);switch(n.op){case"replace":r[i]=n.value;break;case"add":r.splice(i,0,n.value);break;case"remove":r.splice(i,1)}},t.prototype.applySnapshot=function(t,e){t.storedValue.replace(e)},t.prototype.getChildType=function(t){return this.subType},t.prototype.isValidSnapshot=function(t,n){var r=this;return it(t)?M(t.map(function(t,e){return r.subType.validate(t,R(n,""+e,r.subType))})):z(n,t,"Value is not an array")},t.prototype.getDefaultSnapshot=function(){return Q},t.prototype.removeChild=function(t,e){t.storedValue.splice(parseInt(e,10),1)},n([l.action],t.prototype,"applySnapshot",null),t}(A);function Vt(t,e,n,r,i){for(var o,a,s,u=!1,p=void 0,c=!0,l=0;u=l<=r.length-1,o=n[l],a=u?r[l]:void 0,((s=a)instanceof d||s instanceof m)&&(a=a.storedValue),o||u;l++)if(u)if(o)if(It(o,a))n[l]=Tt(e,t,""+i[l],a,o);else{p=void 0;for(var h=l;h<n.length;h++)if(It(n[h],a)){p=n.splice(h,1)[0];break}n.splice(l,0,Tt(e,t,""+i[l],a,p)),c=!1}else W(a)&&J(a).parent===t&&et("Cannot add an object to a state tree if it is already part of the same or another state tree. Tried to assign an object to '"+t.path+"/"+i[l]+"', but it lives already at '"+J(a).path+"'"),n.splice(l,0,Tt(e,t,""+i[l],a)),c=!1;else o.die(),n.splice(l,1),l--,c=!1;return c?null:n}function Tt(t,e,n,r,i){var o;if(W(r)&&((o=J(r)).assertAlive(),null!==o.parent&&o.parent===e))return o.setParent(e,n),i&&i!==o&&i.die(),o;return i?((o=t.reconcile(i,r)).setParent(e,n),o):t.instantiate(e,n,e._environment,r)}function It(t,e){return W(e)?J(e)===t:t.snapshot===e||!!(t instanceof m&&null!==t.identifier&&t.identifierAttribute&&at(e)&&t.identifier===""+e[t.identifierAttribute])}var Nt,Ct,Ot="preProcessSnapshot",jt="postProcessSnapshot";function Et(){return J(this).toString()}(Ct=Nt||(Nt={})).afterCreate="afterCreate",Ct.afterAttach="afterAttach",Ct.beforeDetach="beforeDetach",Ct.beforeDestroy="beforeDestroy";var Dt={name:"AnonymousModel",properties:{},initializers:Q};function xt(t){return Object.keys(t).reduce(function(t,e){var n,r,i;if(e in Nt)return et("Hook '"+e+"' was defined as property. Hooks should be defined as part of the actions");var o=Object.getOwnPropertyDescriptor(t,e);"get"in o&&et("Getters are not supported as properties. Please use views instead");var a=o.value;if(null==a)et("The default value of an attribute cannot be null or undefined as the type cannot be inferred. Did you mean `types.maybe(someType)`?");else{if(ut(a))return Object.assign({},t,((n={})[e]=Qt(function(t){switch(typeof t){case"string":return Mt;case"number":return Lt;case"boolean":return Ut;case"object":if(t instanceof Date)return Wt}return et("Cannot determine primitive type from value "+t)}(a),a),n));if(a instanceof Pt)return Object.assign({},t,((r={})[e]=Qt(a,{}),r));if(a instanceof _t)return Object.assign({},t,((i={})[e]=Qt(a,[]),i));if(w(a))return t;et("Invalid type definition for property '"+e+"', cannot infer a type from a value like '"+a+"' ("+typeof a+")")}},t)}var Rt=function(r){function e(t){var e=r.call(this,t.name||Dt.name)||this;e.flags=v.Object,e.shouldAttachNode=!0;var n=t.name||Dt.name;return/^\w[\w\d_]*$/.test(n)||et("Typename should be a valid identifier: "+n),Object.assign(e,Dt,t),e.properties=xt(e.properties),pt(e.properties),e.propertyNames=Object.keys(e.properties),e.identifierAttribute=e._getIdentifierAttribute(),e}return a(e,r),e.prototype._getIdentifierAttribute=function(){var n=void 0;return this.forAllProps(function(t,e){e.flags&v.Identifier&&(n&&et("Cannot define property '"+t+"' as object identifier, property '"+n+"' is already defined as identifier property"),n=t)}),n},e.prototype.cloneAndEnhance=function(t){return new e({name:t.name||this.name,properties:Object.assign({},this.properties,t.properties),initializers:this.initializers.concat(t.initializers||[]),preProcessor:t.preProcessor||this.preProcessor,postProcessor:t.postProcessor||this.postProcessor})},e.prototype.actions=function(e){var n=this;return this.cloneAndEnhance({initializers:[function(t){return n.instantiateActions(t,e(t)),t}]})},e.prototype.instantiateActions=function(i,o){at(o)||et("actions initializer should return a plain object containing actions"),Object.keys(o).forEach(function(t){t===Ot&&et("Cannot define action '"+Ot+"', it should be defined using 'type.preProcessSnapshot(fn)' instead"),t===jt&&et("Cannot define action '"+jt+"', it should be defined using 'type.postProcessSnapshot(fn)' instead");var e=o[t],n=i[t];if(t in Nt&&n){var r=e;e=function(){n.apply(null,arguments),r.apply(null,arguments)}}ct(i,t,j(i,t,e))})},e.prototype.named=function(t){return this.cloneAndEnhance({name:t})},e.prototype.props=function(t){return this.cloneAndEnhance({properties:t})},e.prototype.volatile=function(e){var n=this;return this.cloneAndEnhance({initializers:[function(t){return n.instantiateVolatileState(t,e(t)),t}]})},e.prototype.instantiateVolatileState=function(t,e){at(e)||et("volatile state initializer should return a plain object containing state"),l.set(t,e)},e.prototype.extend=function(s){var u=this;return this.cloneAndEnhance({initializers:[function(t){var e=s(t),n=e.actions,r=e.views,i=e.state,o=function(t,e){var n={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(r=Object.getOwnPropertySymbols(t);i<r.length;i++)e.indexOf(r[i])<0&&(n[r[i]]=t[r[i]])}return n}(e,["actions","views","state"]);for(var a in o)et("The `extend` function should return an object with a subset of the fields 'actions', 'views' and 'state'. Found invalid key '"+a+"'");return i&&u.instantiateVolatileState(t,i),r&&u.instantiateViews(t,r),n&&u.instantiateActions(t,n),t}]})},e.prototype.views=function(e){var n=this;return this.cloneAndEnhance({initializers:[function(t){return n.instantiateViews(t,e(t)),t}]})},e.prototype.instantiateViews=function(i,o){at(o)||et("views initializer should return a plain object containing views"),Object.keys(o).forEach(function(t){var e=Object.getOwnPropertyDescriptor(o,t),n=e.value;if("get"in e)if(l.isComputedProp(i,t)){var r=l._getAdministration(i,t);r.derivation=e.get,r.scope=i,e.set&&(r.setter=l.action(r.name+"-setter",e.set))}else l.computed(i,t,e,!0);else"function"==typeof n?ct(i,t,n):et("A view member should either be a function or getter based property")})},e.prototype.preProcessSnapshot=function(e){var n=this.preProcessor;return n?this.cloneAndEnhance({preProcessor:function(t){return n(e(t))}}):this.cloneAndEnhance({preProcessor:e})},e.prototype.postProcessSnapshot=function(e){var n=this.postProcessor;return n?this.cloneAndEnhance({postProcessor:function(t){return e(n(t))}}):this.cloneAndEnhance({postProcessor:e})},e.prototype.instantiate=function(t,e,n,r){return $(this,t,e,n,W(r)?r:this.applySnapshotPreProcessor(r))},e.prototype.initializeChildNodes=function(n,r){void 0===r&&(r={});var t=n.type,i={};return t.forAllProps(function(t,e){i[t]=e.instantiate(n,t,n._environment,r[t])}),i},e.prototype.createNewInstance=function(t,e,n){return l.observable.object(e,X,tt)},e.prototype.finalizeNewInstance=function(e,n){ct(n,"toString",Et),this.forAllProps(function(t){l._interceptReads(n,t,e.unbox)}),this.initializers.reduce(function(t,e){return e(t)},n),l.intercept(n,this.willChange),l.observe(n,this.didChange)},e.prototype.willChange=function(t){var e=J(t.object);e.assertWritable();var n=e.type.properties[t.name];return n&&(t.newValue,t.newValue=n.reconcile(e.getChildNode(t.name),t.newValue)),t},e.prototype.didChange=function(t){var e=J(t.object);if(e.type.properties[t.name]){var n=t.oldValue?t.oldValue.snapshot:void 0;e.emitPatch({op:"replace",path:yt(t.name),value:t.newValue.snapshot,oldValue:n},e)}},e.prototype.getChildren=function(n){var r=this,i=[];return this.forAllProps(function(t,e){i.push(r.getChildNode(n,t))}),i},e.prototype.getChildNode=function(t,e){if(!(e in this.properties))return et("Not a value property: "+e);var n=l._getAdministration(t.storedValue,e).value;return n||et("Node not available for property "+e)},e.prototype.getValue=function(t){return t.storedValue},e.prototype.getSnapshot=function(n,t){var r=this;void 0===t&&(t=!0);var i={};return this.forAllProps(function(t,e){l.getAtom(n.storedValue,t).reportObserved(),i[t]=r.getChildNode(n,t).snapshot}),t?this.applySnapshotPostProcessor(i):i},e.prototype.processInitialSnapshot=function(e,t){var n={};return Object.keys(e).forEach(function(t){n[t]=e[t].getSnapshot()}),this.applySnapshotPostProcessor(this.applyOptionalValuesToSnapshot(n))},e.prototype.applyPatchLocally=function(t,e,n){"replace"!==n.op&&"add"!==n.op&&et("object does not support operation "+n.op),t.storedValue[e]=n.value},e.prototype.applySnapshot=function(n,t){var r=this.applySnapshotPreProcessor(t);this.forAllProps(function(t,e){n.storedValue[t]=r[t]})},e.prototype.applySnapshotPreProcessor=function(t){var e=this.preProcessor;return e?e.call(null,t):t},e.prototype.applyOptionalValuesToSnapshot=function(r){return r&&(r=Object.assign({},r),this.forAllProps(function(t,e){if(!(t in r)){var n=kt(e);n&&(r[t]=n.getDefaultValueSnapshot())}})),r},e.prototype.applySnapshotPostProcessor=function(t){var e=this.postProcessor;return e?e.call(null,t):t},e.prototype.getChildType=function(t){return this.properties[t]},e.prototype.isValidSnapshot=function(t,e){var n=this,r=this.applySnapshotPreProcessor(t);return at(r)?M(this.propertyNames.map(function(t){return n.properties[t].validate(r[t],R(e,t,n.properties[t]))})):z(e,r,"Value is not a plain object")},e.prototype.forAllProps=function(e){var n=this;this.propertyNames.forEach(function(t){return e(t,n.properties[t])})},e.prototype.describe=function(){var e=this;return"{ "+this.propertyNames.map(function(t){return t+": "+e.properties[t].describe()}).join("; ")+" }"},e.prototype.getDefaultSnapshot=function(){return X},e.prototype.removeChild=function(t,e){t.storedValue[e]=void 0},n([l.action],e.prototype,"applySnapshot",null),e}(A);function kt(t){if(t)return t.flags&v.Union&&t.types?t.types.find(kt):t.flags&v.Late&&t.getSubType&&t.getSubType(!1)?kt(t.subType):t.flags&v.Optional?t:void 0}var zt=function(o){function t(t,e,n,r){void 0===r&&(r=nt);var i=o.call(this,t)||this;return i.shouldAttachNode=!1,i.flags=e,i.checker=n,i.initializer=r,i}return a(t,o),t.prototype.describe=function(){return this.name},t.prototype.instantiate=function(t,e,n,r){return $(this,t,e,n,r)},t.prototype.createNewInstance=function(t,e,n){return this.initializer(n)},t.prototype.isValidSnapshot=function(t,e){return ut(t)&&this.checker(t)?k():z(e,t,"Value is not a "+("Date"===this.name?"Date or a unix milliseconds timestamp":this.name))},t}(S),Mt=new zt("string",v.String,function(t){return"string"==typeof t}),Lt=new zt("number",v.Number,function(t){return"number"==typeof t}),Ft=new zt("integer",v.Integer,function(t){return rt(t)}),Ut=new zt("boolean",v.Boolean,function(t){return"boolean"==typeof t}),Ht=new zt("null",v.Null,function(t){return null===t}),$t=new zt("undefined",v.Undefined,function(t){return void 0===t}),Wt=new zt("Date",v.Date,function(t){return"number"==typeof t||t instanceof Date},function(t){return t instanceof Date?t:new Date(t)});function Jt(t){return w(t)&&0<(t.flags&(v.String|v.Number|v.Integer|v.Boolean|v.Date))}Wt.getSnapshot=function(t){return t.storedValue.getTime()};var Yt=function(n){function t(t){var e=n.call(this,JSON.stringify(t))||this;return e.shouldAttachNode=!1,e.flags=v.Literal,e.value=t,e}return a(t,n),t.prototype.instantiate=function(t,e,n,r){return $(this,t,e,n,r)},t.prototype.describe=function(){return JSON.stringify(this.value)},t.prototype.isValidSnapshot=function(t,e){return ut(t)&&t===this.value?k():z(e,t,"Value is not a literal "+JSON.stringify(this.value))},t}(S);function Zt(t){return new Yt(t)}var Gt=function(o){function t(t,e,n,r){var i=o.call(this,t)||this;return i.type=e,i.predicate=n,i.message=r,i}return a(t,o),Object.defineProperty(t.prototype,"flags",{get:function(){return this.type.flags|v.Refinement},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"shouldAttachNode",{get:function(){return this.type.shouldAttachNode},enumerable:!0,configurable:!0}),t.prototype.describe=function(){return this.name},t.prototype.instantiate=function(t,e,n,r){return this.type.instantiate(t,e,n,r)},t.prototype.isAssignableFrom=function(t){return this.type.isAssignableFrom(t)},t.prototype.isValidSnapshot=function(t,e){var n=this.type.validate(t,e);if(0<n.length)return n;var r=W(t)?J(t).snapshot:t;return this.predicate(r)?k():z(e,t,this.message(t))},t}(S);var Bt=function(i){function t(t,e,n){var r=i.call(this,t)||this;return r.eager=!0,r.dispatcher=n&&n.dispatcher,n&&!n.eager&&(r.eager=!1),r.types=e,r}return a(t,i),Object.defineProperty(t.prototype,"flags",{get:function(){var e=v.Union;return this.types.forEach(function(t){e|=t.flags}),e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"shouldAttachNode",{get:function(){return this.types.some(function(t){return t.shouldAttachNode})},enumerable:!0,configurable:!0}),t.prototype.isAssignableFrom=function(e){return this.types.some(function(t){return t.isAssignableFrom(e)})},t.prototype.describe=function(){return"("+this.types.map(function(t){return t.describe()}).join(" | ")+")"},t.prototype.instantiate=function(t,e,n,r){var i=this.determineType(r);return i?i.instantiate(t,e,n,r):et("No matching type for union "+this.describe())},t.prototype.reconcile=function(t,e){var n=this.determineType(e);return n?n.reconcile(t,e):et("No matching type for union "+this.describe())},t.prototype.determineType=function(e){return this.dispatcher?this.dispatcher(e):this.types.find(function(t){return t.is(e)})},t.prototype.isValidSnapshot=function(t,e){if(this.dispatcher)return this.dispatcher(t).validate(t,e);for(var n=[],r=0,i=0;i<this.types.length;i++){var o=this.types[i].validate(t,e);if(0===o.length){if(this.eager)return k();r++}else n.push(o)}return 1===r?k():z(e,t,"No type is applicable for the union").concat(M(n))},t}(S);function Kt(t){for(var e=[],n=1;n<arguments.length;n++)e[n-1]=arguments[n];var r=w(t)?void 0:t,i=w(t)?[t].concat(e):e,o="("+i.map(function(t){return t.name}).join(" | ")+")";return new Bt(o,i,r)}var qt=function(r){function t(t,e){var n=r.call(this,t.name)||this;return n.type=t,n.defaultValue=e,n}return a(t,r),Object.defineProperty(t.prototype,"flags",{get:function(){return this.type.flags|v.Optional},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"shouldAttachNode",{get:function(){return this.type.shouldAttachNode},enumerable:!0,configurable:!0}),t.prototype.describe=function(){return this.type.describe()+"?"},t.prototype.instantiate=function(t,e,n,r){if(void 0===r){var i=this.getDefaultInstanceOrSnapshot();return this.type.instantiate(t,e,n,i)}return this.type.instantiate(t,e,n,r)},t.prototype.reconcile=function(t,e){return this.type.reconcile(t,this.type.is(e)&&void 0!==e?e:this.getDefaultInstanceOrSnapshot())},t.prototype.getDefaultInstanceOrSnapshot=function(){var t="function"==typeof this.defaultValue?this.defaultValue():this.defaultValue;return this.defaultValue,t},t.prototype.getDefaultValueSnapshot=function(){var t=this.getDefaultInstanceOrSnapshot();return W(t)?J(t).snapshot:t},t.prototype.isValidSnapshot=function(t,e){return void 0===t?k():this.type.validate(t,e)},t.prototype.isAssignableFrom=function(t){return this.type.isAssignableFrom(t)},t}(S);function Qt(t,e){return"function"!=typeof e&&W(e)&&et("default value cannot be an instance, pass a snapshot or a function that creates an instance/snapshot instead"),new qt(t,e)}var Xt=Qt($t,void 0),te=Qt(Ht,null);var ee=function(r){function t(t,e){var n=r.call(this,t)||this;return n._subType=null,n.definition=e,n}return a(t,r),Object.defineProperty(t.prototype,"flags",{get:function(){return(this._subType?this._subType.flags:0)|v.Late},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"shouldAttachNode",{get:function(){return this.getSubType(!0).shouldAttachNode},enumerable:!0,configurable:!0}),t.prototype.getSubType=function(t){if(null===this._subType){var e=void 0;try{e=this.definition()}catch(t){if(!(t instanceof ReferenceError))throw t;e=void 0}if(t&&void 0===e&&et("Late type seems to be used too early, the definition (still) returns undefined"),e)return this._subType=e}return this._subType},t.prototype.instantiate=function(t,e,n,r){return this.getSubType(!0).instantiate(t,e,n,r)},t.prototype.reconcile=function(t,e){return this.getSubType(!0).reconcile(t,e)},t.prototype.describe=function(){var t=this.getSubType(!1);return t?t.name:"<uknown late type>"},t.prototype.isValidSnapshot=function(t,e){var n=this.getSubType(!1);return n?n.validate(t,e):k()},t.prototype.isAssignableFrom=function(t){var e=this.getSubType(!1);return!!e&&e.isAssignableFrom(t)},t}(S);var ne=function(n){function t(t){var e=n.call(this,t?"frozen("+t.name+")":"frozen")||this;return e.subType=t,e.shouldAttachNode=!1,e.flags=v.Frozen,e}return a(t,n),t.prototype.describe=function(){return"<any immutable value>"},t.prototype.instantiate=function(t,e,n,r){return $(this,t,e,n,r)},t.prototype.isValidSnapshot=function(t,e){return"function"==typeof t?z(e,t,"Value is not serializable and cannot be frozen"):this.subType?this.subType.validate(t,e):k()},t}(S),re=new ne;var ie=function(){function t(t,e,n){if(this.mode=t,this.value=e,this.targetType=n,"object"===t){if(!W(e))return et("Can only store references to tree nodes, got: '"+e+"'");if(!J(e).identifierAttribute)return et("Can only store references with a defined identifier attribute.")}}return Object.defineProperty(t.prototype,"resolvedValue",{get:function(){var t=this.node,e=this.targetType,n=t.root.identifierCache.resolve(e,this.value);return n?n.value:et("Failed to resolve reference '"+this.value+"' to type '"+this.targetType.name+"' (from node: "+t.path+")")},enumerable:!0,configurable:!0}),n([l.computed],t.prototype,"resolvedValue",null),t}(),oe=function(n){function t(t){var e=n.call(this,"reference("+t.name+")")||this;return e.targetType=t,e.shouldAttachNode=!1,e.flags=v.Reference,e}return a(t,n),t.prototype.describe=function(){return this.name},t.prototype.isAssignableFrom=function(t){return this.targetType.isAssignableFrom(t)},t.prototype.isValidSnapshot=function(t,e){return"string"==typeof t||"number"==typeof t?k():z(e,t,"Value is not a valid identifier, which is a string or a number")},t}(S),ae=function(e){function t(t){return e.call(this,t)||this}return a(t,e),t.prototype.getValue=function(t){if(t.isAlive){var e=t.storedValue;return"object"===e.mode?e.value:e.resolvedValue}},t.prototype.getSnapshot=function(t){var e=t.storedValue;switch(e.mode){case"identifier":return e.value;case"object":return e.value[J(e.value).identifierAttribute]}},t.prototype.instantiate=function(t,e,n,r){var i,o=W(r)?"object":"identifier",a=$(this,t,e,n,i=new ie(o,r,this.targetType));return i.node=a},t.prototype.reconcile=function(t,e){if(t.type===this){var n=W(e)?"object":"identifier",r=t.storedValue;if(n===r.mode&&r.value===e)return t}var i=this.instantiate(t.parent,t.subpath,t._environment,e);return t.die(),i},t}(oe),se=function(r){function t(t,e){var n=r.call(this,t)||this;return n.options=e,n}return a(t,r),t.prototype.getValue=function(t){if(t.isAlive)return this.options.get(t.storedValue,t.parent?t.parent.storedValue:null)},t.prototype.getSnapshot=function(t){return t.storedValue},t.prototype.instantiate=function(t,e,n,r){return $(this,t,e,n,W(r)?this.options.set(r,t?t.storedValue:null):r)},t.prototype.reconcile=function(t,e){var n=W(e)?this.options.set(e,t?t.storedValue:null):e;if(t.type===this&&t.storedValue===n)return t;var r=this.instantiate(t.parent,t.subpath,t._environment,n);return t.die(),r},t}(oe);var ue=function(e){function t(){var t=e.call(this,"identifier")||this;return t.shouldAttachNode=!1,t.flags=v.Identifier,t}return a(t,e),t.prototype.instantiate=function(t,e,n,r){return t&&t.type instanceof Rt||et("Identifier types can only be instantiated as direct child of a model type"),$(this,t,e,n,r)},t.prototype.reconcile=function(t,e){return t.storedValue!==e?et("Tried to change identifier from '"+t.storedValue+"' to '"+e+"'. Changing identifiers is not allowed."):t},t.prototype.describe=function(){return"identifier"},t.prototype.isValidSnapshot=function(t,e){return"string"!=typeof t?z(e,t,"Value is not a valid identifier, expected a string"):k()},t}(S),pe=function(i){function t(){var t=i.call(this)||this;return t.name="identifierNumber",t}return a(t,i),t.prototype.instantiate=function(t,e,n,r){return i.prototype.instantiate.call(this,t,e,n,r)},t.prototype.isValidSnapshot=function(t,e){return"number"==typeof t?k():z(e,t,"Value is not a valid identifierNumber, expected a number")},t.prototype.reconcile=function(t,e){return i.prototype.reconcile.call(this,t,e)},t.prototype.getSnapshot=function(t){return t.storedValue},t.prototype.describe=function(){return"identifierNumber"},t}(ue),ce=new ue,le=new pe;var he=function(n){function t(t){var e=n.call(this,t.name)||this;return e.options=t,e.flags=v.Reference,e.shouldAttachNode=!1,e}return a(t,n),t.prototype.describe=function(){return this.name},t.prototype.isAssignableFrom=function(t){return t===this},t.prototype.isValidSnapshot=function(t,e){if(this.options.isTargetType(t))return k();var n=this.options.getValidationMessage(t);return n?z(e,t,"Invalid value for type '"+this.name+"': "+n):k()},t.prototype.getValue=function(t){if(t.isAlive)return t.storedValue},t.prototype.getSnapshot=function(t){return this.options.toSnapshot(t.storedValue)},t.prototype.instantiate=function(t,e,n,r){return $(this,t,e,n,this.options.isTargetType(r)?r:this.options.fromSnapshot(r))},t.prototype.reconcile=function(t,e){var n=!this.options.isTargetType(e);if(t.type===this&&(n?e===t.snapshot:e===t.storedValue))return t;var r=n?this.options.fromSnapshot(e):e,i=this.instantiate(t.parent,t.subpath,t._environment,r);return t.die(),i},t}(S),fe={enumeration:function(t,e){var n=Kt.apply(void 0,("string"==typeof t?e:t).map(function(t){return Zt(""+t)}));return"string"==typeof t&&(n.name=t),n},model:function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n="string"==typeof t[0]?t.shift():"AnonymousModel",r=t.shift()||{};return new Rt({name:n,properties:r})},compose:function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n="string"==typeof t[0]?t.shift():"AnonymousModel";return t.reduce(function(t,e){return t.cloneAndEnhance({name:t.name+"_"+e.name,properties:e.properties,initializers:e.initializers})}).named(n)},custom:function(t){return new he(t)},reference:function(t,e){return e?new se(t,e):new ae(t)},union:Kt,optional:Qt,literal:Zt,maybe:function(t){return Kt(t,Xt)},maybeNull:function(t){return Kt(t,te)},refinement:function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n="string"==typeof t[0]?t.shift():w(t[0])?t[0].name:null,r=t[0],i=t[1],o=t[2]?t[2]:function(t){return"Value does not respect the refinement predicate"};return new Gt(n,r,i,o)},string:Mt,boolean:Ut,number:Lt,integer:Ft,Date:Wt,map:function(t){return new Pt("map<string, "+t.name+">",t)},array:function(t){return new _t(t.name+"[]",t)},frozen:function(t){return 0===arguments.length?re:w(t)?new ne(t):Qt(re,t)},identifier:ce,identifierNumber:le,late:function(t,e){var n="string"==typeof t?t:"late("+t.toString()+")";return new ee(n,"string"==typeof t?e:t)},undefined:$t,null:Ht};t.types=fe,t.typecheck=L,t.escapeJsonPath=yt,t.unescapeJsonPath=vt,t.joinJsonPath=bt,t.splitJsonPath=gt,t.decorate=function(t,e){var n={handler:t,includeHooks:!0};return e.$mst_middleware&&e.$mst_middleware.push(n),e.$mst_middleware=[n],e},t.addMiddleware=E,t.process=function(t){return ft("process","`process()` has been renamed to `flow()`. See https://github.com/mobxjs/mobx-state-tree/issues/399 for more information. Note that the middleware event types starting with `process` now start with `flow`."),dt(t)},t.isStateTreeNode=W,t.flow=dt,t.applyAction=V,t.onAction=T,t.recordActions=function(t){var e={actions:[],stop:function(){return n()},replay:function(t){V(t,e.actions)}},n=T(t,e.actions.push.bind(e.actions));return e},t.createActionTrackingMiddleware=function(a){return function(e,t,n){switch(e.type){case"action":if(a.filter&&!0!==a.filter(e))return t(e);var r=a.onStart(e);a.onResume(e,r),P.set(e.id,{call:e,context:r,async:!1});try{var i=t(e);return a.onSuspend(e,r),!1===P.get(e.id).async&&(P.delete(e.id),a.onSuccess(e,r,i)),i}catch(t){throw P.delete(e.id),a.onFail(e,r,t),t}case"flow_spawn":return(o=P.get(e.rootId)).async=!0,t(e);case"flow_resume":case"flow_resume_error":var o=P.get(e.rootId);a.onResume(e,o.context);try{return t(e)}finally{a.onSuspend(e,o.context)}case"flow_throw":return o=P.get(e.rootId),P.delete(e.id),a.onFail(e,o.context,e.args[0]),t(e);case"flow_return":return o=P.get(e.rootId),P.delete(e.id),a.onSuccess(e,o.context,e.args[0]),t(e)}}},t.setLivelynessChecking=function(t){e=t},t.getType=u,t.getChildType=function(t,e){return J(t).getChildType(e)},t.onPatch=o,t.onSnapshot=function(t,e){return J(t).onSnapshot(e)},t.applyPatch=s,t.recordPatches=function(e){var t=null;function n(){t||(t=o(e,function(t,e){r.rawPatches.push([t,e])}))}var r={rawPatches:[],get patches(){return this.rawPatches.map(function(t){return t[0]})},get inversePatches(){return this.rawPatches.map(function(t){return t[0],t[1]})},stop:function(){t&&t(),t=null},resume:n,replay:function(t){s(t||e,r.patches)},undo:function(t){s(t||e,r.inversePatches.slice().reverse())}};return n(),r},t.protect=function(t){var e=J(t);e.isRoot||et("`protect` can only be invoked on root nodes"),e.isProtectionEnabled=!0},t.unprotect=function(t){var e=J(t);e.isRoot||et("`unprotect` can only be invoked on root nodes"),e.isProtectionEnabled=!1},t.isProtected=function(t){return J(t).isProtected},t.applySnapshot=p,t.getSnapshot=function(t,e){void 0===e&&(e=!0);var n=J(t);return e?n.snapshot:pt(n.type.getSnapshot(n,!1))},t.hasParent=function(t,e){void 0===e&&(e=1);for(var n=J(t).parent;n;){if(0==--e)return!0;n=n.parent}return!1},t.getParent=function(t,e){void 0===e&&(e=1);for(var n=e,r=J(t).parent;r;){if(0==--n)return r.storedValue;r=r.parent}return et("Failed to find the parent of "+J(t)+" at depth "+e)},t.hasParentOfType=function(t,e){for(var n=J(t).parent;n;){if(e.is(n.storedValue))return!0;n=n.parent}return!1},t.getParentOfType=function(t,e){for(var n=J(t).parent;n;){if(e.is(n.storedValue))return n.storedValue;n=n.parent}return et("Failed to find the parent of "+J(t)+" of a given type")},t.getRoot=c,t.getPath=function(t){return J(t).path},t.getPathParts=function(t){return gt(J(t).path)},t.isRoot=function(t){return J(t).isRoot},t.resolvePath=function(t,e){var n=B(J(t),e);return n?n.value:void 0},t.resolveIdentifier=function(t,e,n){var r=J(e).root.identifierCache.resolve(t,""+n);return r?r.value:void 0},t.getIdentifier=function(t){return J(t).identifier},t.tryResolve=h,t.getRelativePath=function(t,e){return G(J(t),J(e))},t.clone=function(t,e){void 0===e&&(e=!0);var n=J(t);return n.type.create(n.snapshot,!0===e?n.root._environment:!1===e?void 0:e)},t.detach=function(t){return J(t).detach(),t},t.destroy=function(t){var e=J(t);e.isRoot?e.die():e.parent.removeChild(e.subpath)},t.isAlive=function(t){return J(t).isAlive},t.addDisposer=function(t,e){J(t).addDisposer(e)},t.getEnv=function(t){var e=J(t).root._environment;return e||X},t.walk=f,t.getMembers=function(n){var t=J(n).type,e=Object.getOwnPropertyNames(n),r={name:t.name,properties:i({},t.properties),actions:[],volatile:[],views:[]};return e.forEach(function(t){if(!(t in r.properties)){var e=Object.getOwnPropertyDescriptor(n,t);e.get?l.isComputedProp(n,t)?r.views.push(t):r.volatile.push(t):!0===e.value._isMSTAction?r.actions.push(t):l.isObservableProp(n,t)?r.volatile.push(t):r.views.push(t)}}),r},t.cast=function(t){return t},t.isType=w,t.isArrayType=function(t){return w(t)&&0<(t.flags&v.Array)},t.isFrozenType=function(t){return w(t)&&0<(t.flags&v.Frozen)},t.isIdentifierType=function(t){return w(t)&&0<(t.flags&v.Identifier)},t.isLateType=function(t){return w(t)&&0<(t.flags&v.Late)},t.isLiteralType=function(t){return w(t)&&0<(t.flags&v.Literal)},t.isMapType=function(t){return w(t)&&0<(t.flags&v.Map)},t.isModelType=function(t){return w(t)&&0<(t.flags&v.Object)},t.isOptionalType=function(t){return w(t)&&0<(t.flags&v.Optional)},t.isPrimitiveType=Jt,t.isReferenceType=function(t){return 0<(t.flags&v.Reference)},t.isRefinementType=function(t){return 0<(t.flags&v.Refinement)},t.isUnionType=function(t){return 0<(t.flags&v.Union)},Object.defineProperty(t,"__esModule",{value:!0})});

@@ -16,3 +16,3 @@ import { ExtractIStateTreeNode, IAnyType, IComplexType, IStateTreeNode, IType } from "../../internal";

export interface OptionalProperty {
optional: true;
readonly $optionalType: undefined;
}

@@ -56,7 +56,6 @@ export declare type RequiredPropNames<T> = {

}): IModelType<PROPS, OTHERS & A & V & VS>;
preProcessSnapshot<S0 = ModelCreationType<PROPS>>(fn: (snapshot: S0) => ModelCreationType<PROPS>): IModelType<PROPS, OTHERS, S0>;
postProcessSnapshot<S1 = ModelCreationType<PROPS>>(fn: (snapshot: ModelSnapshotType<PROPS>) => S1): IModelType<PROPS, OTHERS, S1>;
preProcessSnapshot<NewC = C>(fn: (snapshot: NewC) => C): IModelType<PROPS, OTHERS, NewC, S>;
postProcessSnapshot<NewS = S>(fn: (snapshot: S) => NewS): IModelType<PROPS, OTHERS, C, NewS>;
}
export interface IAnyModelType extends IModelType<any, any, any, any, any> {
}
export declare type IAnyModelType = IModelType<any, any, any, any, any>;
export declare type ExtractProps<T extends IAnyModelType> = T extends IModelType<infer P, any> ? P : never;

@@ -63,0 +62,0 @@ export declare type ExtractOthers<T extends IAnyModelType> = T extends IModelType<any, infer O> ? O : never;

import { IType, IComplexType, OptionalProperty } from "../../internal";
export declare function optional<C, S, T>(type: IComplexType<C, S, T>, defaultValueOrFunction: C | S | T): IComplexType<C | undefined, S, T> & OptionalProperty;
export declare function optional<C, S, T>(type: IComplexType<C, S, T>, defaultValueOrFunction: () => C | S | T): IComplexType<C | undefined, S, T> & OptionalProperty;
export declare function optional<C, S, T>(type: IType<C, S, T>, defaultValueOrFunction: C | S | T): IType<C | undefined, S, T> & OptionalProperty;
export declare function optional<C, S, T>(type: IType<C, S, T>, defaultValueOrFunction: () => C | S | T): IType<C | undefined, S, T> & OptionalProperty;
export declare function optional<C, S, T>(type: IComplexType<C, S, T>, defaultValueOrFunction: C | S | (() => C | S | T)): IComplexType<C | undefined, S, T> & OptionalProperty;
export declare function optional<C, S, T>(type: IType<C, S, T>, defaultValueOrFunction: C | S | (() => C | S | T)): IType<C | undefined, S, T> & OptionalProperty;
/**

@@ -7,0 +5,0 @@ * Returns if a value represents an optional type.

{
"name": "mobx-state-tree",
"version": "3.2.4",
"version": "3.3.0",
"description": "Opinionated, transactional, MobX powered state container",

@@ -5,0 +5,0 @@ "main": "dist/mobx-state-tree.js",

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc