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.
@@ -348,7 +348,7 @@
348
348
  assertIsStateTreeNode(target, 1);
349
349
  var node = getStateTreeNode(target);
350
350
  if (!node.isRoot)
351
- throw fail$1("`protect` can only be invoked on root nodes");
351
+ throw fail("`protect` can only be invoked on root nodes");
352
352
  node.isProtectionEnabled = true;
353
353
  }
354
354
  /**
@@ -380,7 +380,7 @@
380
380
  assertIsStateTreeNode(target, 1);
381
381
  var node = getStateTreeNode(target);
382
382
  if (!node.isRoot)
383
- throw fail$1("`unprotect` can only be invoked on root nodes");
383
+ throw fail("`unprotect` can only be invoked on root nodes");
384
384
  node.isProtectionEnabled = false;
385
385
  }
386
386
  /**
@@ -463,7 +463,7 @@
463
463
  return parent.storedValue;
464
464
  parent = parent.parent;
465
465
  }
466
- throw fail$1("Failed to find the parent of " + getStateTreeNode(target) + " at depth " + depth);
466
+ throw fail("Failed to find the parent of " + getStateTreeNode(target) + " at depth " + depth);
467
467
  }
468
468
  /**
469
469
  * 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
@@ -501,7 +501,7 @@
501
501
  return parent.storedValue;
502
502
  parent = parent.parent;
503
503
  }
504
- throw fail$1("Failed to find the parent of " + getStateTreeNode(target) + " of a given type");
504
+ throw fail("Failed to find the parent of " + getStateTreeNode(target) + " of a given type");
505
505
  }
506
506
  /**
507
507
  * Given an object in a model tree, returns the root object of that tree.
@@ -618,7 +618,7 @@
618
618
  }
619
619
  }
620
620
  else {
621
- throw fail$1("The reference to be checked is not one of node, null or undefined");
621
+ throw fail("The reference to be checked is not one of node, null or undefined");
622
622
  }
623
623
  }
624
624
  catch (e) {
@@ -646,7 +646,7 @@
646
646
  return checkIfAlive ? isAlive(node) : true;
647
647
  }
648
648
  else {
649
- throw fail$1("The reference to be checked is not one of node, null or undefined");
649
+ throw fail("The reference to be checked is not one of node, null or undefined");
650
650
  }
651
651
  }
652
652
  catch (e) {
@@ -1301,7 +1301,7 @@
1301
1301
  get: function () {
1302
1302
  // future optimization: store root ref in the node and maintain it
1303
1303
  if (!this.parent)
1304
- throw fail$1("This scalar node is not part of a tree");
1304
+ throw fail("This scalar node is not part of a tree");
1305
1305
  return this.parent.root;
1306
1306
  },
1307
1307
  enumerable: false,
@@ -1320,15 +1320,15 @@
1320
1320
  {
1321
1321
  if (!subpath) {
1322
1322
  // istanbul ignore next
1323
- throw fail$1("assertion failed: subpath expected");
1323
+ throw fail("assertion failed: subpath expected");
1324
1324
  }
1325
1325
  if (!newParent) {
1326
1326
  // istanbul ignore next
1327
- throw fail$1("assertion failed: parent expected");
1327
+ throw fail("assertion failed: parent expected");
1328
1328
  }
1329
1329
  if (parentChanged) {
1330
1330
  // istanbul ignore next
1331
- throw fail$1("assertion failed: scalar nodes cannot change their parent");
1331
+ throw fail("assertion failed: scalar nodes cannot change their parent");
1332
1332
  }
1333
1333
  }
1334
1334
  this.environment = undefined; // use parent's
@@ -1569,7 +1569,7 @@
1569
1569
  }
1570
1570
  }
1571
1571
  if (typeof id !== "string" && typeof id !== "number") {
1572
- throw fail$1("Instance identifier '" + _this.identifierAttribute + "' for type '" + _this.type.name + "' must be a string or a number");
1572
+ throw fail("Instance identifier '" + _this.identifierAttribute + "' for type '" + _this.type.name + "' must be a string or a number");
1573
1573
  }
1574
1574
  // normalize internal identifier to string
1575
1575
  _this.identifier = normalizeIdentifier(id);
@@ -1622,7 +1622,7 @@
1622
1622
  {
1623
1623
  if (this.state !== NodeLifeCycle.INITIALIZING) {
1624
1624
  // istanbul ignore next
1625
- throw fail$1("assertion failed: the creation of the observable instance must be done on the initializing phase");
1625
+ throw fail("assertion failed: the creation of the observable instance must be done on the initializing phase");
1626
1626
  }
1627
1627
  }
1628
1628
  this._observableInstanceState = 1 /* CREATING */;
@@ -1745,20 +1745,20 @@
1745
1745
  {
1746
1746
  if (!subpath) {
1747
1747
  // istanbul ignore next
1748
- throw fail$1("assertion failed: subpath expected");
1748
+ throw fail("assertion failed: subpath expected");
1749
1749
  }
1750
1750
  if (!newParent) {
1751
1751
  // istanbul ignore next
1752
- throw fail$1("assertion failed: new parent expected");
1752
+ throw fail("assertion failed: new parent expected");
1753
1753
  }
1754
1754
  if (this.parent && parentChanged) {
1755
- throw fail$1("A node cannot exists twice in the state tree. Failed to add " + this + " to path '" + newParent.path + "/" + subpath + "'.");
1755
+ throw fail("A node cannot exists twice in the state tree. Failed to add " + this + " to path '" + newParent.path + "/" + subpath + "'.");
1756
1756
  }
1757
1757
  if (!this.parent && newParent.root === this) {
1758
- throw fail$1("A state tree is not allowed to contain itself. Cannot assign " + this + " to path '" + newParent.path + "/" + subpath + "'");
1758
+ throw fail("A state tree is not allowed to contain itself. Cannot assign " + this + " to path '" + newParent.path + "/" + subpath + "'");
1759
1759
  }
1760
1760
  if (!this.parent && !!this.environment && this.environment !== newParent.root.environment) {
1761
- throw fail$1("A state tree cannot be made part of another state tree as long as their environments are different.");
1761
+ throw fail("A state tree cannot be made part of another state tree as long as their environments are different.");
1762
1762
  }
1763
1763
  }
1764
1764
  if (parentChanged) {
@@ -1864,7 +1864,7 @@
1864
1864
  var error = this._getAssertAliveError(context);
1865
1865
  switch (livelinessChecking) {
1866
1866
  case "error":
1867
- throw fail$1(error);
1867
+ throw fail(error);
1868
1868
  case "warn":
1869
1869
  warnError(error);
1870
1870
  }
@@ -1950,7 +1950,7 @@
1950
1950
  value: function (context) {
1951
1951
  this.assertAlive(context);
1952
1952
  if (!this.isRunningAction() && this.isProtected) {
1953
- throw fail$1("Cannot modify '" + this + "', the object is protected and can only be modified by using an action.");
1953
+ throw fail("Cannot modify '" + this + "', the object is protected and can only be modified by using an action.");
1954
1954
  }
1955
1955
  }
1956
1956
  });
@@ -2017,7 +2017,7 @@
2017
2017
  writable: true,
2018
2018
  value: function () {
2019
2019
  if (!this.isAlive)
2020
- throw fail$1("Error while detaching, node is not alive.");
2020
+ throw fail("Error while detaching, node is not alive.");
2021
2021
  this.clearParent();
2022
2022
  }
2023
2023
  });
@@ -2153,7 +2153,7 @@
2153
2153
  this._internalEventsRegister("dispose" /* Dispose */, disposer, true);
2154
2154
  return;
2155
2155
  }
2156
- throw fail$1("cannot add a disposer when it is already registered for execution");
2156
+ throw fail("cannot add a disposer when it is already registered for execution");
2157
2157
  }
2158
2158
  });
2159
2159
  Object.defineProperty(ObjectNode.prototype, "removeDisposer", {
@@ -2162,7 +2162,7 @@
2162
2162
  writable: true,
2163
2163
  value: function (disposer) {
2164
2164
  if (!this._internalEventsHas("dispose" /* Dispose */, disposer)) {
2165
- throw fail$1("cannot remove a disposer which was never registered for execution");
2165
+ throw fail("cannot remove a disposer which was never registered for execution");
2166
2166
  }
2167
2167
  this._internalEventsUnregister("dispose" /* Dispose */, disposer);
2168
2168
  }
@@ -2408,7 +2408,7 @@
2408
2408
  writable: true,
2409
2409
  value: function (node, applyPostProcess) {
2410
2410
  // istanbul ignore next
2411
- throw fail$1("unimplemented method");
2411
+ throw fail("unimplemented method");
2412
2412
  }
2413
2413
  });
2414
2414
  Object.defineProperty(BaseType.prototype, "isAssignableFrom", {
@@ -2446,7 +2446,7 @@
2446
2446
  Object.defineProperty(BaseType.prototype, "Type", {
2447
2447
  get: function () {
2448
2448
  // istanbul ignore next
2449
- 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`");
2449
+ 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`");
2450
2450
  },
2451
2451
  enumerable: false,
2452
2452
  configurable: true
@@ -2454,7 +2454,7 @@
2454
2454
  Object.defineProperty(BaseType.prototype, "TypeWithoutSTN", {
2455
2455
  get: function () {
2456
2456
  // istanbul ignore next
2457
- 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`");
2457
+ 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`");
2458
2458
  },
2459
2459
  enumerable: false,
2460
2460
  configurable: true
@@ -2462,7 +2462,7 @@
2462
2462
  Object.defineProperty(BaseType.prototype, "SnapshotType", {
2463
2463
  get: function () {
2464
2464
  // istanbul ignore next
2465
- 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`");
2465
+ 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`");
2466
2466
  },
2467
2467
  enumerable: false,
2468
2468
  configurable: true
@@ -2470,7 +2470,7 @@
2470
2470
  Object.defineProperty(BaseType.prototype, "CreationType", {
2471
2471
  get: function () {
2472
2472
  // istanbul ignore next
2473
- 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`");
2473
+ 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`");
2474
2474
  },
2475
2475
  enumerable: false,
2476
2476
  configurable: true
@@ -2960,7 +2960,7 @@
2960
2960
  function baseApplyAction(target, action) {
2961
2961
  var resolvedTarget = tryResolve(target, action.path || "");
2962
2962
  if (!resolvedTarget)
2963
- throw fail$1("Invalid action path: " + (action.path || ""));
2963
+ throw fail("Invalid action path: " + (action.path || ""));
2964
2964
  var node = getStateTreeNode(resolvedTarget);
2965
2965
  // Reserved functions
2966
2966
  if (action.name === "@APPLY_PATCHES") {
@@ -2970,7 +2970,7 @@
2970
2970
  return applySnapshot.call(null, resolvedTarget, action.args[0]);
2971
2971
  }
2972
2972
  if (!(typeof resolvedTarget[action.name] === "function"))
2973
- throw fail$1("Action '" + action.name + "' does not exist in '" + node.path + "'");
2973
+ throw fail("Action '" + action.name + "' does not exist in '" + node.path + "'");
2974
2974
  return resolvedTarget[action.name].apply(resolvedTarget, action.args ? action.args.map(function (v) { return deserializeArgument(node, v); }) : []);
2975
2975
  }
2976
2976
  /**
@@ -3331,11 +3331,11 @@
3331
3331
  {
3332
3332
  if (!nextInvoked && !abortInvoked) {
3333
3333
  var node2 = getStateTreeNode(call.tree);
3334
- 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.");
3334
+ 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.");
3335
3335
  }
3336
3336
  else if (nextInvoked && abortInvoked) {
3337
3337
  var node2 = getStateTreeNode(call.tree);
3338
- 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.");
3338
+ 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.");
3339
3339
  }
3340
3340
  }
3341
3341
  return result;
@@ -3482,7 +3482,7 @@
3482
3482
  function typecheck(type, value) {
3483
3483
  var errors = type.validate(value, [{ path: "", type: type }]);
3484
3484
  if (errors.length > 0) {
3485
- throw fail$1(validationErrorsToString(type, value, errors));
3485
+ throw fail(validationErrorsToString(type, value, errors));
3486
3486
  }
3487
3487
  }
3488
3488
  function validationErrorsToString(type, value, errors) {
@@ -3553,7 +3553,7 @@
3553
3553
  }
3554
3554
  var set = this.cache.get(identifier);
3555
3555
  if (set.indexOf(node) !== -1)
3556
- throw fail$1("Already registered");
3556
+ throw fail("Already registered");
3557
3557
  set.push(node);
3558
3558
  if (lastCacheUpdate) {
3559
3559
  this.updateLastCacheModificationPerId(identifier);
@@ -3652,7 +3652,7 @@
3652
3652
  case 1:
3653
3653
  return matches[0];
3654
3654
  default:
3655
- throw fail$1("Cannot resolve a reference to type '" + type.name + "' with id: '" + identifier + "' unambigously, there are multiple candidates: " + matches
3655
+ throw fail("Cannot resolve a reference to type '" + type.name + "' with id: '" + identifier + "' unambigously, there are multiple candidates: " + matches
3656
3656
  .map(function (n) { return n.path; })
3657
3657
  .join(", "));
3658
3658
  }
@@ -3670,7 +3670,7 @@
3670
3670
  if (existingNode) {
3671
3671
  if (existingNode.parent) {
3672
3672
  // istanbul ignore next
3673
- 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 + "'");
3673
+ 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 + "'");
3674
3674
  }
3675
3675
  if (parent) {
3676
3676
  existingNode.setParent(parent, subpath);
@@ -3733,7 +3733,7 @@
3733
3733
  function getStateTreeNode(value) {
3734
3734
  if (!isStateTreeNode(value)) {
3735
3735
  // istanbul ignore next
3736
- throw fail$1("Value " + value + " is no MST Node");
3736
+ throw fail("Value " + value + " is no MST Node");
3737
3737
  }
3738
3738
  return value.$treenode;
3739
3739
  }
@@ -3759,7 +3759,7 @@
3759
3759
  function getRelativePathBetweenNodes(base, target) {
3760
3760
  // PRE condition target is (a child of) base!
3761
3761
  if (base.root !== target.root) {
3762
- throw fail$1("Cannot calculate relative path: objects '" + base + "' and '" + target + "' are not part of the same object tree");
3762
+ throw fail("Cannot calculate relative path: objects '" + base + "' and '" + target + "' are not part of the same object tree");
3763
3763
  }
3764
3764
  var baseParts = splitJsonPath(base.path);
3765
3765
  var targetParts = splitJsonPath(target.path);
@@ -3816,7 +3816,7 @@
3816
3816
  }
3817
3817
  }
3818
3818
  }
3819
- throw fail$1("Could not resolve '" + part + "' in path '" + (joinJsonPath(pathParts.slice(0, i)) || "/") + "' while resolving '" + joinJsonPath(pathParts) + "'");
3819
+ throw fail("Could not resolve '" + part + "' in path '" + (joinJsonPath(pathParts.slice(0, i)) || "/") + "' while resolving '" + joinJsonPath(pathParts) + "'");
3820
3820
  }
3821
3821
  }
3822
3822
  catch (e) {
@@ -3892,7 +3892,7 @@
3892
3892
  * @internal
3893
3893
  * @hidden
3894
3894
  */
3895
- function fail$1(message) {
3895
+ function fail(message) {
3896
3896
  if (message === void 0) { message = "Illegal state"; }
3897
3897
  return new Error("[mobx-state-tree] " + message);
3898
3898
  }
@@ -4277,7 +4277,7 @@
4277
4277
  {
4278
4278
  if (!fn(value)) {
4279
4279
  // istanbul ignore next
4280
- throw fail$1("expected " + typeName + " as argument " + asArray(argNumber).join(" or ") + ", got " + value + " instead");
4280
+ throw fail("expected " + typeName + " as argument " + asArray(argNumber).join(" or ") + ", got " + value + " instead");
4281
4281
  }
4282
4282
  }
4283
4283
  }
@@ -4422,11 +4422,11 @@
4422
4422
  var runId = getNextActionId();
4423
4423
  var parentContext = getCurrentActionContext();
4424
4424
  if (!parentContext) {
4425
- throw fail$1("a mst flow must always have a parent context");
4425
+ throw fail("a mst flow must always have a parent context");
4426
4426
  }
4427
4427
  var parentActionContext = getParentActionContext(parentContext);
4428
4428
  if (!parentActionContext) {
4429
- throw fail$1("a mst flow must always have a parent action context");
4429
+ throw fail("a mst flow must always have a parent action context");
4430
4430
  }
4431
4431
  var contextBase = {
4432
4432
  name: name,
@@ -4497,7 +4497,7 @@
4497
4497
  // TODO: support more type of values? See https://github.com/tj/co/blob/249bbdc72da24ae44076afd716349d2089b31c4c/index.js#L100
4498
4498
  if (!ret.value || typeof ret.value.then !== "function") {
4499
4499
  // istanbul ignore next
4500
- throw fail$1("Only promises can be yielded to `async`, got: " + ret);
4500
+ throw fail("Only promises can be yielded to `async`, got: " + ret);
4501
4501
  }
4502
4502
  return ret.value.then(onFulfilled, onRejected);
4503
4503
  }
@@ -4513,7 +4513,7 @@
4513
4513
  */
4514
4514
  function splitPatch(patch) {
4515
4515
  if (!("oldValue" in patch))
4516
- throw fail$1("Patches without `oldValue` field cannot be inversed");
4516
+ throw fail("Patches without `oldValue` field cannot be inversed");
4517
4517
  return [stripPatch(patch), invertPatch(patch)];
4518
4518
  }
4519
4519
  /**
@@ -4614,7 +4614,7 @@
4614
4614
  stringStartsWith(path, "./") ||
4615
4615
  stringStartsWith(path, "../");
4616
4616
  if (!valid) {
4617
- throw fail$1("a json path must be either rooted, empty or relative, but got '" + path + "'");
4617
+ throw fail("a json path must be either rooted, empty or relative, but got '" + path + "'");
4618
4618
  }
4619
4619
  // '/a/b/c' -> ["a", "b", "c"]
4620
4620
  // '../../b/c' -> ["..", "..", "b", "c"]
@@ -4962,28 +4962,28 @@
4962
4962
  writable: true,
4963
4963
  value: function (value) {
4964
4964
  if (!value)
4965
- throw fail$1("Map.put cannot be used to set empty values");
4965
+ throw fail("Map.put cannot be used to set empty values");
4966
4966
  if (isStateTreeNode(value)) {
4967
4967
  var node = getStateTreeNode(value);
4968
4968
  {
4969
4969
  if (!node.identifierAttribute) {
4970
- throw fail$1(needsIdentifierError);
4970
+ throw fail(needsIdentifierError);
4971
4971
  }
4972
4972
  }
4973
4973
  if (node.identifier === null) {
4974
- throw fail$1(needsIdentifierError);
4974
+ throw fail(needsIdentifierError);
4975
4975
  }
4976
4976
  this.set(node.identifier, value);
4977
4977
  return value;
4978
4978
  }
4979
4979
  else if (!isMutable(value)) {
4980
- throw fail$1("Map.put can only be used to store complex values");
4980
+ throw fail("Map.put can only be used to store complex values");
4981
4981
  }
4982
4982
  else {
4983
4983
  var mapNode = getStateTreeNode(this);
4984
4984
  var mapType = mapNode.type;
4985
4985
  if (mapType.identifierMode !== MapIdentifierMode.YES) {
4986
- throw fail$1(needsIdentifierError);
4986
+ throw fail(needsIdentifierError);
4987
4987
  }
4988
4988
  var idAttr = mapType.mapIdentifierAttribute;
4989
4989
  var id = value[idAttr];
@@ -5076,7 +5076,7 @@
5076
5076
  if (!type.identifierAttribute)
5077
5077
  return current;
5078
5078
  if (current && current !== type.identifierAttribute) {
5079
- 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");
5079
+ 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");
5080
5080
  }
5081
5081
  return type.identifierAttribute;
5082
5082
  }, undefined);
@@ -5155,7 +5155,7 @@
5155
5155
  value: function (node, key) {
5156
5156
  var childNode = node.storedValue.get("" + key);
5157
5157
  if (!childNode)
5158
- throw fail$1("Not a child " + key);
5158
+ throw fail("Not a child " + key);
5159
5159
  return childNode;
5160
5160
  }
5161
5161
  });
@@ -5200,7 +5200,7 @@
5200
5200
  if (this.identifierMode === MapIdentifierMode.YES && node instanceof ObjectNode) {
5201
5201
  var identifier = node.identifier;
5202
5202
  if (identifier !== expected)
5203
- 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 + "'");
5203
+ 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 + "'");
5204
5204
  }
5205
5205
  }
5206
5206
  });
@@ -5498,7 +5498,7 @@
5498
5498
  var index = Number(key);
5499
5499
  if (index < node.storedValue.length)
5500
5500
  return node.storedValue[index];
5501
- throw fail$1("Not a child: " + key);
5501
+ throw fail("Not a child: " + key);
5502
5502
  }
5503
5503
  });
5504
5504
  Object.defineProperty(ArrayType.prototype, "willChange", {
@@ -5723,7 +5723,7 @@
5723
5723
  // check if already belongs to the same parent. if so, avoid pushing item in. only swapping can occur.
5724
5724
  if (isStateTreeNode(newValue) && getStateTreeNode(newValue).parent === parent) {
5725
5725
  // this node is owned by this parent, but not in the reconcilable set, so it must be double
5726
- 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 + "'");
5726
+ 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 + "'");
5727
5727
  }
5728
5728
  nothingChanged = false;
5729
5729
  var newNode = valueAsNode(childType, parent, newPath, newValue);
@@ -5839,7 +5839,7 @@
5839
5839
  var alreadySeenKeys = new Set();
5840
5840
  keysList.forEach(function (key) {
5841
5841
  if (alreadySeenKeys.has(key)) {
5842
- throw fail$1(key + " is declared twice in the model. Model should not contain the same keys");
5842
+ throw fail(key + " is declared twice in the model. Model should not contain the same keys");
5843
5843
  }
5844
5844
  alreadySeenKeys.add(key);
5845
5845
  });
@@ -5847,17 +5847,17 @@
5847
5847
  return keysList.reduce(function (props, key) {
5848
5848
  // warn if user intended a HOOK
5849
5849
  if (key in Hook) {
5850
- throw fail$1("Hook '" + key + "' was defined as property. Hooks should be defined as part of the actions");
5850
+ throw fail("Hook '" + key + "' was defined as property. Hooks should be defined as part of the actions");
5851
5851
  }
5852
5852
  // the user intended to use a view
5853
5853
  var descriptor = Object.getOwnPropertyDescriptor(declaredProps, key);
5854
5854
  if ("get" in descriptor) {
5855
- throw fail$1("Getters are not supported as properties. Please use views instead");
5855
+ throw fail("Getters are not supported as properties. Please use views instead");
5856
5856
  }
5857
5857
  // undefined and null are not valid
5858
5858
  var value = descriptor.value;
5859
5859
  if (value === null || value === undefined) {
5860
- 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)`?");
5860
+ 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)`?");
5861
5861
  }
5862
5862
  // its a primitive, convert to its type
5863
5863
  else if (isPrimitive(value)) {
@@ -5874,14 +5874,14 @@
5874
5874
  else if (isType(value)) ;
5875
5875
  // its a function, maybe the user wanted a view?
5876
5876
  else if (typeof value === "function") {
5877
- 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?");
5877
+ 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?");
5878
5878
  }
5879
5879
  // no other complex values
5880
5880
  else if (typeof value === "object") {
5881
- 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.");
5881
+ throw fail("Invalid type definition for property '" + key + "', it looks like you passed an object. Try passing another model type or a types.frozen.");
5882
5882
  }
5883
5883
  else {
5884
- throw fail$1("Invalid type definition for property '" + key + "', cannot infer a type from a value like '" + value + "' (" + typeof value + ")");
5884
+ throw fail("Invalid type definition for property '" + key + "', cannot infer a type from a value like '" + value + "' (" + typeof value + ")");
5885
5885
  }
5886
5886
  return props;
5887
5887
  }, declaredProps);
@@ -5994,7 +5994,7 @@
5994
5994
  this.forAllProps(function (propName, propType) {
5995
5995
  if (propType.flags & TypeFlags.Identifier) {
5996
5996
  if (identifierAttribute)
5997
- throw fail$1("Cannot define property '" + propName + "' as object identifier, property '" + identifierAttribute + "' is already defined as identifier property");
5997
+ throw fail("Cannot define property '" + propName + "' as object identifier, property '" + identifierAttribute + "' is already defined as identifier property");
5998
5998
  identifierAttribute = propName;
5999
5999
  }
6000
6000
  });
@@ -6035,15 +6035,15 @@
6035
6035
  value: function (self, actions) {
6036
6036
  // check if return is correct
6037
6037
  if (!isPlainObject(actions))
6038
- throw fail$1("actions initializer should return a plain object containing actions");
6038
+ throw fail("actions initializer should return a plain object containing actions");
6039
6039
  // bind actions to the object created
6040
6040
  Object.keys(actions).forEach(function (name) {
6041
6041
  // warn if preprocessor was given
6042
6042
  if (name === PRE_PROCESS_SNAPSHOT)
6043
- throw fail$1("Cannot define action '" + PRE_PROCESS_SNAPSHOT + "', it should be defined using 'type.preProcessSnapshot(fn)' instead");
6043
+ throw fail("Cannot define action '" + PRE_PROCESS_SNAPSHOT + "', it should be defined using 'type.preProcessSnapshot(fn)' instead");
6044
6044
  // warn if postprocessor was given
6045
6045
  if (name === POST_PROCESS_SNAPSHOT)
6046
- throw fail$1("Cannot define action '" + POST_PROCESS_SNAPSHOT + "', it should be defined using 'type.postProcessSnapshot(fn)' instead");
6046
+ throw fail("Cannot define action '" + POST_PROCESS_SNAPSHOT + "', it should be defined using 'type.postProcessSnapshot(fn)' instead");
6047
6047
  var action2 = actions[name];
6048
6048
  // apply hook composition
6049
6049
  var baseAction = self[name];
@@ -6073,7 +6073,7 @@
6073
6073
  value: function (fn) {
6074
6074
  var _this = this;
6075
6075
  if (typeof fn !== "function") {
6076
- throw fail$1("You passed an " + typeof fn + " to volatile state as an argument, when function is expected");
6076
+ throw fail("You passed an " + typeof fn + " to volatile state as an argument, when function is expected");
6077
6077
  }
6078
6078
  var stateInitializer = function (self) {
6079
6079
  _this.instantiateVolatileState(self, fn(self));
@@ -6089,7 +6089,7 @@
6089
6089
  value: function (self, state) {
6090
6090
  // check views return
6091
6091
  if (!isPlainObject(state))
6092
- throw fail$1("volatile state initializer should return a plain object containing state");
6092
+ throw fail("volatile state initializer should return a plain object containing state");
6093
6093
  mobx.set(self, state);
6094
6094
  }
6095
6095
  });
@@ -6102,7 +6102,7 @@
6102
6102
  var initializer = function (self) {
6103
6103
  var _a = fn(self), actions = _a.actions, views = _a.views, state = _a.state, rest = __rest(_a, ["actions", "views", "state"]);
6104
6104
  for (var key in rest)
6105
- throw fail$1("The `extend` function should return an object with a subset of the fields 'actions', 'views' and 'state'. Found invalid key '" + key + "'");
6105
+ throw fail("The `extend` function should return an object with a subset of the fields 'actions', 'views' and 'state'. Found invalid key '" + key + "'");
6106
6106
  if (state)
6107
6107
  _this.instantiateVolatileState(self, state);
6108
6108
  if (views)
@@ -6134,7 +6134,7 @@
6134
6134
  value: function (self, views) {
6135
6135
  // check views return
6136
6136
  if (!isPlainObject(views))
6137
- throw fail$1("views initializer should return a plain object containing views");
6137
+ throw fail("views initializer should return a plain object containing views");
6138
6138
  Object.getOwnPropertyNames(views).forEach(function (key) {
6139
6139
  var _a;
6140
6140
  // is this a computed property?
@@ -6147,7 +6147,7 @@
6147
6147
  (addHiddenWritableProp)(self, key, descriptor.value);
6148
6148
  }
6149
6149
  else {
6150
- throw fail$1("A view member should either be a function or getter based property");
6150
+ throw fail("A view member should either be a function or getter based property");
6151
6151
  }
6152
6152
  });
6153
6153
  }
@@ -6263,11 +6263,11 @@
6263
6263
  value: function (node, key) {
6264
6264
  var _a;
6265
6265
  if (!(key in this.properties))
6266
- throw fail$1("Not a value property: " + key);
6266
+ throw fail("Not a value property: " + key);
6267
6267
  var adm = mobx._getAdministration(node.storedValue, key);
6268
6268
  var childNode = (_a = adm.raw) === null || _a === void 0 ? void 0 : _a.call(adm);
6269
6269
  if (!childNode)
6270
- throw fail$1("Node not available for property " + key);
6270
+ throw fail("Node not available for property " + key);
6271
6271
  return childNode;
6272
6272
  }
6273
6273
  });
@@ -6286,7 +6286,7 @@
6286
6286
  atom.reportObserved();
6287
6287
  }
6288
6288
  catch (e) {
6289
- throw fail$1(name + " property is declared twice");
6289
+ throw fail(name + " property is declared twice");
6290
6290
  }
6291
6291
  res[name] = _this.getChildNode(node, name).snapshot;
6292
6292
  });
@@ -6314,7 +6314,7 @@
6314
6314
  writable: true,
6315
6315
  value: function (node, subpath, patch) {
6316
6316
  if (!(patch.op === "replace" || patch.op === "add")) {
6317
- throw fail$1("object does not support operation " + patch.op);
6317
+ throw fail("object does not support operation " + patch.op);
6318
6318
  }
6319
6319
  node.storedValue[subpath] = patch.value;
6320
6320
  }
@@ -6426,7 +6426,7 @@
6426
6426
  args[_i] = arguments[_i];
6427
6427
  }
6428
6428
  if (typeof args[0] !== "string" && args[1]) {
6429
- throw fail$1("Model creation failed. First argument must be a string when two arguments are provided");
6429
+ throw fail("Model creation failed. First argument must be a string when two arguments are provided");
6430
6430
  }
6431
6431
  var name = typeof args[0] === "string" ? args.shift() : "AnonymousModel";
6432
6432
  var properties = args.shift() || {};
@@ -6673,7 +6673,7 @@
6673
6673
  if (value instanceof Date)
6674
6674
  return DatePrimitive;
6675
6675
  }
6676
- throw fail$1("Cannot determine primitive type from value " + value);
6676
+ throw fail("Cannot determine primitive type from value " + value);
6677
6677
  }
6678
6678
  /**
6679
6679
  * Returns if a given value represents a primitive type.
@@ -6993,7 +6993,7 @@
6993
6993
  value: function (parent, subpath, environment, initialValue) {
6994
6994
  var type = this.determineType(initialValue, undefined);
6995
6995
  if (!type)
6996
- throw fail$1("No matching type for union " + this.describe()); // can happen in prod builds
6996
+ throw fail("No matching type for union " + this.describe()); // can happen in prod builds
6997
6997
  return type.instantiate(parent, subpath, environment, initialValue);
6998
6998
  }
6999
6999
  });
@@ -7004,7 +7004,7 @@
7004
7004
  value: function (current, newValue, parent, subpath) {
7005
7005
  var type = this.determineType(newValue, current.getReconciliationType());
7006
7006
  if (!type)
7007
- throw fail$1("No matching type for union " + this.describe()); // can happen in prod builds
7007
+ throw fail("No matching type for union " + this.describe()); // can happen in prod builds
7008
7008
  return type.reconcile(current, newValue, parent, subpath);
7009
7009
  }
7010
7010
  });
@@ -7219,7 +7219,7 @@
7219
7219
  function checkOptionalPreconditions(type, defaultValueOrFunction) {
7220
7220
  // make sure we never pass direct instances
7221
7221
  if (typeof defaultValueOrFunction !== "function" && isStateTreeNode(defaultValueOrFunction)) {
7222
- throw fail$1("default value cannot be an instance, pass a snapshot or a function that creates an instance/snapshot instead");
7222
+ throw fail("default value cannot be an instance, pass a snapshot or a function that creates an instance/snapshot instead");
7223
7223
  }
7224
7224
  assertIsType(type, 1);
7225
7225
  {
@@ -7358,10 +7358,10 @@
7358
7358
  throw e;
7359
7359
  }
7360
7360
  if (mustSucceed && t === undefined)
7361
- throw fail$1("Late type seems to be used too early, the definition (still) returns undefined");
7361
+ throw fail("Late type seems to be used too early, the definition (still) returns undefined");
7362
7362
  if (t) {
7363
7363
  if (!isType(t))
7364
- throw fail$1("Failed to determine subtype, make sure types.late returns a type definition.");
7364
+ throw fail("Failed to determine subtype, make sure types.late returns a type definition.");
7365
7365
  this._subType = t;
7366
7366
  }
7367
7367
  }
@@ -7448,7 +7448,7 @@
7448
7448
  // checks that the type is actually a late type
7449
7449
  {
7450
7450
  if (!(typeof type === "function" && type.length === 0))
7451
- throw fail$1("Invalid late type, expected a function with zero arguments that returns a type, got: " +
7451
+ throw fail("Invalid late type, expected a function with zero arguments that returns a type, got: " +
7452
7452
  type);
7453
7453
  }
7454
7454
  return new Late(name, type);
@@ -7731,15 +7731,15 @@
7731
7731
  else if (isStateTreeNode(value)) {
7732
7732
  var targetNode = getStateTreeNode(value);
7733
7733
  if (!targetNode.identifierAttribute)
7734
- throw fail$1("Can only store references with a defined identifier attribute.");
7734
+ throw fail("Can only store references with a defined identifier attribute.");
7735
7735
  var id = targetNode.unnormalizedIdentifier;
7736
7736
  if (id === null || id === undefined) {
7737
- throw fail$1("Can only store references to tree nodes with a defined identifier.");
7737
+ throw fail("Can only store references to tree nodes with a defined identifier.");
7738
7738
  }
7739
7739
  this.identifier = id;
7740
7740
  }
7741
7741
  else {
7742
- throw fail$1("Can only store references to tree nodes or identifiers, got: '" + value + "'");
7742
+ throw fail("Can only store references to tree nodes or identifiers, got: '" + value + "'");
7743
7743
  }
7744
7744
  }
7745
7745
  Object.defineProperty(StoredReference.prototype, "updateResolvedReference", {
@@ -8121,7 +8121,7 @@
8121
8121
  {
8122
8122
  if (arguments.length === 2 && typeof arguments[1] === "string") {
8123
8123
  // istanbul ignore next
8124
- throw fail$1("References with base path are no longer supported. Please remove the base path.");
8124
+ throw fail("References with base path are no longer supported. Please remove the base path.");
8125
8125
  }
8126
8126
  }
8127
8127
  var getSetOptions = options ? options : undefined;
@@ -8131,7 +8131,7 @@
8131
8131
  if (getSetOptions && (getSetOptions.get || getSetOptions.set)) {
8132
8132
  {
8133
8133
  if (!getSetOptions.get || !getSetOptions.set) {
8134
- throw fail$1("reference options must either contain both a 'get' and a 'set' method or none of them");
8134
+ throw fail("reference options must either contain both a 'get' and a 'set' method or none of them");
8135
8135
  }
8136
8136
  }
8137
8137
  return new CustomReferenceType(subType, {
@@ -8209,7 +8209,7 @@
8209
8209
  writable: true,
8210
8210
  value: function (parent, subpath, environment, initialValue) {
8211
8211
  if (!parent || !(parent.type instanceof ModelType))
8212
- throw fail$1("Identifier types can only be instantiated as direct child of a model type");
8212
+ throw fail("Identifier types can only be instantiated as direct child of a model type");
8213
8213
  return createScalarNode(this, parent, subpath, environment, initialValue);
8214
8214
  }
8215
8215
  });
@@ -8220,7 +8220,7 @@
8220
8220
  value: function (current, newValue, parent, subpath) {
8221
8221
  // we don't consider detaching here since identifier are scalar nodes, and scalar nodes cannot be detached
8222
8222
  if (current.storedValue !== newValue)
8223
- throw fail$1("Tried to change identifier from '" + current.storedValue + "' to '" + newValue + "'. Changing identifiers is not allowed.");
8223
+ throw fail("Tried to change identifier from '" + current.storedValue + "' to '" + newValue + "'. Changing identifiers is not allowed.");
8224
8224
  current.setParent(parent, subpath);
8225
8225
  return current;
8226
8226
  }