mobx-state-tree 5.4.0 → 5.4.1

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.
@@ -344,7 +344,7 @@ function protect(target) {
344
344
  assertIsStateTreeNode(target, 1);
345
345
  var node = getStateTreeNode(target);
346
346
  if (!node.isRoot)
347
- throw fail$1("`protect` can only be invoked on root nodes");
347
+ throw fail("`protect` can only be invoked on root nodes");
348
348
  node.isProtectionEnabled = true;
349
349
  }
350
350
  /**
@@ -376,7 +376,7 @@ function unprotect(target) {
376
376
  assertIsStateTreeNode(target, 1);
377
377
  var node = getStateTreeNode(target);
378
378
  if (!node.isRoot)
379
- throw fail$1("`unprotect` can only be invoked on root nodes");
379
+ throw fail("`unprotect` can only be invoked on root nodes");
380
380
  node.isProtectionEnabled = false;
381
381
  }
382
382
  /**
@@ -459,7 +459,7 @@ function getParent(target, depth) {
459
459
  return parent.storedValue;
460
460
  parent = parent.parent;
461
461
  }
462
- throw fail$1("Failed to find the parent of " + getStateTreeNode(target) + " at depth " + depth);
462
+ throw fail("Failed to find the parent of " + getStateTreeNode(target) + " at depth " + depth);
463
463
  }
464
464
  /**
465
465
  * 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
@@ -497,7 +497,7 @@ function getParentOfType(target, type) {
497
497
  return parent.storedValue;
498
498
  parent = parent.parent;
499
499
  }
500
- throw fail$1("Failed to find the parent of " + getStateTreeNode(target) + " of a given type");
500
+ throw fail("Failed to find the parent of " + getStateTreeNode(target) + " of a given type");
501
501
  }
502
502
  /**
503
503
  * Given an object in a model tree, returns the root object of that tree.
@@ -614,7 +614,7 @@ function tryReference(getter, checkIfAlive) {
614
614
  }
615
615
  }
616
616
  else {
617
- throw fail$1("The reference to be checked is not one of node, null or undefined");
617
+ throw fail("The reference to be checked is not one of node, null or undefined");
618
618
  }
619
619
  }
620
620
  catch (e) {
@@ -642,7 +642,7 @@ function isValidReference(getter, checkIfAlive) {
642
642
  return checkIfAlive ? isAlive(node) : true;
643
643
  }
644
644
  else {
645
- throw fail$1("The reference to be checked is not one of node, null or undefined");
645
+ throw fail("The reference to be checked is not one of node, null or undefined");
646
646
  }
647
647
  }
648
648
  catch (e) {
@@ -1297,7 +1297,7 @@ var ScalarNode = /** @class */ (function (_super) {
1297
1297
  get: function () {
1298
1298
  // future optimization: store root ref in the node and maintain it
1299
1299
  if (!this.parent)
1300
- throw fail$1("This scalar node is not part of a tree");
1300
+ throw fail("This scalar node is not part of a tree");
1301
1301
  return this.parent.root;
1302
1302
  },
1303
1303
  enumerable: false,
@@ -1316,15 +1316,15 @@ var ScalarNode = /** @class */ (function (_super) {
1316
1316
  if (devMode()) {
1317
1317
  if (!subpath) {
1318
1318
  // istanbul ignore next
1319
- throw fail$1("assertion failed: subpath expected");
1319
+ throw fail("assertion failed: subpath expected");
1320
1320
  }
1321
1321
  if (!newParent) {
1322
1322
  // istanbul ignore next
1323
- throw fail$1("assertion failed: parent expected");
1323
+ throw fail("assertion failed: parent expected");
1324
1324
  }
1325
1325
  if (parentChanged) {
1326
1326
  // istanbul ignore next
1327
- throw fail$1("assertion failed: scalar nodes cannot change their parent");
1327
+ throw fail("assertion failed: scalar nodes cannot change their parent");
1328
1328
  }
1329
1329
  }
1330
1330
  this.environment = undefined; // use parent's
@@ -1565,7 +1565,7 @@ var ObjectNode = /** @class */ (function (_super) {
1565
1565
  }
1566
1566
  }
1567
1567
  if (typeof id !== "string" && typeof id !== "number") {
1568
- throw fail$1("Instance identifier '" + _this.identifierAttribute + "' for type '" + _this.type.name + "' must be a string or a number");
1568
+ throw fail("Instance identifier '" + _this.identifierAttribute + "' for type '" + _this.type.name + "' must be a string or a number");
1569
1569
  }
1570
1570
  // normalize internal identifier to string
1571
1571
  _this.identifier = normalizeIdentifier(id);
@@ -1618,7 +1618,7 @@ var ObjectNode = /** @class */ (function (_super) {
1618
1618
  if (devMode()) {
1619
1619
  if (this.state !== NodeLifeCycle.INITIALIZING) {
1620
1620
  // istanbul ignore next
1621
- throw fail$1("assertion failed: the creation of the observable instance must be done on the initializing phase");
1621
+ throw fail("assertion failed: the creation of the observable instance must be done on the initializing phase");
1622
1622
  }
1623
1623
  }
1624
1624
  this._observableInstanceState = 1 /* CREATING */;
@@ -1741,20 +1741,20 @@ var ObjectNode = /** @class */ (function (_super) {
1741
1741
  if (devMode()) {
1742
1742
  if (!subpath) {
1743
1743
  // istanbul ignore next
1744
- throw fail$1("assertion failed: subpath expected");
1744
+ throw fail("assertion failed: subpath expected");
1745
1745
  }
1746
1746
  if (!newParent) {
1747
1747
  // istanbul ignore next
1748
- throw fail$1("assertion failed: new parent expected");
1748
+ throw fail("assertion failed: new parent expected");
1749
1749
  }
1750
1750
  if (this.parent && parentChanged) {
1751
- throw fail$1("A node cannot exists twice in the state tree. Failed to add " + this + " to path '" + newParent.path + "/" + subpath + "'.");
1751
+ throw fail("A node cannot exists twice in the state tree. Failed to add " + this + " to path '" + newParent.path + "/" + subpath + "'.");
1752
1752
  }
1753
1753
  if (!this.parent && newParent.root === this) {
1754
- throw fail$1("A state tree is not allowed to contain itself. Cannot assign " + this + " to path '" + newParent.path + "/" + subpath + "'");
1754
+ throw fail("A state tree is not allowed to contain itself. Cannot assign " + this + " to path '" + newParent.path + "/" + subpath + "'");
1755
1755
  }
1756
1756
  if (!this.parent && !!this.environment && this.environment !== newParent.root.environment) {
1757
- throw fail$1("A state tree cannot be made part of another state tree as long as their environments are different.");
1757
+ throw fail("A state tree cannot be made part of another state tree as long as their environments are different.");
1758
1758
  }
1759
1759
  }
1760
1760
  if (parentChanged) {
@@ -1860,7 +1860,7 @@ var ObjectNode = /** @class */ (function (_super) {
1860
1860
  var error = this._getAssertAliveError(context);
1861
1861
  switch (livelinessChecking) {
1862
1862
  case "error":
1863
- throw fail$1(error);
1863
+ throw fail(error);
1864
1864
  case "warn":
1865
1865
  warnError(error);
1866
1866
  }
@@ -1946,7 +1946,7 @@ var ObjectNode = /** @class */ (function (_super) {
1946
1946
  value: function (context) {
1947
1947
  this.assertAlive(context);
1948
1948
  if (!this.isRunningAction() && this.isProtected) {
1949
- throw fail$1("Cannot modify '" + this + "', the object is protected and can only be modified by using an action.");
1949
+ throw fail("Cannot modify '" + this + "', the object is protected and can only be modified by using an action.");
1950
1950
  }
1951
1951
  }
1952
1952
  });
@@ -2013,7 +2013,7 @@ var ObjectNode = /** @class */ (function (_super) {
2013
2013
  writable: true,
2014
2014
  value: function () {
2015
2015
  if (!this.isAlive)
2016
- throw fail$1("Error while detaching, node is not alive.");
2016
+ throw fail("Error while detaching, node is not alive.");
2017
2017
  this.clearParent();
2018
2018
  }
2019
2019
  });
@@ -2149,7 +2149,7 @@ var ObjectNode = /** @class */ (function (_super) {
2149
2149
  this._internalEventsRegister("dispose" /* Dispose */, disposer, true);
2150
2150
  return;
2151
2151
  }
2152
- throw fail$1("cannot add a disposer when it is already registered for execution");
2152
+ throw fail("cannot add a disposer when it is already registered for execution");
2153
2153
  }
2154
2154
  });
2155
2155
  Object.defineProperty(ObjectNode.prototype, "removeDisposer", {
@@ -2158,7 +2158,7 @@ var ObjectNode = /** @class */ (function (_super) {
2158
2158
  writable: true,
2159
2159
  value: function (disposer) {
2160
2160
  if (!this._internalEventsHas("dispose" /* Dispose */, disposer)) {
2161
- throw fail$1("cannot remove a disposer which was never registered for execution");
2161
+ throw fail("cannot remove a disposer which was never registered for execution");
2162
2162
  }
2163
2163
  this._internalEventsUnregister("dispose" /* Dispose */, disposer);
2164
2164
  }
@@ -2404,7 +2404,7 @@ var BaseType = /** @class */ (function () {
2404
2404
  writable: true,
2405
2405
  value: function (node, applyPostProcess) {
2406
2406
  // istanbul ignore next
2407
- throw fail$1("unimplemented method");
2407
+ throw fail("unimplemented method");
2408
2408
  }
2409
2409
  });
2410
2410
  Object.defineProperty(BaseType.prototype, "isAssignableFrom", {
@@ -2442,7 +2442,7 @@ var BaseType = /** @class */ (function () {
2442
2442
  Object.defineProperty(BaseType.prototype, "Type", {
2443
2443
  get: function () {
2444
2444
  // istanbul ignore next
2445
- throw fail$1("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`");
2445
+ 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`");
2446
2446
  },
2447
2447
  enumerable: false,
2448
2448
  configurable: true
@@ -2450,7 +2450,7 @@ var BaseType = /** @class */ (function () {
2450
2450
  Object.defineProperty(BaseType.prototype, "TypeWithoutSTN", {
2451
2451
  get: function () {
2452
2452
  // istanbul ignore next
2453
- throw fail$1("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`");
2453
+ 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`");
2454
2454
  },
2455
2455
  enumerable: false,
2456
2456
  configurable: true
@@ -2458,7 +2458,7 @@ var BaseType = /** @class */ (function () {
2458
2458
  Object.defineProperty(BaseType.prototype, "SnapshotType", {
2459
2459
  get: function () {
2460
2460
  // istanbul ignore next
2461
- throw fail$1("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`");
2461
+ 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`");
2462
2462
  },
2463
2463
  enumerable: false,
2464
2464
  configurable: true
@@ -2466,7 +2466,7 @@ var BaseType = /** @class */ (function () {
2466
2466
  Object.defineProperty(BaseType.prototype, "CreationType", {
2467
2467
  get: function () {
2468
2468
  // istanbul ignore next
2469
- throw fail$1("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`");
2469
+ 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`");
2470
2470
  },
2471
2471
  enumerable: false,
2472
2472
  configurable: true
@@ -2956,7 +2956,7 @@ function applyAction(target, actions) {
2956
2956
  function baseApplyAction(target, action) {
2957
2957
  var resolvedTarget = tryResolve(target, action.path || "");
2958
2958
  if (!resolvedTarget)
2959
- throw fail$1("Invalid action path: " + (action.path || ""));
2959
+ throw fail("Invalid action path: " + (action.path || ""));
2960
2960
  var node = getStateTreeNode(resolvedTarget);
2961
2961
  // Reserved functions
2962
2962
  if (action.name === "@APPLY_PATCHES") {
@@ -2966,7 +2966,7 @@ function baseApplyAction(target, action) {
2966
2966
  return applySnapshot.call(null, resolvedTarget, action.args[0]);
2967
2967
  }
2968
2968
  if (!(typeof resolvedTarget[action.name] === "function"))
2969
- throw fail$1("Action '" + action.name + "' does not exist in '" + node.path + "'");
2969
+ throw fail("Action '" + action.name + "' does not exist in '" + node.path + "'");
2970
2970
  return resolvedTarget[action.name].apply(resolvedTarget, action.args ? action.args.map(function (v) { return deserializeArgument(node, v); }) : []);
2971
2971
  }
2972
2972
  /**
@@ -3327,11 +3327,11 @@ function runMiddleWares(node, baseCall, originalFn) {
3327
3327
  if (devMode()) {
3328
3328
  if (!nextInvoked && !abortInvoked) {
3329
3329
  var node2 = getStateTreeNode(call.tree);
3330
- throw fail$1("Neither the next() nor the abort() callback within the middleware " + handler.name + " for the action: \"" + call.name + "\" on the node: " + node2.type.name + " was invoked.");
3330
+ throw fail("Neither the next() nor the abort() callback within the middleware " + handler.name + " for the action: \"" + call.name + "\" on the node: " + node2.type.name + " was invoked.");
3331
3331
  }
3332
3332
  else if (nextInvoked && abortInvoked) {
3333
3333
  var node2 = getStateTreeNode(call.tree);
3334
- throw fail$1("The next() and abort() callback within the middleware " + handler.name + " for the action: \"" + call.name + "\" on the node: " + node2.type.name + " were invoked.");
3334
+ throw fail("The next() and abort() callback within the middleware " + handler.name + " for the action: \"" + call.name + "\" on the node: " + node2.type.name + " were invoked.");
3335
3335
  }
3336
3336
  }
3337
3337
  return result;
@@ -3478,7 +3478,7 @@ function typecheckInternal(type, value) {
3478
3478
  function typecheck(type, value) {
3479
3479
  var errors = type.validate(value, [{ path: "", type: type }]);
3480
3480
  if (errors.length > 0) {
3481
- throw fail$1(validationErrorsToString(type, value, errors));
3481
+ throw fail(validationErrorsToString(type, value, errors));
3482
3482
  }
3483
3483
  }
3484
3484
  function validationErrorsToString(type, value, errors) {
@@ -3549,7 +3549,7 @@ var IdentifierCache = /** @class */ (function () {
3549
3549
  }
3550
3550
  var set = this.cache.get(identifier);
3551
3551
  if (set.indexOf(node) !== -1)
3552
- throw fail$1("Already registered");
3552
+ throw fail("Already registered");
3553
3553
  set.push(node);
3554
3554
  if (lastCacheUpdate) {
3555
3555
  this.updateLastCacheModificationPerId(identifier);
@@ -3648,7 +3648,7 @@ var IdentifierCache = /** @class */ (function () {
3648
3648
  case 1:
3649
3649
  return matches[0];
3650
3650
  default:
3651
- throw fail$1("Cannot resolve a reference to type '" + type.name + "' with id: '" + identifier + "' unambigously, there are multiple candidates: " + matches
3651
+ throw fail("Cannot resolve a reference to type '" + type.name + "' with id: '" + identifier + "' unambigously, there are multiple candidates: " + matches
3652
3652
  .map(function (n) { return n.path; })
3653
3653
  .join(", "));
3654
3654
  }
@@ -3666,7 +3666,7 @@ function createObjectNode(type, parent, subpath, environment, initialValue) {
3666
3666
  if (existingNode) {
3667
3667
  if (existingNode.parent) {
3668
3668
  // istanbul ignore next
3669
- throw fail$1("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 '" + (parent ? parent.path : "") + "/" + subpath + "', but it lives already at '" + existingNode.path + "'");
3669
+ 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 '" + (parent ? parent.path : "") + "/" + subpath + "', but it lives already at '" + existingNode.path + "'");
3670
3670
  }
3671
3671
  if (parent) {
3672
3672
  existingNode.setParent(parent, subpath);
@@ -3729,7 +3729,7 @@ function assertIsStateTreeNode(value, argNumber) {
3729
3729
  function getStateTreeNode(value) {
3730
3730
  if (!isStateTreeNode(value)) {
3731
3731
  // istanbul ignore next
3732
- throw fail$1("Value " + value + " is no MST Node");
3732
+ throw fail("Value " + value + " is no MST Node");
3733
3733
  }
3734
3734
  return value.$treenode;
3735
3735
  }
@@ -3755,7 +3755,7 @@ var doubleDot = function (_) { return ".."; };
3755
3755
  function getRelativePathBetweenNodes(base, target) {
3756
3756
  // PRE condition target is (a child of) base!
3757
3757
  if (base.root !== target.root) {
3758
- throw fail$1("Cannot calculate relative path: objects '" + base + "' and '" + target + "' are not part of the same object tree");
3758
+ throw fail("Cannot calculate relative path: objects '" + base + "' and '" + target + "' are not part of the same object tree");
3759
3759
  }
3760
3760
  var baseParts = splitJsonPath(base.path);
3761
3761
  var targetParts = splitJsonPath(target.path);
@@ -3812,7 +3812,7 @@ function resolveNodeByPathParts(base, pathParts, failIfResolveFails) {
3812
3812
  }
3813
3813
  }
3814
3814
  }
3815
- throw fail$1("Could not resolve '" + part + "' in path '" + (joinJsonPath(pathParts.slice(0, i)) || "/") + "' while resolving '" + joinJsonPath(pathParts) + "'");
3815
+ throw fail("Could not resolve '" + part + "' in path '" + (joinJsonPath(pathParts.slice(0, i)) || "/") + "' while resolving '" + joinJsonPath(pathParts) + "'");
3816
3816
  }
3817
3817
  }
3818
3818
  catch (e) {
@@ -3888,7 +3888,7 @@ Object.freeze(mobxShallow);
3888
3888
  * @internal
3889
3889
  * @hidden
3890
3890
  */
3891
- function fail$1(message) {
3891
+ function fail(message) {
3892
3892
  if (message === void 0) { message = "Illegal state"; }
3893
3893
  return new Error("[mobx-state-tree] " + message);
3894
3894
  }
@@ -4295,7 +4295,7 @@ function assertArg(value, fn, typeName, argNumber) {
4295
4295
  if (devMode()) {
4296
4296
  if (!fn(value)) {
4297
4297
  // istanbul ignore next
4298
- throw fail$1("expected " + typeName + " as argument " + asArray(argNumber).join(" or ") + ", got " + value + " instead");
4298
+ throw fail("expected " + typeName + " as argument " + asArray(argNumber).join(" or ") + ", got " + value + " instead");
4299
4299
  }
4300
4300
  }
4301
4301
  }
@@ -4440,11 +4440,11 @@ function createFlowSpawner(name, generator) {
4440
4440
  var runId = getNextActionId();
4441
4441
  var parentContext = getCurrentActionContext();
4442
4442
  if (!parentContext) {
4443
- throw fail$1("a mst flow must always have a parent context");
4443
+ throw fail("a mst flow must always have a parent context");
4444
4444
  }
4445
4445
  var parentActionContext = getParentActionContext(parentContext);
4446
4446
  if (!parentActionContext) {
4447
- throw fail$1("a mst flow must always have a parent action context");
4447
+ throw fail("a mst flow must always have a parent action context");
4448
4448
  }
4449
4449
  var contextBase = {
4450
4450
  name: name,
@@ -4515,7 +4515,7 @@ function createFlowSpawner(name, generator) {
4515
4515
  // TODO: support more type of values? See https://github.com/tj/co/blob/249bbdc72da24ae44076afd716349d2089b31c4c/index.js#L100
4516
4516
  if (!ret.value || typeof ret.value.then !== "function") {
4517
4517
  // istanbul ignore next
4518
- throw fail$1("Only promises can be yielded to `async`, got: " + ret);
4518
+ throw fail("Only promises can be yielded to `async`, got: " + ret);
4519
4519
  }
4520
4520
  return ret.value.then(onFulfilled, onRejected);
4521
4521
  }
@@ -4531,7 +4531,7 @@ function createFlowSpawner(name, generator) {
4531
4531
  */
4532
4532
  function splitPatch(patch) {
4533
4533
  if (!("oldValue" in patch))
4534
- throw fail$1("Patches without `oldValue` field cannot be inversed");
4534
+ throw fail("Patches without `oldValue` field cannot be inversed");
4535
4535
  return [stripPatch(patch), invertPatch(patch)];
4536
4536
  }
4537
4537
  /**
@@ -4632,7 +4632,7 @@ function splitJsonPath(path) {
4632
4632
  stringStartsWith(path, "./") ||
4633
4633
  stringStartsWith(path, "../");
4634
4634
  if (!valid) {
4635
- throw fail$1("a json path must be either rooted, empty or relative, but got '" + path + "'");
4635
+ throw fail("a json path must be either rooted, empty or relative, but got '" + path + "'");
4636
4636
  }
4637
4637
  // '/a/b/c' -> ["a", "b", "c"]
4638
4638
  // '../../b/c' -> ["..", "..", "b", "c"]
@@ -4980,28 +4980,28 @@ var MSTMap = /** @class */ (function (_super) {
4980
4980
  writable: true,
4981
4981
  value: function (value) {
4982
4982
  if (!value)
4983
- throw fail$1("Map.put cannot be used to set empty values");
4983
+ throw fail("Map.put cannot be used to set empty values");
4984
4984
  if (isStateTreeNode(value)) {
4985
4985
  var node = getStateTreeNode(value);
4986
4986
  if (devMode()) {
4987
4987
  if (!node.identifierAttribute) {
4988
- throw fail$1(needsIdentifierError);
4988
+ throw fail(needsIdentifierError);
4989
4989
  }
4990
4990
  }
4991
4991
  if (node.identifier === null) {
4992
- throw fail$1(needsIdentifierError);
4992
+ throw fail(needsIdentifierError);
4993
4993
  }
4994
4994
  this.set(node.identifier, value);
4995
4995
  return value;
4996
4996
  }
4997
4997
  else if (!isMutable(value)) {
4998
- throw fail$1("Map.put can only be used to store complex values");
4998
+ throw fail("Map.put can only be used to store complex values");
4999
4999
  }
5000
5000
  else {
5001
5001
  var mapNode = getStateTreeNode(this);
5002
5002
  var mapType = mapNode.type;
5003
5003
  if (mapType.identifierMode !== MapIdentifierMode.YES) {
5004
- throw fail$1(needsIdentifierError);
5004
+ throw fail(needsIdentifierError);
5005
5005
  }
5006
5006
  var idAttr = mapType.mapIdentifierAttribute;
5007
5007
  var id = value[idAttr];
@@ -5094,7 +5094,7 @@ var MapType = /** @class */ (function (_super) {
5094
5094
  if (!type.identifierAttribute)
5095
5095
  return current;
5096
5096
  if (current && current !== type.identifierAttribute) {
5097
- throw fail$1("The objects in a map should all have the same identifier attribute, expected '" + current + "', but child of type '" + type.name + "' declared attribute '" + type.identifierAttribute + "' as identifier");
5097
+ throw fail("The objects in a map should all have the same identifier attribute, expected '" + current + "', but child of type '" + type.name + "' declared attribute '" + type.identifierAttribute + "' as identifier");
5098
5098
  }
5099
5099
  return type.identifierAttribute;
5100
5100
  }, undefined);
@@ -5173,7 +5173,7 @@ var MapType = /** @class */ (function (_super) {
5173
5173
  value: function (node, key) {
5174
5174
  var childNode = node.storedValue.get("" + key);
5175
5175
  if (!childNode)
5176
- throw fail$1("Not a child " + key);
5176
+ throw fail("Not a child " + key);
5177
5177
  return childNode;
5178
5178
  }
5179
5179
  });
@@ -5218,7 +5218,7 @@ var MapType = /** @class */ (function (_super) {
5218
5218
  if (this.identifierMode === MapIdentifierMode.YES && node instanceof ObjectNode) {
5219
5219
  var identifier = node.identifier;
5220
5220
  if (identifier !== expected)
5221
- throw fail$1("A map of objects containing an identifier should always store the object under their own identifier. Trying to store key '" + identifier + "', but expected: '" + expected + "'");
5221
+ throw fail("A map of objects containing an identifier should always store the object under their own identifier. Trying to store key '" + identifier + "', but expected: '" + expected + "'");
5222
5222
  }
5223
5223
  }
5224
5224
  });
@@ -5516,7 +5516,7 @@ var ArrayType = /** @class */ (function (_super) {
5516
5516
  var index = Number(key);
5517
5517
  if (index < node.storedValue.length)
5518
5518
  return node.storedValue[index];
5519
- throw fail$1("Not a child: " + key);
5519
+ throw fail("Not a child: " + key);
5520
5520
  }
5521
5521
  });
5522
5522
  Object.defineProperty(ArrayType.prototype, "willChange", {
@@ -5741,7 +5741,7 @@ function reconcileArrayChildren(parent, childType, oldNodes, newValues, newPaths
5741
5741
  // check if already belongs to the same parent. if so, avoid pushing item in. only swapping can occur.
5742
5742
  if (isStateTreeNode(newValue) && getStateTreeNode(newValue).parent === parent) {
5743
5743
  // this node is owned by this parent, but not in the reconcilable set, so it must be double
5744
- throw fail$1("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 '" + parent.path + "/" + newPath + "', but it lives already at '" + getStateTreeNode(newValue).path + "'");
5744
+ 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 '" + parent.path + "/" + newPath + "', but it lives already at '" + getStateTreeNode(newValue).path + "'");
5745
5745
  }
5746
5746
  nothingChanged = false;
5747
5747
  var newNode = valueAsNode(childType, parent, newPath, newValue);
@@ -5857,7 +5857,7 @@ function toPropertiesObject(declaredProps) {
5857
5857
  var alreadySeenKeys = new Set();
5858
5858
  keysList.forEach(function (key) {
5859
5859
  if (alreadySeenKeys.has(key)) {
5860
- throw fail$1(key + " is declared twice in the model. Model should not contain the same keys");
5860
+ throw fail(key + " is declared twice in the model. Model should not contain the same keys");
5861
5861
  }
5862
5862
  alreadySeenKeys.add(key);
5863
5863
  });
@@ -5865,17 +5865,17 @@ function toPropertiesObject(declaredProps) {
5865
5865
  return keysList.reduce(function (props, key) {
5866
5866
  // warn if user intended a HOOK
5867
5867
  if (key in Hook) {
5868
- throw fail$1("Hook '" + key + "' was defined as property. Hooks should be defined as part of the actions");
5868
+ throw fail("Hook '" + key + "' was defined as property. Hooks should be defined as part of the actions");
5869
5869
  }
5870
5870
  // the user intended to use a view
5871
5871
  var descriptor = Object.getOwnPropertyDescriptor(declaredProps, key);
5872
5872
  if ("get" in descriptor) {
5873
- throw fail$1("Getters are not supported as properties. Please use views instead");
5873
+ throw fail("Getters are not supported as properties. Please use views instead");
5874
5874
  }
5875
5875
  // undefined and null are not valid
5876
5876
  var value = descriptor.value;
5877
5877
  if (value === null || value === undefined) {
5878
- throw fail$1("The default value of an attribute cannot be null or undefined as the type cannot be inferred. Did you mean `types.maybe(someType)`?");
5878
+ 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)`?");
5879
5879
  }
5880
5880
  // its a primitive, convert to its type
5881
5881
  else if (isPrimitive(value)) {
@@ -5892,14 +5892,14 @@ function toPropertiesObject(declaredProps) {
5892
5892
  else if (isType(value)) ;
5893
5893
  // its a function, maybe the user wanted a view?
5894
5894
  else if (devMode() && typeof value === "function") {
5895
- throw fail$1("Invalid type definition for property '" + key + "', it looks like you passed a function. Did you forget to invoke it, or did you intend to declare a view / action?");
5895
+ throw fail("Invalid type definition for property '" + key + "', it looks like you passed a function. Did you forget to invoke it, or did you intend to declare a view / action?");
5896
5896
  }
5897
5897
  // no other complex values
5898
5898
  else if (devMode() && typeof value === "object") {
5899
- throw fail$1("Invalid type definition for property '" + key + "', it looks like you passed an object. Try passing another model type or a types.frozen.");
5899
+ throw fail("Invalid type definition for property '" + key + "', it looks like you passed an object. Try passing another model type or a types.frozen.");
5900
5900
  }
5901
5901
  else {
5902
- throw fail$1("Invalid type definition for property '" + key + "', cannot infer a type from a value like '" + value + "' (" + typeof value + ")");
5902
+ throw fail("Invalid type definition for property '" + key + "', cannot infer a type from a value like '" + value + "' (" + typeof value + ")");
5903
5903
  }
5904
5904
  return props;
5905
5905
  }, declaredProps);
@@ -6012,7 +6012,7 @@ var ModelType = /** @class */ (function (_super) {
6012
6012
  this.forAllProps(function (propName, propType) {
6013
6013
  if (propType.flags & TypeFlags.Identifier) {
6014
6014
  if (identifierAttribute)
6015
- throw fail$1("Cannot define property '" + propName + "' as object identifier, property '" + identifierAttribute + "' is already defined as identifier property");
6015
+ throw fail("Cannot define property '" + propName + "' as object identifier, property '" + identifierAttribute + "' is already defined as identifier property");
6016
6016
  identifierAttribute = propName;
6017
6017
  }
6018
6018
  });
@@ -6053,15 +6053,15 @@ var ModelType = /** @class */ (function (_super) {
6053
6053
  value: function (self, actions) {
6054
6054
  // check if return is correct
6055
6055
  if (!isPlainObject(actions))
6056
- throw fail$1("actions initializer should return a plain object containing actions");
6056
+ throw fail("actions initializer should return a plain object containing actions");
6057
6057
  // bind actions to the object created
6058
6058
  Object.keys(actions).forEach(function (name) {
6059
6059
  // warn if preprocessor was given
6060
6060
  if (name === PRE_PROCESS_SNAPSHOT)
6061
- throw fail$1("Cannot define action '" + PRE_PROCESS_SNAPSHOT + "', it should be defined using 'type.preProcessSnapshot(fn)' instead");
6061
+ throw fail("Cannot define action '" + PRE_PROCESS_SNAPSHOT + "', it should be defined using 'type.preProcessSnapshot(fn)' instead");
6062
6062
  // warn if postprocessor was given
6063
6063
  if (name === POST_PROCESS_SNAPSHOT)
6064
- throw fail$1("Cannot define action '" + POST_PROCESS_SNAPSHOT + "', it should be defined using 'type.postProcessSnapshot(fn)' instead");
6064
+ throw fail("Cannot define action '" + POST_PROCESS_SNAPSHOT + "', it should be defined using 'type.postProcessSnapshot(fn)' instead");
6065
6065
  var action2 = actions[name];
6066
6066
  // apply hook composition
6067
6067
  var baseAction = self[name];
@@ -6091,7 +6091,7 @@ var ModelType = /** @class */ (function (_super) {
6091
6091
  value: function (fn) {
6092
6092
  var _this = this;
6093
6093
  if (typeof fn !== "function") {
6094
- throw fail$1("You passed an " + typeof fn + " to volatile state as an argument, when function is expected");
6094
+ throw fail("You passed an " + typeof fn + " to volatile state as an argument, when function is expected");
6095
6095
  }
6096
6096
  var stateInitializer = function (self) {
6097
6097
  _this.instantiateVolatileState(self, fn(self));
@@ -6107,7 +6107,7 @@ var ModelType = /** @class */ (function (_super) {
6107
6107
  value: function (self, state) {
6108
6108
  // check views return
6109
6109
  if (!isPlainObject(state))
6110
- throw fail$1("volatile state initializer should return a plain object containing state");
6110
+ throw fail("volatile state initializer should return a plain object containing state");
6111
6111
  set(self, state);
6112
6112
  }
6113
6113
  });
@@ -6120,7 +6120,7 @@ var ModelType = /** @class */ (function (_super) {
6120
6120
  var initializer = function (self) {
6121
6121
  var _a = fn(self), actions = _a.actions, views = _a.views, state = _a.state, rest = __rest(_a, ["actions", "views", "state"]);
6122
6122
  for (var key in rest)
6123
- throw fail$1("The `extend` function should return an object with a subset of the fields 'actions', 'views' and 'state'. Found invalid key '" + key + "'");
6123
+ throw fail("The `extend` function should return an object with a subset of the fields 'actions', 'views' and 'state'. Found invalid key '" + key + "'");
6124
6124
  if (state)
6125
6125
  _this.instantiateVolatileState(self, state);
6126
6126
  if (views)
@@ -6152,7 +6152,7 @@ var ModelType = /** @class */ (function (_super) {
6152
6152
  value: function (self, views) {
6153
6153
  // check views return
6154
6154
  if (!isPlainObject(views))
6155
- throw fail$1("views initializer should return a plain object containing views");
6155
+ throw fail("views initializer should return a plain object containing views");
6156
6156
  Object.getOwnPropertyNames(views).forEach(function (key) {
6157
6157
  var _a;
6158
6158
  // is this a computed property?
@@ -6165,7 +6165,7 @@ var ModelType = /** @class */ (function (_super) {
6165
6165
  (!devMode() ? addHiddenFinalProp : addHiddenWritableProp)(self, key, descriptor.value);
6166
6166
  }
6167
6167
  else {
6168
- throw fail$1("A view member should either be a function or getter based property");
6168
+ throw fail("A view member should either be a function or getter based property");
6169
6169
  }
6170
6170
  });
6171
6171
  }
@@ -6281,11 +6281,11 @@ var ModelType = /** @class */ (function (_super) {
6281
6281
  value: function (node, key) {
6282
6282
  var _a;
6283
6283
  if (!(key in this.properties))
6284
- throw fail$1("Not a value property: " + key);
6284
+ throw fail("Not a value property: " + key);
6285
6285
  var adm = _getAdministration(node.storedValue, key);
6286
6286
  var childNode = (_a = adm.raw) === null || _a === void 0 ? void 0 : _a.call(adm);
6287
6287
  if (!childNode)
6288
- throw fail$1("Node not available for property " + key);
6288
+ throw fail("Node not available for property " + key);
6289
6289
  return childNode;
6290
6290
  }
6291
6291
  });
@@ -6304,7 +6304,7 @@ var ModelType = /** @class */ (function (_super) {
6304
6304
  atom.reportObserved();
6305
6305
  }
6306
6306
  catch (e) {
6307
- throw fail$1(name + " property is declared twice");
6307
+ throw fail(name + " property is declared twice");
6308
6308
  }
6309
6309
  res[name] = _this.getChildNode(node, name).snapshot;
6310
6310
  });
@@ -6332,7 +6332,7 @@ var ModelType = /** @class */ (function (_super) {
6332
6332
  writable: true,
6333
6333
  value: function (node, subpath, patch) {
6334
6334
  if (!(patch.op === "replace" || patch.op === "add")) {
6335
- throw fail$1("object does not support operation " + patch.op);
6335
+ throw fail("object does not support operation " + patch.op);
6336
6336
  }
6337
6337
  node.storedValue[subpath] = patch.value;
6338
6338
  }
@@ -6444,7 +6444,7 @@ function model() {
6444
6444
  args[_i] = arguments[_i];
6445
6445
  }
6446
6446
  if (devMode() && typeof args[0] !== "string" && args[1]) {
6447
- throw fail$1("Model creation failed. First argument must be a string when two arguments are provided");
6447
+ throw fail("Model creation failed. First argument must be a string when two arguments are provided");
6448
6448
  }
6449
6449
  var name = typeof args[0] === "string" ? args.shift() : "AnonymousModel";
6450
6450
  var properties = args.shift() || {};
@@ -6691,7 +6691,7 @@ function getPrimitiveFactoryFromValue(value) {
6691
6691
  if (value instanceof Date)
6692
6692
  return DatePrimitive;
6693
6693
  }
6694
- throw fail$1("Cannot determine primitive type from value " + value);
6694
+ throw fail("Cannot determine primitive type from value " + value);
6695
6695
  }
6696
6696
  /**
6697
6697
  * Returns if a given value represents a primitive type.
@@ -7011,7 +7011,7 @@ var Union = /** @class */ (function (_super) {
7011
7011
  value: function (parent, subpath, environment, initialValue) {
7012
7012
  var type = this.determineType(initialValue, undefined);
7013
7013
  if (!type)
7014
- throw fail$1("No matching type for union " + this.describe()); // can happen in prod builds
7014
+ throw fail("No matching type for union " + this.describe()); // can happen in prod builds
7015
7015
  return type.instantiate(parent, subpath, environment, initialValue);
7016
7016
  }
7017
7017
  });
@@ -7022,7 +7022,7 @@ var Union = /** @class */ (function (_super) {
7022
7022
  value: function (current, newValue, parent, subpath) {
7023
7023
  var type = this.determineType(newValue, current.getReconciliationType());
7024
7024
  if (!type)
7025
- throw fail$1("No matching type for union " + this.describe()); // can happen in prod builds
7025
+ throw fail("No matching type for union " + this.describe()); // can happen in prod builds
7026
7026
  return type.reconcile(current, newValue, parent, subpath);
7027
7027
  }
7028
7028
  });
@@ -7237,7 +7237,7 @@ var OptionalValue = /** @class */ (function (_super) {
7237
7237
  function checkOptionalPreconditions(type, defaultValueOrFunction) {
7238
7238
  // make sure we never pass direct instances
7239
7239
  if (typeof defaultValueOrFunction !== "function" && isStateTreeNode(defaultValueOrFunction)) {
7240
- throw fail$1("default value cannot be an instance, pass a snapshot or a function that creates an instance/snapshot instead");
7240
+ throw fail("default value cannot be an instance, pass a snapshot or a function that creates an instance/snapshot instead");
7241
7241
  }
7242
7242
  assertIsType(type, 1);
7243
7243
  if (devMode()) {
@@ -7376,10 +7376,10 @@ var Late = /** @class */ (function (_super) {
7376
7376
  throw e;
7377
7377
  }
7378
7378
  if (mustSucceed && t === undefined)
7379
- throw fail$1("Late type seems to be used too early, the definition (still) returns undefined");
7379
+ throw fail("Late type seems to be used too early, the definition (still) returns undefined");
7380
7380
  if (t) {
7381
7381
  if (devMode() && !isType(t))
7382
- throw fail$1("Failed to determine subtype, make sure types.late returns a type definition.");
7382
+ throw fail("Failed to determine subtype, make sure types.late returns a type definition.");
7383
7383
  this._subType = t;
7384
7384
  }
7385
7385
  }
@@ -7466,7 +7466,7 @@ function late(nameOrType, maybeType) {
7466
7466
  // checks that the type is actually a late type
7467
7467
  if (devMode()) {
7468
7468
  if (!(typeof type === "function" && type.length === 0))
7469
- throw fail$1("Invalid late type, expected a function with zero arguments that returns a type, got: " +
7469
+ throw fail("Invalid late type, expected a function with zero arguments that returns a type, got: " +
7470
7470
  type);
7471
7471
  }
7472
7472
  return new Late(name, type);
@@ -7749,15 +7749,15 @@ var StoredReference = /** @class */ (function () {
7749
7749
  else if (isStateTreeNode(value)) {
7750
7750
  var targetNode = getStateTreeNode(value);
7751
7751
  if (!targetNode.identifierAttribute)
7752
- throw fail$1("Can only store references with a defined identifier attribute.");
7752
+ throw fail("Can only store references with a defined identifier attribute.");
7753
7753
  var id = targetNode.unnormalizedIdentifier;
7754
7754
  if (id === null || id === undefined) {
7755
- throw fail$1("Can only store references to tree nodes with a defined identifier.");
7755
+ throw fail("Can only store references to tree nodes with a defined identifier.");
7756
7756
  }
7757
7757
  this.identifier = id;
7758
7758
  }
7759
7759
  else {
7760
- throw fail$1("Can only store references to tree nodes or identifiers, got: '" + value + "'");
7760
+ throw fail("Can only store references to tree nodes or identifiers, got: '" + value + "'");
7761
7761
  }
7762
7762
  }
7763
7763
  Object.defineProperty(StoredReference.prototype, "updateResolvedReference", {
@@ -8139,7 +8139,7 @@ function reference(subType, options) {
8139
8139
  if (devMode()) {
8140
8140
  if (arguments.length === 2 && typeof arguments[1] === "string") {
8141
8141
  // istanbul ignore next
8142
- throw fail$1("References with base path are no longer supported. Please remove the base path.");
8142
+ throw fail("References with base path are no longer supported. Please remove the base path.");
8143
8143
  }
8144
8144
  }
8145
8145
  var getSetOptions = options ? options : undefined;
@@ -8149,7 +8149,7 @@ function reference(subType, options) {
8149
8149
  if (getSetOptions && (getSetOptions.get || getSetOptions.set)) {
8150
8150
  if (devMode()) {
8151
8151
  if (!getSetOptions.get || !getSetOptions.set) {
8152
- throw fail$1("reference options must either contain both a 'get' and a 'set' method or none of them");
8152
+ throw fail("reference options must either contain both a 'get' and a 'set' method or none of them");
8153
8153
  }
8154
8154
  }
8155
8155
  return new CustomReferenceType(subType, {
@@ -8227,7 +8227,7 @@ var BaseIdentifierType = /** @class */ (function (_super) {
8227
8227
  writable: true,
8228
8228
  value: function (parent, subpath, environment, initialValue) {
8229
8229
  if (!parent || !(parent.type instanceof ModelType))
8230
- throw fail$1("Identifier types can only be instantiated as direct child of a model type");
8230
+ throw fail("Identifier types can only be instantiated as direct child of a model type");
8231
8231
  return createScalarNode(this, parent, subpath, environment, initialValue);
8232
8232
  }
8233
8233
  });
@@ -8238,7 +8238,7 @@ var BaseIdentifierType = /** @class */ (function (_super) {
8238
8238
  value: function (current, newValue, parent, subpath) {
8239
8239
  // we don't consider detaching here since identifier are scalar nodes, and scalar nodes cannot be detached
8240
8240
  if (current.storedValue !== newValue)
8241
- throw fail$1("Tried to change identifier from '" + current.storedValue + "' to '" + newValue + "'. Changing identifiers is not allowed.");
8241
+ throw fail("Tried to change identifier from '" + current.storedValue + "' to '" + newValue + "'. Changing identifiers is not allowed.");
8242
8242
  current.setParent(parent, subpath);
8243
8243
  return current;
8244
8244
  }