mobx-state-tree 6.0.0-pre.2 → 6.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -356,7 +356,7 @@ function protect(target) {
356
356
  assertIsStateTreeNode(target, 1);
357
357
  var node = getStateTreeNode(target);
358
358
  if (!node.isRoot)
359
- throw fail("`protect` can only be invoked on root nodes");
359
+ throw new MstError("`protect` can only be invoked on root nodes");
360
360
  node.isProtectionEnabled = true;
361
361
  }
362
362
  /**
@@ -388,7 +388,7 @@ function unprotect(target) {
388
388
  assertIsStateTreeNode(target, 1);
389
389
  var node = getStateTreeNode(target);
390
390
  if (!node.isRoot)
391
- throw fail("`unprotect` can only be invoked on root nodes");
391
+ throw new MstError("`unprotect` can only be invoked on root nodes");
392
392
  node.isProtectionEnabled = false;
393
393
  }
394
394
  /**
@@ -471,7 +471,7 @@ function getParent(target, depth) {
471
471
  return parent.storedValue;
472
472
  parent = parent.parent;
473
473
  }
474
- throw fail("Failed to find the parent of ".concat(getStateTreeNode(target), " at depth ").concat(depth));
474
+ throw new MstError("Failed to find the parent of ".concat(getStateTreeNode(target), " at depth ").concat(depth));
475
475
  }
476
476
  /**
477
477
  * Given a model instance, returns `true` if the object has a parent of given type, that is, is part of another object, map or array
@@ -509,7 +509,7 @@ function getParentOfType(target, type) {
509
509
  return parent.storedValue;
510
510
  parent = parent.parent;
511
511
  }
512
- throw fail("Failed to find the parent of ".concat(getStateTreeNode(target), " of a given type"));
512
+ throw new MstError("Failed to find the parent of ".concat(getStateTreeNode(target), " of a given type"));
513
513
  }
514
514
  /**
515
515
  * Given an object in a model tree, returns the root object of that tree.
@@ -626,7 +626,7 @@ function tryReference(getter, checkIfAlive) {
626
626
  }
627
627
  }
628
628
  else {
629
- throw fail("The reference to be checked is not one of node, null or undefined");
629
+ throw new MstError("The reference to be checked is not one of node, null or undefined");
630
630
  }
631
631
  }
632
632
  catch (e) {
@@ -654,7 +654,7 @@ function isValidReference(getter, checkIfAlive) {
654
654
  return checkIfAlive ? isAlive(node) : true;
655
655
  }
656
656
  else {
657
- throw fail("The reference to be checked is not one of node, null or undefined");
657
+ throw new MstError("The reference to be checked is not one of node, null or undefined");
658
658
  }
659
659
  }
660
660
  catch (e) {
@@ -811,7 +811,7 @@ function getEnv(target) {
811
811
  var node = getStateTreeNode(target);
812
812
  var env = node.root.environment;
813
813
  if (!env)
814
- throw fail("Failed to find the environment of ".concat(node, " ").concat(node.path));
814
+ throw new MstError("Failed to find the environment of ".concat(node, " ").concat(node.path));
815
815
  return env;
816
816
  }
817
817
  /**
@@ -825,7 +825,7 @@ function hasEnv(target) {
825
825
  // check all arguments
826
826
  if (process.env.NODE_ENV !== "production") {
827
827
  if (!isStateTreeNode(target))
828
- fail("expected first argument to be a mobx-state-tree node, got " + target + " instead");
828
+ throw new MstError("expected first argument to be a mobx-state-tree node, got " + target + " instead");
829
829
  }
830
830
  var node = getStateTreeNode(target);
831
831
  var env = node.root.environment;
@@ -894,14 +894,18 @@ function getMembers(target) {
894
894
  reflected.volatile.push(key);
895
895
  return;
896
896
  }
897
- if (descriptor.value._isMSTAction === true)
898
- reflected.actions.push(key);
899
- if (descriptor.value._isFlowAction === true)
897
+ if (descriptor.value._isFlowAction === true) {
900
898
  reflected.flowActions.push(key);
901
- else if (mobx.isObservableProp(target, key))
899
+ }
900
+ if (descriptor.value._isMSTAction === true) {
901
+ reflected.actions.push(key);
902
+ }
903
+ else if (mobx.isObservableProp(target, key)) {
902
904
  reflected.volatile.push(key);
903
- else
905
+ }
906
+ else {
904
907
  reflected.views.push(key);
908
+ }
905
909
  });
906
910
  return reflected;
907
911
  }
@@ -1255,7 +1259,7 @@ var BaseNode = /** @class */ (function () {
1255
1259
  if (devMode()) {
1256
1260
  if (!this.isAlive) {
1257
1261
  // istanbul ignore next
1258
- throw fail("assertion failed: cannot finalize the creation of a node that is already dead");
1262
+ throw new MstError("assertion failed: cannot finalize the creation of a node that is already dead");
1259
1263
  }
1260
1264
  }
1261
1265
  // goal: afterCreate hooks runs depth-first. After attach runs parent first, so on afterAttach the parent has completed already
@@ -1326,7 +1330,7 @@ var ScalarNode = /** @class */ (function (_super) {
1326
1330
  get: function () {
1327
1331
  // future optimization: store root ref in the node and maintain it
1328
1332
  if (!this.parent)
1329
- throw fail("This scalar node is not part of a tree");
1333
+ throw new MstError("This scalar node is not part of a tree");
1330
1334
  return this.parent.root;
1331
1335
  },
1332
1336
  enumerable: false,
@@ -1345,15 +1349,15 @@ var ScalarNode = /** @class */ (function (_super) {
1345
1349
  if (devMode()) {
1346
1350
  if (!subpath) {
1347
1351
  // istanbul ignore next
1348
- throw fail("assertion failed: subpath expected");
1352
+ throw new MstError("assertion failed: subpath expected");
1349
1353
  }
1350
1354
  if (!newParent) {
1351
1355
  // istanbul ignore next
1352
- throw fail("assertion failed: parent expected");
1356
+ throw new MstError("assertion failed: parent expected");
1353
1357
  }
1354
1358
  if (parentChanged) {
1355
1359
  // istanbul ignore next
1356
- throw fail("assertion failed: scalar nodes cannot change their parent");
1360
+ throw new MstError("assertion failed: scalar nodes cannot change their parent");
1357
1361
  }
1358
1362
  }
1359
1363
  this.environment = undefined; // use parent's
@@ -1432,6 +1436,21 @@ var ScalarNode = /** @class */ (function (_super) {
1432
1436
  ScalarNode.prototype.die = mobx.action(ScalarNode.prototype.die);
1433
1437
 
1434
1438
  var nextNodeId = 1;
1439
+ var ObservableInstanceLifecycle;
1440
+ (function (ObservableInstanceLifecycle) {
1441
+ // the actual observable instance has not been created yet
1442
+ ObservableInstanceLifecycle[ObservableInstanceLifecycle["UNINITIALIZED"] = 0] = "UNINITIALIZED";
1443
+ // the actual observable instance is being created
1444
+ ObservableInstanceLifecycle[ObservableInstanceLifecycle["CREATING"] = 1] = "CREATING";
1445
+ // the actual observable instance has been created
1446
+ ObservableInstanceLifecycle[ObservableInstanceLifecycle["CREATED"] = 2] = "CREATED";
1447
+ })(ObservableInstanceLifecycle || (ObservableInstanceLifecycle = {}));
1448
+ var InternalEvents;
1449
+ (function (InternalEvents) {
1450
+ InternalEvents["Dispose"] = "dispose";
1451
+ InternalEvents["Patch"] = "patch";
1452
+ InternalEvents["Snapshot"] = "snapshot";
1453
+ })(InternalEvents || (InternalEvents = {}));
1435
1454
  var snapshotReactionOptions = {
1436
1455
  onError: function (e) {
1437
1456
  throw e;
@@ -1527,7 +1546,7 @@ var ObjectNode = /** @class */ (function (_super) {
1527
1546
  enumerable: true,
1528
1547
  configurable: true,
1529
1548
  writable: true,
1530
- value: 0 /* ObservableInstanceLifecycle.UNINITIALIZED */
1549
+ value: ObservableInstanceLifecycle.UNINITIALIZED
1531
1550
  });
1532
1551
  Object.defineProperty(_this, "_childNodes", {
1533
1552
  enumerable: true,
@@ -1594,7 +1613,7 @@ var ObjectNode = /** @class */ (function (_super) {
1594
1613
  }
1595
1614
  }
1596
1615
  if (typeof id !== "string" && typeof id !== "number") {
1597
- throw fail("Instance identifier '".concat(_this.identifierAttribute, "' for type '").concat(_this.type.name, "' must be a string or a number"));
1616
+ throw new MstError("Instance identifier '".concat(_this.identifierAttribute, "' for type '").concat(_this.type.name, "' must be a string or a number"));
1598
1617
  }
1599
1618
  // normalize internal identifier to string
1600
1619
  _this.identifier = normalizeIdentifier(id);
@@ -1632,7 +1651,7 @@ var ObjectNode = /** @class */ (function (_super) {
1632
1651
  writable: true,
1633
1652
  value: function (fireHooks) {
1634
1653
  if (fireHooks === void 0) { fireHooks = true; }
1635
- if (this._observableInstanceState === 0 /* ObservableInstanceLifecycle.UNINITIALIZED */) {
1654
+ if (this._observableInstanceState === ObservableInstanceLifecycle.UNINITIALIZED) {
1636
1655
  this.createObservableInstance(fireHooks);
1637
1656
  }
1638
1657
  }
@@ -1647,10 +1666,10 @@ var ObjectNode = /** @class */ (function (_super) {
1647
1666
  if (devMode()) {
1648
1667
  if (this.state !== NodeLifeCycle.INITIALIZING) {
1649
1668
  // istanbul ignore next
1650
- throw fail("assertion failed: the creation of the observable instance must be done on the initializing phase");
1669
+ throw new MstError("assertion failed: the creation of the observable instance must be done on the initializing phase");
1651
1670
  }
1652
1671
  }
1653
- this._observableInstanceState = 1 /* ObservableInstanceLifecycle.CREATING */;
1672
+ this._observableInstanceState = ObservableInstanceLifecycle.CREATING;
1654
1673
  // make sure the parent chain is created as well
1655
1674
  // array with parent chain from parent to child
1656
1675
  var parentChain = [];
@@ -1660,7 +1679,7 @@ var ObjectNode = /** @class */ (function (_super) {
1660
1679
  // this is done to avoid traversing the whole tree to the root when using
1661
1680
  // the same reference again
1662
1681
  while (parent &&
1663
- parent._observableInstanceState === 0 /* ObservableInstanceLifecycle.UNINITIALIZED */) {
1682
+ parent._observableInstanceState === ObservableInstanceLifecycle.UNINITIALIZED) {
1664
1683
  parentChain.unshift(parent);
1665
1684
  parent = parent.parent;
1666
1685
  }
@@ -1694,7 +1713,7 @@ var ObjectNode = /** @class */ (function (_super) {
1694
1713
  finally {
1695
1714
  this._isRunningAction = false;
1696
1715
  }
1697
- this._observableInstanceState = 2 /* ObservableInstanceLifecycle.CREATED */;
1716
+ this._observableInstanceState = ObservableInstanceLifecycle.CREATED;
1698
1717
  this._snapshotComputed.trackAndCompute();
1699
1718
  if (this.isRoot)
1700
1719
  this._addSnapshotReaction();
@@ -1770,20 +1789,20 @@ var ObjectNode = /** @class */ (function (_super) {
1770
1789
  if (devMode()) {
1771
1790
  if (!subpath) {
1772
1791
  // istanbul ignore next
1773
- throw fail("assertion failed: subpath expected");
1792
+ throw new MstError("assertion failed: subpath expected");
1774
1793
  }
1775
1794
  if (!newParent) {
1776
1795
  // istanbul ignore next
1777
- throw fail("assertion failed: new parent expected");
1796
+ throw new MstError("assertion failed: new parent expected");
1778
1797
  }
1779
1798
  if (this.parent && parentChanged) {
1780
- throw fail("A node cannot exists twice in the state tree. Failed to add ".concat(this, " to path '").concat(newParent.path, "/").concat(subpath, "'."));
1799
+ throw new MstError("A node cannot exists twice in the state tree. Failed to add ".concat(this, " to path '").concat(newParent.path, "/").concat(subpath, "'."));
1781
1800
  }
1782
1801
  if (!this.parent && newParent.root === this) {
1783
- throw fail("A state tree is not allowed to contain itself. Cannot assign ".concat(this, " to path '").concat(newParent.path, "/").concat(subpath, "'"));
1802
+ throw new MstError("A state tree is not allowed to contain itself. Cannot assign ".concat(this, " to path '").concat(newParent.path, "/").concat(subpath, "'"));
1784
1803
  }
1785
1804
  if (!this.parent && !!this.environment && this.environment !== newParent.root.environment) {
1786
- throw fail("A state tree cannot be made part of another state tree as long as their environments are different.");
1805
+ throw new MstError("A state tree cannot be made part of another state tree as long as their environments are different.");
1787
1806
  }
1788
1807
  }
1789
1808
  if (parentChanged) {
@@ -1839,7 +1858,7 @@ var ObjectNode = /** @class */ (function (_super) {
1839
1858
  value: function () {
1840
1859
  if (!this.isAlive)
1841
1860
  return this._snapshotUponDeath;
1842
- return this._observableInstanceState === 2 /* ObservableInstanceLifecycle.CREATED */
1861
+ return this._observableInstanceState === ObservableInstanceLifecycle.CREATED
1843
1862
  ? this._getActualSnapshot()
1844
1863
  : this._getCachedInitialSnapshot();
1845
1864
  }
@@ -1889,7 +1908,7 @@ var ObjectNode = /** @class */ (function (_super) {
1889
1908
  var error = this._getAssertAliveError(context);
1890
1909
  switch (livelinessChecking) {
1891
1910
  case "error":
1892
- throw fail(error);
1911
+ throw new MstError(error);
1893
1912
  case "warn":
1894
1913
  warnError(error);
1895
1914
  }
@@ -1927,7 +1946,7 @@ var ObjectNode = /** @class */ (function (_super) {
1927
1946
  });
1928
1947
  this._autoUnbox = false;
1929
1948
  try {
1930
- return this._observableInstanceState === 2 /* ObservableInstanceLifecycle.CREATED */
1949
+ return this._observableInstanceState === ObservableInstanceLifecycle.CREATED
1931
1950
  ? this.type.getChildNode(this, subpath)
1932
1951
  : this._childNodes[subpath];
1933
1952
  }
@@ -1944,7 +1963,7 @@ var ObjectNode = /** @class */ (function (_super) {
1944
1963
  this.assertAlive(EMPTY_OBJECT);
1945
1964
  this._autoUnbox = false;
1946
1965
  try {
1947
- return this._observableInstanceState === 2 /* ObservableInstanceLifecycle.CREATED */
1966
+ return this._observableInstanceState === ObservableInstanceLifecycle.CREATED
1948
1967
  ? this.type.getChildren(this)
1949
1968
  : convertChildNodesToArray(this._childNodes);
1950
1969
  }
@@ -1975,7 +1994,7 @@ var ObjectNode = /** @class */ (function (_super) {
1975
1994
  value: function (context) {
1976
1995
  this.assertAlive(context);
1977
1996
  if (!this.isRunningAction() && this.isProtected) {
1978
- throw fail("Cannot modify '".concat(this, "', the object is protected and can only be modified by using an action."));
1997
+ throw new MstError("Cannot modify '".concat(this, "', the object is protected and can only be modified by using an action."));
1979
1998
  }
1980
1999
  }
1981
2000
  });
@@ -2042,7 +2061,7 @@ var ObjectNode = /** @class */ (function (_super) {
2042
2061
  writable: true,
2043
2062
  value: function () {
2044
2063
  if (!this.isAlive)
2045
- throw fail("Error while detaching, node is not alive.");
2064
+ throw new MstError("Error while detaching, node is not alive.");
2046
2065
  this.clearParent();
2047
2066
  }
2048
2067
  });
@@ -2090,7 +2109,7 @@ var ObjectNode = /** @class */ (function (_super) {
2090
2109
  configurable: true,
2091
2110
  writable: true,
2092
2111
  value: function () {
2093
- if (this._observableInstanceState === 0 /* ObservableInstanceLifecycle.UNINITIALIZED */) {
2112
+ if (this._observableInstanceState === ObservableInstanceLifecycle.UNINITIALIZED) {
2094
2113
  return;
2095
2114
  }
2096
2115
  this.getChildren().forEach(function (node) {
@@ -2099,8 +2118,8 @@ var ObjectNode = /** @class */ (function (_super) {
2099
2118
  // beforeDestroy should run before the disposers since else we could end up in a situation where
2100
2119
  // a disposer added with addDisposer at this stage (beforeDestroy) is actually never released
2101
2120
  this.baseAboutToDie();
2102
- this._internalEventsEmit("dispose" /* InternalEvents.Dispose */);
2103
- this._internalEventsClear("dispose" /* InternalEvents.Dispose */);
2121
+ this._internalEventsEmit(InternalEvents.Dispose);
2122
+ this._internalEventsClear(InternalEvents.Dispose);
2104
2123
  }
2105
2124
  });
2106
2125
  Object.defineProperty(ObjectNode.prototype, "finalizeDeath", {
@@ -2126,7 +2145,7 @@ var ObjectNode = /** @class */ (function (_super) {
2126
2145
  writable: true,
2127
2146
  value: function (onChange) {
2128
2147
  this._addSnapshotReaction();
2129
- return this._internalEventsRegister("snapshot" /* InternalEvents.Snapshot */, onChange);
2148
+ return this._internalEventsRegister(InternalEvents.Snapshot, onChange);
2130
2149
  }
2131
2150
  });
2132
2151
  Object.defineProperty(ObjectNode.prototype, "emitSnapshot", {
@@ -2134,7 +2153,7 @@ var ObjectNode = /** @class */ (function (_super) {
2134
2153
  configurable: true,
2135
2154
  writable: true,
2136
2155
  value: function (snapshot) {
2137
- this._internalEventsEmit("snapshot" /* InternalEvents.Snapshot */, snapshot);
2156
+ this._internalEventsEmit(InternalEvents.Snapshot, snapshot);
2138
2157
  }
2139
2158
  });
2140
2159
  Object.defineProperty(ObjectNode.prototype, "onPatch", {
@@ -2142,7 +2161,7 @@ var ObjectNode = /** @class */ (function (_super) {
2142
2161
  configurable: true,
2143
2162
  writable: true,
2144
2163
  value: function (handler) {
2145
- return this._internalEventsRegister("patch" /* InternalEvents.Patch */, handler);
2164
+ return this._internalEventsRegister(InternalEvents.Patch, handler);
2146
2165
  }
2147
2166
  });
2148
2167
  Object.defineProperty(ObjectNode.prototype, "emitPatch", {
@@ -2150,12 +2169,12 @@ var ObjectNode = /** @class */ (function (_super) {
2150
2169
  configurable: true,
2151
2170
  writable: true,
2152
2171
  value: function (basePatch, source) {
2153
- if (this._internalEventsHasSubscribers("patch" /* InternalEvents.Patch */)) {
2172
+ if (this._internalEventsHasSubscribers(InternalEvents.Patch)) {
2154
2173
  // calculate the relative path of the patch
2155
2174
  var path = source.path.substr(this.path.length) + (basePatch.path ? "/" + basePatch.path : "");
2156
2175
  var localizedPatch = extend({}, basePatch, { path: path });
2157
2176
  var _a = __read(splitPatch(localizedPatch), 2), patch = _a[0], reversePatch = _a[1];
2158
- this._internalEventsEmit("patch" /* InternalEvents.Patch */, patch, reversePatch);
2177
+ this._internalEventsEmit(InternalEvents.Patch, patch, reversePatch);
2159
2178
  }
2160
2179
  if (this.parent)
2161
2180
  this.parent.emitPatch(basePatch, source);
@@ -2166,7 +2185,7 @@ var ObjectNode = /** @class */ (function (_super) {
2166
2185
  configurable: true,
2167
2186
  writable: true,
2168
2187
  value: function (disposer) {
2169
- return this._internalEventsHas("dispose" /* InternalEvents.Dispose */, disposer);
2188
+ return this._internalEventsHas(InternalEvents.Dispose, disposer);
2170
2189
  }
2171
2190
  });
2172
2191
  Object.defineProperty(ObjectNode.prototype, "addDisposer", {
@@ -2175,10 +2194,10 @@ var ObjectNode = /** @class */ (function (_super) {
2175
2194
  writable: true,
2176
2195
  value: function (disposer) {
2177
2196
  if (!this.hasDisposer(disposer)) {
2178
- this._internalEventsRegister("dispose" /* InternalEvents.Dispose */, disposer, true);
2197
+ this._internalEventsRegister(InternalEvents.Dispose, disposer, true);
2179
2198
  return;
2180
2199
  }
2181
- throw fail("cannot add a disposer when it is already registered for execution");
2200
+ throw new MstError("cannot add a disposer when it is already registered for execution");
2182
2201
  }
2183
2202
  });
2184
2203
  Object.defineProperty(ObjectNode.prototype, "removeDisposer", {
@@ -2186,10 +2205,10 @@ var ObjectNode = /** @class */ (function (_super) {
2186
2205
  configurable: true,
2187
2206
  writable: true,
2188
2207
  value: function (disposer) {
2189
- if (!this._internalEventsHas("dispose" /* InternalEvents.Dispose */, disposer)) {
2190
- throw fail("cannot remove a disposer which was never registered for execution");
2208
+ if (!this._internalEventsHas(InternalEvents.Dispose, disposer)) {
2209
+ throw new MstError("cannot remove a disposer which was never registered for execution");
2191
2210
  }
2192
- this._internalEventsUnregister("dispose" /* InternalEvents.Dispose */, disposer);
2211
+ this._internalEventsUnregister(InternalEvents.Dispose, disposer);
2193
2212
  }
2194
2213
  });
2195
2214
  Object.defineProperty(ObjectNode.prototype, "removeMiddleware", {
@@ -2433,7 +2452,7 @@ var BaseType = /** @class */ (function () {
2433
2452
  writable: true,
2434
2453
  value: function (node, applyPostProcess) {
2435
2454
  // istanbul ignore next
2436
- throw fail("unimplemented method");
2455
+ throw new MstError("unimplemented method");
2437
2456
  }
2438
2457
  });
2439
2458
  Object.defineProperty(BaseType.prototype, "isAssignableFrom", {
@@ -2471,7 +2490,7 @@ var BaseType = /** @class */ (function () {
2471
2490
  Object.defineProperty(BaseType.prototype, "Type", {
2472
2491
  get: function () {
2473
2492
  // istanbul ignore next
2474
- throw fail("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`");
2493
+ throw new MstError("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`");
2475
2494
  },
2476
2495
  enumerable: false,
2477
2496
  configurable: true
@@ -2479,7 +2498,7 @@ var BaseType = /** @class */ (function () {
2479
2498
  Object.defineProperty(BaseType.prototype, "TypeWithoutSTN", {
2480
2499
  get: function () {
2481
2500
  // istanbul ignore next
2482
- throw fail("Factory.TypeWithoutSTN should not be actually called. It is just a Type signature that can be used at compile time with Typescript, by using `typeof type.TypeWithoutSTN`");
2501
+ throw new MstError("Factory.TypeWithoutSTN should not be actually called. It is just a Type signature that can be used at compile time with Typescript, by using `typeof type.TypeWithoutSTN`");
2483
2502
  },
2484
2503
  enumerable: false,
2485
2504
  configurable: true
@@ -2487,7 +2506,7 @@ var BaseType = /** @class */ (function () {
2487
2506
  Object.defineProperty(BaseType.prototype, "SnapshotType", {
2488
2507
  get: function () {
2489
2508
  // istanbul ignore next
2490
- throw fail("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`");
2509
+ throw new MstError("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`");
2491
2510
  },
2492
2511
  enumerable: false,
2493
2512
  configurable: true
@@ -2495,7 +2514,7 @@ var BaseType = /** @class */ (function () {
2495
2514
  Object.defineProperty(BaseType.prototype, "CreationType", {
2496
2515
  get: function () {
2497
2516
  // istanbul ignore next
2498
- throw fail("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`");
2517
+ throw new MstError("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`");
2499
2518
  },
2500
2519
  enumerable: false,
2501
2520
  configurable: true
@@ -2985,7 +3004,7 @@ function applyAction(target, actions) {
2985
3004
  function baseApplyAction(target, action) {
2986
3005
  var resolvedTarget = tryResolve(target, action.path || "");
2987
3006
  if (!resolvedTarget)
2988
- throw fail("Invalid action path: ".concat(action.path || ""));
3007
+ throw new MstError("Invalid action path: ".concat(action.path || ""));
2989
3008
  var node = getStateTreeNode(resolvedTarget);
2990
3009
  // Reserved functions
2991
3010
  if (action.name === "@APPLY_PATCHES") {
@@ -2995,7 +3014,7 @@ function baseApplyAction(target, action) {
2995
3014
  return applySnapshot.call(null, resolvedTarget, action.args[0]);
2996
3015
  }
2997
3016
  if (!(typeof resolvedTarget[action.name] === "function"))
2998
- throw fail("Action '".concat(action.name, "' does not exist in '").concat(node.path, "'"));
3017
+ throw new MstError("Action '".concat(action.name, "' does not exist in '").concat(node.path, "'"));
2999
3018
  return resolvedTarget[action.name].apply(resolvedTarget, action.args ? action.args.map(function (v) { return deserializeArgument(node, v); }) : []);
3000
3019
  }
3001
3020
  /**
@@ -3356,11 +3375,11 @@ function runMiddleWares(node, baseCall, originalFn) {
3356
3375
  if (devMode()) {
3357
3376
  if (!nextInvoked && !abortInvoked) {
3358
3377
  var node2 = getStateTreeNode(call.tree);
3359
- throw fail("Neither the next() nor the abort() callback within the middleware ".concat(handler.name, " for the action: \"").concat(call.name, "\" on the node: ").concat(node2.type.name, " was invoked."));
3378
+ throw new MstError("Neither the next() nor the abort() callback within the middleware ".concat(handler.name, " for the action: \"").concat(call.name, "\" on the node: ").concat(node2.type.name, " was invoked."));
3360
3379
  }
3361
3380
  else if (nextInvoked && abortInvoked) {
3362
3381
  var node2 = getStateTreeNode(call.tree);
3363
- throw fail("The next() and abort() callback within the middleware ".concat(handler.name, " for the action: \"").concat(call.name, "\" on the node: ").concat(node2.type.name, " were invoked."));
3382
+ throw new MstError("The next() and abort() callback within the middleware ".concat(handler.name, " for the action: \"").concat(call.name, "\" on the node: ").concat(node2.type.name, " were invoked."));
3364
3383
  }
3365
3384
  }
3366
3385
  return result;
@@ -3507,7 +3526,7 @@ function typecheckInternal(type, value) {
3507
3526
  function typecheck(type, value) {
3508
3527
  var errors = type.validate(value, [{ path: "", type: type }]);
3509
3528
  if (errors.length > 0) {
3510
- throw fail(validationErrorsToString(type, value, errors));
3529
+ throw new MstError(validationErrorsToString(type, value, errors));
3511
3530
  }
3512
3531
  }
3513
3532
  function validationErrorsToString(type, value, errors) {
@@ -3578,7 +3597,7 @@ var IdentifierCache = /** @class */ (function () {
3578
3597
  }
3579
3598
  var set = this.cache.get(identifier);
3580
3599
  if (set.indexOf(node) !== -1)
3581
- throw fail("Already registered");
3600
+ throw new MstError("Already registered");
3582
3601
  set.push(node);
3583
3602
  if (lastCacheUpdate) {
3584
3603
  this.updateLastCacheModificationPerId(identifier);
@@ -3677,7 +3696,7 @@ var IdentifierCache = /** @class */ (function () {
3677
3696
  case 1:
3678
3697
  return matches[0];
3679
3698
  default:
3680
- throw fail("Cannot resolve a reference to type '".concat(type.name, "' with id: '").concat(identifier, "' unambigously, there are multiple candidates: ").concat(matches
3699
+ throw new MstError("Cannot resolve a reference to type '".concat(type.name, "' with id: '").concat(identifier, "' unambigously, there are multiple candidates: ").concat(matches
3681
3700
  .map(function (n) { return n.path; })
3682
3701
  .join(", ")));
3683
3702
  }
@@ -3695,7 +3714,7 @@ function createObjectNode(type, parent, subpath, environment, initialValue) {
3695
3714
  if (existingNode) {
3696
3715
  if (existingNode.parent) {
3697
3716
  // istanbul ignore next
3698
- throw fail("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 '".concat(parent ? parent.path : "", "/").concat(subpath, "', but it lives already at '").concat(existingNode.path, "'"));
3717
+ throw new MstError("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 '".concat(parent ? parent.path : "", "/").concat(subpath, "', but it lives already at '").concat(existingNode.path, "'"));
3699
3718
  }
3700
3719
  if (parent) {
3701
3720
  existingNode.setParent(parent, subpath);
@@ -3758,7 +3777,7 @@ function assertIsStateTreeNode(value, argNumber) {
3758
3777
  function getStateTreeNode(value) {
3759
3778
  if (!isStateTreeNode(value)) {
3760
3779
  // istanbul ignore next
3761
- throw fail("Value ".concat(value, " is no MST Node"));
3780
+ throw new MstError("Value ".concat(value, " is no MST Node"));
3762
3781
  }
3763
3782
  return value.$treenode;
3764
3783
  }
@@ -3784,7 +3803,7 @@ var doubleDot = function (_) { return ".."; };
3784
3803
  function getRelativePathBetweenNodes(base, target) {
3785
3804
  // PRE condition target is (a child of) base!
3786
3805
  if (base.root !== target.root) {
3787
- throw fail("Cannot calculate relative path: objects '".concat(base, "' and '").concat(target, "' are not part of the same object tree"));
3806
+ throw new MstError("Cannot calculate relative path: objects '".concat(base, "' and '").concat(target, "' are not part of the same object tree"));
3788
3807
  }
3789
3808
  var baseParts = splitJsonPath(base.path);
3790
3809
  var targetParts = splitJsonPath(target.path);
@@ -3841,7 +3860,7 @@ function resolveNodeByPathParts(base, pathParts, failIfResolveFails) {
3841
3860
  }
3842
3861
  }
3843
3862
  }
3844
- throw fail("Could not resolve '".concat(part, "' in path '").concat(joinJsonPath(pathParts.slice(0, i)) || "/", "' while resolving '").concat(joinJsonPath(pathParts), "'"));
3863
+ throw new MstError("Could not resolve '".concat(part, "' in path '").concat(joinJsonPath(pathParts.slice(0, i)) || "/", "' while resolving '").concat(joinJsonPath(pathParts), "'"));
3845
3864
  }
3846
3865
  }
3847
3866
  catch (e) {
@@ -3917,10 +3936,14 @@ Object.freeze(mobxShallow);
3917
3936
  * @internal
3918
3937
  * @hidden
3919
3938
  */
3920
- function fail(message) {
3921
- if (message === void 0) { message = "Illegal state"; }
3922
- return new Error("[mobx-state-tree] " + message);
3923
- }
3939
+ var MstError = /** @class */ (function (_super) {
3940
+ __extends(MstError, _super);
3941
+ function MstError(message) {
3942
+ if (message === void 0) { message = "Illegal state"; }
3943
+ return _super.call(this, "[mobx-state-tree] ".concat(message)) || this;
3944
+ }
3945
+ return MstError;
3946
+ }(Error));
3924
3947
  /**
3925
3948
  * @internal
3926
3949
  * @hidden
@@ -4324,7 +4347,7 @@ function assertArg(value, fn, typeName, argNumber) {
4324
4347
  if (devMode()) {
4325
4348
  if (!fn(value)) {
4326
4349
  // istanbul ignore next
4327
- throw fail("expected ".concat(typeName, " as argument ").concat(asArray(argNumber).join(" or "), ", got ").concat(value, " instead"));
4350
+ throw new MstError("expected ".concat(typeName, " as argument ").concat(asArray(argNumber).join(" or "), ", got ").concat(value, " instead"));
4328
4351
  }
4329
4352
  }
4330
4353
  }
@@ -4469,11 +4492,11 @@ function createFlowSpawner(name, generator) {
4469
4492
  var runId = getNextActionId();
4470
4493
  var parentContext = getCurrentActionContext();
4471
4494
  if (!parentContext) {
4472
- throw fail("a mst flow must always have a parent context");
4495
+ throw new MstError("a mst flow must always have a parent context");
4473
4496
  }
4474
4497
  var parentActionContext = getParentActionContext(parentContext);
4475
4498
  if (!parentActionContext) {
4476
- throw fail("a mst flow must always have a parent action context");
4499
+ throw new MstError("a mst flow must always have a parent action context");
4477
4500
  }
4478
4501
  var contextBase = {
4479
4502
  name: name,
@@ -4544,7 +4567,7 @@ function createFlowSpawner(name, generator) {
4544
4567
  // TODO: support more type of values? See https://github.com/tj/co/blob/249bbdc72da24ae44076afd716349d2089b31c4c/index.js#L100
4545
4568
  if (!ret.value || typeof ret.value.then !== "function") {
4546
4569
  // istanbul ignore next
4547
- throw fail("Only promises can be yielded to `async`, got: " + ret);
4570
+ throw new MstError("Only promises can be yielded to `async`, got: " + ret);
4548
4571
  }
4549
4572
  return ret.value.then(onFulfilled, onRejected);
4550
4573
  }
@@ -4560,7 +4583,7 @@ function createFlowSpawner(name, generator) {
4560
4583
  */
4561
4584
  function splitPatch(patch) {
4562
4585
  if (!("oldValue" in patch))
4563
- throw fail("Patches without `oldValue` field cannot be inversed");
4586
+ throw new MstError("Patches without `oldValue` field cannot be inversed");
4564
4587
  return [stripPatch(patch), invertPatch(patch)];
4565
4588
  }
4566
4589
  /**
@@ -4661,7 +4684,7 @@ function splitJsonPath(path) {
4661
4684
  stringStartsWith(path, "./") ||
4662
4685
  stringStartsWith(path, "../");
4663
4686
  if (!valid) {
4664
- throw fail("a json path must be either rooted, empty or relative, but got '".concat(path, "'"));
4687
+ throw new MstError("a json path must be either rooted, empty or relative, but got '".concat(path, "'"));
4665
4688
  }
4666
4689
  // '/a/b/c' -> ["a", "b", "c"]
4667
4690
  // '../../b/c' -> ["..", "..", "b", "c"]
@@ -4916,11 +4939,11 @@ function snapshotProcessor(type, processors, name) {
4916
4939
  if (devMode()) {
4917
4940
  if (processors.postProcessor && typeof processors.postProcessor !== "function") {
4918
4941
  // istanbul ignore next
4919
- throw fail("postSnapshotProcessor must be a function");
4942
+ throw new MstError("postSnapshotProcessor must be a function");
4920
4943
  }
4921
4944
  if (processors.preProcessor && typeof processors.preProcessor !== "function") {
4922
4945
  // istanbul ignore next
4923
- throw fail("preSnapshotProcessor must be a function");
4946
+ throw new MstError("preSnapshotProcessor must be a function");
4924
4947
  }
4925
4948
  }
4926
4949
  return new SnapshotProcessor(type, processors, name);
@@ -5009,28 +5032,28 @@ var MSTMap = /** @class */ (function (_super) {
5009
5032
  writable: true,
5010
5033
  value: function (value) {
5011
5034
  if (!value)
5012
- throw fail("Map.put cannot be used to set empty values");
5035
+ throw new MstError("Map.put cannot be used to set empty values");
5013
5036
  if (isStateTreeNode(value)) {
5014
5037
  var node = getStateTreeNode(value);
5015
5038
  if (devMode()) {
5016
5039
  if (!node.identifierAttribute) {
5017
- throw fail(needsIdentifierError);
5040
+ throw new MstError(needsIdentifierError);
5018
5041
  }
5019
5042
  }
5020
5043
  if (node.identifier === null) {
5021
- throw fail(needsIdentifierError);
5044
+ throw new MstError(needsIdentifierError);
5022
5045
  }
5023
5046
  this.set(node.identifier, value);
5024
5047
  return value;
5025
5048
  }
5026
5049
  else if (!isMutable(value)) {
5027
- throw fail("Map.put can only be used to store complex values");
5050
+ throw new MstError("Map.put can only be used to store complex values");
5028
5051
  }
5029
5052
  else {
5030
5053
  var mapNode = getStateTreeNode(this);
5031
5054
  var mapType = mapNode.type;
5032
5055
  if (mapType.identifierMode !== MapIdentifierMode.YES) {
5033
- throw fail(needsIdentifierError);
5056
+ throw new MstError(needsIdentifierError);
5034
5057
  }
5035
5058
  var idAttr = mapType.mapIdentifierAttribute;
5036
5059
  var id = value[idAttr];
@@ -5123,7 +5146,7 @@ var MapType = /** @class */ (function (_super) {
5123
5146
  if (!type.identifierAttribute)
5124
5147
  return current;
5125
5148
  if (current && current !== type.identifierAttribute) {
5126
- throw fail("The objects in a map should all have the same identifier attribute, expected '".concat(current, "', but child of type '").concat(type.name, "' declared attribute '").concat(type.identifierAttribute, "' as identifier"));
5149
+ throw new MstError("The objects in a map should all have the same identifier attribute, expected '".concat(current, "', but child of type '").concat(type.name, "' declared attribute '").concat(type.identifierAttribute, "' as identifier"));
5127
5150
  }
5128
5151
  return type.identifierAttribute;
5129
5152
  }, undefined);
@@ -5202,7 +5225,7 @@ var MapType = /** @class */ (function (_super) {
5202
5225
  value: function (node, key) {
5203
5226
  var childNode = node.storedValue.get("" + key);
5204
5227
  if (!childNode)
5205
- throw fail("Not a child " + key);
5228
+ throw new MstError("Not a child " + key);
5206
5229
  return childNode;
5207
5230
  }
5208
5231
  });
@@ -5247,7 +5270,7 @@ var MapType = /** @class */ (function (_super) {
5247
5270
  if (this.identifierMode === MapIdentifierMode.YES && node instanceof ObjectNode) {
5248
5271
  var identifier = node.identifier;
5249
5272
  if (identifier !== expected)
5250
- throw fail("A map of objects containing an identifier should always store the object under their own identifier. Trying to store key '".concat(identifier, "', but expected: '").concat(expected, "'"));
5273
+ throw new MstError("A map of objects containing an identifier should always store the object under their own identifier. Trying to store key '".concat(identifier, "', but expected: '").concat(expected, "'"));
5251
5274
  }
5252
5275
  }
5253
5276
  });
@@ -5545,7 +5568,7 @@ var ArrayType = /** @class */ (function (_super) {
5545
5568
  var index = Number(key);
5546
5569
  if (index < node.storedValue.length)
5547
5570
  return node.storedValue[index];
5548
- throw fail("Not a child: " + key);
5571
+ throw new MstError("Not a child: " + key);
5549
5572
  }
5550
5573
  });
5551
5574
  Object.defineProperty(ArrayType.prototype, "willChange", {
@@ -5779,7 +5802,7 @@ function reconcileArrayChildren(parent, childType, oldNodes, newValues, newPaths
5779
5802
  // check if already belongs to the same parent. if so, avoid pushing item in. only swapping can occur.
5780
5803
  if (isStateTreeNode(newValue) && getStateTreeNode(newValue).parent === parent) {
5781
5804
  // this node is owned by this parent, but not in the reconcilable set, so it must be double
5782
- throw fail("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 '".concat(parent.path, "/").concat(newPath, "', but it lives already at '").concat(getStateTreeNode(newValue).path, "'"));
5805
+ throw new MstError("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 '".concat(parent.path, "/").concat(newPath, "', but it lives already at '").concat(getStateTreeNode(newValue).path, "'"));
5783
5806
  }
5784
5807
  nothingChanged = false;
5785
5808
  var newNode = valueAsNode(childType, parent, newPath, newValue);
@@ -5895,7 +5918,7 @@ function toPropertiesObject(declaredProps) {
5895
5918
  var alreadySeenKeys = new Set();
5896
5919
  keysList.forEach(function (key) {
5897
5920
  if (alreadySeenKeys.has(key)) {
5898
- throw fail("".concat(key, " is declared twice in the model. Model should not contain the same keys"));
5921
+ throw new MstError("".concat(key, " is declared twice in the model. Model should not contain the same keys"));
5899
5922
  }
5900
5923
  alreadySeenKeys.add(key);
5901
5924
  });
@@ -5903,17 +5926,17 @@ function toPropertiesObject(declaredProps) {
5903
5926
  return keysList.reduce(function (props, key) {
5904
5927
  // warn if user intended a HOOK
5905
5928
  if (key in Hook) {
5906
- throw fail("Hook '".concat(key, "' was defined as property. Hooks should be defined as part of the actions"));
5929
+ throw new MstError("Hook '".concat(key, "' was defined as property. Hooks should be defined as part of the actions"));
5907
5930
  }
5908
5931
  // the user intended to use a view
5909
5932
  var descriptor = Object.getOwnPropertyDescriptor(declaredProps, key);
5910
5933
  if ("get" in descriptor) {
5911
- throw fail("Getters are not supported as properties. Please use views instead");
5934
+ throw new MstError("Getters are not supported as properties. Please use views instead");
5912
5935
  }
5913
5936
  // undefined and null are not valid
5914
5937
  var value = descriptor.value;
5915
5938
  if (value === null || value === undefined) {
5916
- throw fail("The default value of an attribute cannot be null or undefined as the type cannot be inferred. Did you mean `types.maybe(someType)`?");
5939
+ throw new MstError("The default value of an attribute cannot be null or undefined as the type cannot be inferred. Did you mean `types.maybe(someType)`?");
5917
5940
  }
5918
5941
  // its a primitive, convert to its type
5919
5942
  else if (isPrimitive(value)) {
@@ -5930,17 +5953,17 @@ function toPropertiesObject(declaredProps) {
5930
5953
  else if (isType(value)) ;
5931
5954
  // its a function, maybe the user wanted a view?
5932
5955
  else if (devMode() && typeof value === "function") {
5933
- throw fail("Invalid type definition for property '".concat(key, "', it looks like you passed a function. Did you forget to invoke it, or did you intend to declare a view / action?"));
5956
+ throw new MstError("Invalid type definition for property '".concat(key, "', it looks like you passed a function. Did you forget to invoke it, or did you intend to declare a view / action?"));
5934
5957
  }
5935
5958
  // no other complex values
5936
5959
  else if (devMode() && typeof value === "object") {
5937
- throw fail("Invalid type definition for property '".concat(key, "', it looks like you passed an object. Try passing another model type or a types.frozen."));
5960
+ throw new MstError("Invalid type definition for property '".concat(key, "', it looks like you passed an object. Try passing another model type or a types.frozen."));
5938
5961
  }
5939
5962
  else {
5940
- throw fail("Invalid type definition for property '".concat(key, "', cannot infer a type from a value like '").concat(value, "' (").concat(typeof value, ")"));
5963
+ throw new MstError("Invalid type definition for property '".concat(key, "', cannot infer a type from a value like '").concat(value, "' (").concat(typeof value, ")"));
5941
5964
  }
5942
5965
  return props;
5943
- }, declaredProps);
5966
+ }, __assign({}, declaredProps));
5944
5967
  }
5945
5968
  /**
5946
5969
  * @internal
@@ -6050,7 +6073,7 @@ var ModelType = /** @class */ (function (_super) {
6050
6073
  this.forAllProps(function (propName, propType) {
6051
6074
  if (propType.flags & TypeFlags.Identifier) {
6052
6075
  if (identifierAttribute)
6053
- throw fail("Cannot define property '".concat(propName, "' as object identifier, property '").concat(identifierAttribute, "' is already defined as identifier property"));
6076
+ throw new MstError("Cannot define property '".concat(propName, "' as object identifier, property '").concat(identifierAttribute, "' is already defined as identifier property"));
6054
6077
  identifierAttribute = propName;
6055
6078
  }
6056
6079
  });
@@ -6091,15 +6114,15 @@ var ModelType = /** @class */ (function (_super) {
6091
6114
  value: function (self, actions) {
6092
6115
  // check if return is correct
6093
6116
  if (!isPlainObject(actions))
6094
- throw fail("actions initializer should return a plain object containing actions");
6117
+ throw new MstError("actions initializer should return a plain object containing actions");
6095
6118
  // bind actions to the object created
6096
6119
  Object.keys(actions).forEach(function (name) {
6097
6120
  // warn if preprocessor was given
6098
6121
  if (name === PRE_PROCESS_SNAPSHOT)
6099
- throw fail("Cannot define action '".concat(PRE_PROCESS_SNAPSHOT, "', it should be defined using 'type.preProcessSnapshot(fn)' instead"));
6122
+ throw new MstError("Cannot define action '".concat(PRE_PROCESS_SNAPSHOT, "', it should be defined using 'type.preProcessSnapshot(fn)' instead"));
6100
6123
  // warn if postprocessor was given
6101
6124
  if (name === POST_PROCESS_SNAPSHOT)
6102
- throw fail("Cannot define action '".concat(POST_PROCESS_SNAPSHOT, "', it should be defined using 'type.postProcessSnapshot(fn)' instead"));
6125
+ throw new MstError("Cannot define action '".concat(POST_PROCESS_SNAPSHOT, "', it should be defined using 'type.postProcessSnapshot(fn)' instead"));
6103
6126
  var action2 = actions[name];
6104
6127
  // apply hook composition
6105
6128
  var baseAction = self[name];
@@ -6129,7 +6152,7 @@ var ModelType = /** @class */ (function (_super) {
6129
6152
  value: function (fn) {
6130
6153
  var _this = this;
6131
6154
  if (typeof fn !== "function") {
6132
- throw fail("You passed an ".concat(typeof fn, " to volatile state as an argument, when function is expected"));
6155
+ throw new MstError("You passed an ".concat(typeof fn, " to volatile state as an argument, when function is expected"));
6133
6156
  }
6134
6157
  var stateInitializer = function (self) {
6135
6158
  _this.instantiateVolatileState(self, fn(self));
@@ -6145,7 +6168,7 @@ var ModelType = /** @class */ (function (_super) {
6145
6168
  value: function (self, state) {
6146
6169
  // check views return
6147
6170
  if (!isPlainObject(state))
6148
- throw fail("volatile state initializer should return a plain object containing state");
6171
+ throw new MstError("volatile state initializer should return a plain object containing state");
6149
6172
  mobx.set(self, state);
6150
6173
  }
6151
6174
  });
@@ -6158,7 +6181,7 @@ var ModelType = /** @class */ (function (_super) {
6158
6181
  var initializer = function (self) {
6159
6182
  var _a = fn(self), actions = _a.actions, views = _a.views, state = _a.state, rest = __rest(_a, ["actions", "views", "state"]);
6160
6183
  for (var key in rest)
6161
- throw fail("The `extend` function should return an object with a subset of the fields 'actions', 'views' and 'state'. Found invalid key '".concat(key, "'"));
6184
+ throw new MstError("The `extend` function should return an object with a subset of the fields 'actions', 'views' and 'state'. Found invalid key '".concat(key, "'"));
6162
6185
  if (state)
6163
6186
  _this.instantiateVolatileState(self, state);
6164
6187
  if (views)
@@ -6190,7 +6213,7 @@ var ModelType = /** @class */ (function (_super) {
6190
6213
  value: function (self, views) {
6191
6214
  // check views return
6192
6215
  if (!isPlainObject(views))
6193
- throw fail("views initializer should return a plain object containing views");
6216
+ throw new MstError("views initializer should return a plain object containing views");
6194
6217
  Object.getOwnPropertyNames(views).forEach(function (key) {
6195
6218
  var _a;
6196
6219
  // is this a computed property?
@@ -6203,7 +6226,7 @@ var ModelType = /** @class */ (function (_super) {
6203
6226
  (!devMode() ? addHiddenFinalProp : addHiddenWritableProp)(self, key, descriptor.value);
6204
6227
  }
6205
6228
  else {
6206
- throw fail("A view member should either be a function or getter based property");
6229
+ throw new MstError("A view member should either be a function or getter based property");
6207
6230
  }
6208
6231
  });
6209
6232
  }
@@ -6319,11 +6342,11 @@ var ModelType = /** @class */ (function (_super) {
6319
6342
  value: function (node, key) {
6320
6343
  var _a;
6321
6344
  if (!(key in this.properties))
6322
- throw fail("Not a value property: " + key);
6345
+ throw new MstError("Not a value property: " + key);
6323
6346
  var adm = mobx._getAdministration(node.storedValue, key);
6324
6347
  var childNode = (_a = adm.raw) === null || _a === void 0 ? void 0 : _a.call(adm);
6325
6348
  if (!childNode)
6326
- throw fail("Node not available for property " + key);
6349
+ throw new MstError("Node not available for property " + key);
6327
6350
  return childNode;
6328
6351
  }
6329
6352
  });
@@ -6342,7 +6365,7 @@ var ModelType = /** @class */ (function (_super) {
6342
6365
  atom.reportObserved();
6343
6366
  }
6344
6367
  catch (e) {
6345
- throw fail("".concat(name, " property is declared twice"));
6368
+ throw new MstError("".concat(name, " property is declared twice"));
6346
6369
  }
6347
6370
  res[name] = _this.getChildNode(node, name).snapshot;
6348
6371
  });
@@ -6370,7 +6393,7 @@ var ModelType = /** @class */ (function (_super) {
6370
6393
  writable: true,
6371
6394
  value: function (node, subpath, patch) {
6372
6395
  if (!(patch.op === "replace" || patch.op === "add")) {
6373
- throw fail("object does not support operation ".concat(patch.op));
6396
+ throw new MstError("object does not support operation ".concat(patch.op));
6374
6397
  }
6375
6398
  node.storedValue[subpath] = patch.value;
6376
6399
  }
@@ -6482,7 +6505,7 @@ function model() {
6482
6505
  args[_i] = arguments[_i];
6483
6506
  }
6484
6507
  if (devMode() && typeof args[0] !== "string" && args[1]) {
6485
- throw fail("Model creation failed. First argument must be a string when two arguments are provided");
6508
+ throw new MstError("Model creation failed. First argument must be a string when two arguments are provided");
6486
6509
  }
6487
6510
  var name = typeof args[0] === "string" ? args.shift() : "AnonymousModel";
6488
6511
  var properties = args.shift() || {};
@@ -6729,7 +6752,7 @@ function getPrimitiveFactoryFromValue(value) {
6729
6752
  if (value instanceof Date)
6730
6753
  return DatePrimitive;
6731
6754
  }
6732
- throw fail("Cannot determine primitive type from value " + value);
6755
+ throw new MstError("Cannot determine primitive type from value " + value);
6733
6756
  }
6734
6757
  /**
6735
6758
  * Returns if a given value represents a primitive type.
@@ -7049,7 +7072,7 @@ var Union = /** @class */ (function (_super) {
7049
7072
  value: function (parent, subpath, environment, initialValue) {
7050
7073
  var type = this.determineType(initialValue, undefined);
7051
7074
  if (!type)
7052
- throw fail("No matching type for union " + this.describe()); // can happen in prod builds
7075
+ throw new MstError("No matching type for union " + this.describe()); // can happen in prod builds
7053
7076
  return type.instantiate(parent, subpath, environment, initialValue);
7054
7077
  }
7055
7078
  });
@@ -7060,7 +7083,7 @@ var Union = /** @class */ (function (_super) {
7060
7083
  value: function (current, newValue, parent, subpath) {
7061
7084
  var type = this.determineType(newValue, current.getReconciliationType());
7062
7085
  if (!type)
7063
- throw fail("No matching type for union " + this.describe()); // can happen in prod builds
7086
+ throw new MstError("No matching type for union " + this.describe()); // can happen in prod builds
7064
7087
  return type.reconcile(current, newValue, parent, subpath);
7065
7088
  }
7066
7089
  });
@@ -7275,7 +7298,7 @@ var OptionalValue = /** @class */ (function (_super) {
7275
7298
  function checkOptionalPreconditions(type, defaultValueOrFunction) {
7276
7299
  // make sure we never pass direct instances
7277
7300
  if (typeof defaultValueOrFunction !== "function" && isStateTreeNode(defaultValueOrFunction)) {
7278
- throw fail("default value cannot be an instance, pass a snapshot or a function that creates an instance/snapshot instead");
7301
+ throw new MstError("default value cannot be an instance, pass a snapshot or a function that creates an instance/snapshot instead");
7279
7302
  }
7280
7303
  assertIsType(type, 1);
7281
7304
  if (devMode()) {
@@ -7414,10 +7437,10 @@ var Late = /** @class */ (function (_super) {
7414
7437
  throw e;
7415
7438
  }
7416
7439
  if (mustSucceed && t === undefined)
7417
- throw fail("Late type seems to be used too early, the definition (still) returns undefined");
7440
+ throw new MstError("Late type seems to be used too early, the definition (still) returns undefined");
7418
7441
  if (t) {
7419
7442
  if (devMode() && !isType(t))
7420
- throw fail("Failed to determine subtype, make sure types.late returns a type definition.");
7443
+ throw new MstError("Failed to determine subtype, make sure types.late returns a type definition.");
7421
7444
  this._subType = t;
7422
7445
  }
7423
7446
  }
@@ -7504,7 +7527,7 @@ function late(nameOrType, maybeType) {
7504
7527
  // checks that the type is actually a late type
7505
7528
  if (devMode()) {
7506
7529
  if (!(typeof type === "function" && type.length === 0))
7507
- throw fail("Invalid late type, expected a function with zero arguments that returns a type, got: " +
7530
+ throw new MstError("Invalid late type, expected a function with zero arguments that returns a type, got: " +
7508
7531
  type);
7509
7532
  }
7510
7533
  return new Late(name, type);
@@ -7787,15 +7810,15 @@ var StoredReference = /** @class */ (function () {
7787
7810
  else if (isStateTreeNode(value)) {
7788
7811
  var targetNode = getStateTreeNode(value);
7789
7812
  if (!targetNode.identifierAttribute)
7790
- throw fail("Can only store references with a defined identifier attribute.");
7813
+ throw new MstError("Can only store references with a defined identifier attribute.");
7791
7814
  var id = targetNode.unnormalizedIdentifier;
7792
7815
  if (id === null || id === undefined) {
7793
- throw fail("Can only store references to tree nodes with a defined identifier.");
7816
+ throw new MstError("Can only store references to tree nodes with a defined identifier.");
7794
7817
  }
7795
7818
  this.identifier = id;
7796
7819
  }
7797
7820
  else {
7798
- throw fail("Can only store references to tree nodes or identifiers, got: '".concat(value, "'"));
7821
+ throw new MstError("Can only store references to tree nodes or identifiers, got: '".concat(value, "'"));
7799
7822
  }
7800
7823
  }
7801
7824
  Object.defineProperty(StoredReference.prototype, "updateResolvedReference", {
@@ -8177,7 +8200,7 @@ function reference(subType, options) {
8177
8200
  if (devMode()) {
8178
8201
  if (arguments.length === 2 && typeof arguments[1] === "string") {
8179
8202
  // istanbul ignore next
8180
- throw fail("References with base path are no longer supported. Please remove the base path.");
8203
+ throw new MstError("References with base path are no longer supported. Please remove the base path.");
8181
8204
  }
8182
8205
  }
8183
8206
  var getSetOptions = options ? options : undefined;
@@ -8187,7 +8210,7 @@ function reference(subType, options) {
8187
8210
  if (getSetOptions && (getSetOptions.get || getSetOptions.set)) {
8188
8211
  if (devMode()) {
8189
8212
  if (!getSetOptions.get || !getSetOptions.set) {
8190
- throw fail("reference options must either contain both a 'get' and a 'set' method or none of them");
8213
+ throw new MstError("reference options must either contain both a 'get' and a 'set' method or none of them");
8191
8214
  }
8192
8215
  }
8193
8216
  return new CustomReferenceType(subType, {
@@ -8265,7 +8288,7 @@ var BaseIdentifierType = /** @class */ (function (_super) {
8265
8288
  writable: true,
8266
8289
  value: function (parent, subpath, environment, initialValue) {
8267
8290
  if (!parent || !(parent.type instanceof ModelType))
8268
- throw fail("Identifier types can only be instantiated as direct child of a model type");
8291
+ throw new MstError("Identifier types can only be instantiated as direct child of a model type");
8269
8292
  return createScalarNode(this, parent, subpath, environment, initialValue);
8270
8293
  }
8271
8294
  });
@@ -8276,7 +8299,7 @@ var BaseIdentifierType = /** @class */ (function (_super) {
8276
8299
  value: function (current, newValue, parent, subpath) {
8277
8300
  // we don't consider detaching here since identifier are scalar nodes, and scalar nodes cannot be detached
8278
8301
  if (current.storedValue !== newValue)
8279
- throw fail("Tried to change identifier from '".concat(current.storedValue, "' to '").concat(newValue, "'. Changing identifiers is not allowed."));
8302
+ throw new MstError("Tried to change identifier from '".concat(current.storedValue, "' to '").concat(newValue, "'. Changing identifiers is not allowed."));
8280
8303
  current.setParent(parent, subpath);
8281
8304
  return current;
8282
8305
  }