mobx-state-tree 5.4.0-pre.1 → 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.
- package/dist/mobx-state-tree.js +110 -98
- package/dist/mobx-state-tree.min.js +1 -1
- package/dist/mobx-state-tree.module.js +110 -98
- package/dist/mobx-state-tree.umd.js +110 -98
- package/dist/mobx-state-tree.umd.min.js +1 -1
- package/dist/types/utility-types/snapshotProcessor.d.ts +9 -7
- package/package.json +1 -2
package/dist/mobx-state-tree.js
CHANGED
|
@@ -348,7 +348,7 @@ function protect(target) {
|
|
|
348
348
|
assertIsStateTreeNode(target, 1);
|
|
349
349
|
var node = getStateTreeNode(target);
|
|
350
350
|
if (!node.isRoot)
|
|
351
|
-
throw fail
|
|
351
|
+
throw fail("`protect` can only be invoked on root nodes");
|
|
352
352
|
node.isProtectionEnabled = true;
|
|
353
353
|
}
|
|
354
354
|
/**
|
|
@@ -380,7 +380,7 @@ function unprotect(target) {
|
|
|
380
380
|
assertIsStateTreeNode(target, 1);
|
|
381
381
|
var node = getStateTreeNode(target);
|
|
382
382
|
if (!node.isRoot)
|
|
383
|
-
throw fail
|
|
383
|
+
throw fail("`unprotect` can only be invoked on root nodes");
|
|
384
384
|
node.isProtectionEnabled = false;
|
|
385
385
|
}
|
|
386
386
|
/**
|
|
@@ -463,7 +463,7 @@ function getParent(target, depth) {
|
|
|
463
463
|
return parent.storedValue;
|
|
464
464
|
parent = parent.parent;
|
|
465
465
|
}
|
|
466
|
-
throw fail
|
|
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 @@ function getParentOfType(target, type) {
|
|
|
501
501
|
return parent.storedValue;
|
|
502
502
|
parent = parent.parent;
|
|
503
503
|
}
|
|
504
|
-
throw fail
|
|
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 @@ function tryReference(getter, checkIfAlive) {
|
|
|
618
618
|
}
|
|
619
619
|
}
|
|
620
620
|
else {
|
|
621
|
-
throw fail
|
|
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 @@ function isValidReference(getter, checkIfAlive) {
|
|
|
646
646
|
return checkIfAlive ? isAlive(node) : true;
|
|
647
647
|
}
|
|
648
648
|
else {
|
|
649
|
-
throw fail
|
|
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 @@ var ScalarNode = /** @class */ (function (_super) {
|
|
|
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
|
|
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 @@ var ScalarNode = /** @class */ (function (_super) {
|
|
|
1320
1320
|
if (devMode()) {
|
|
1321
1321
|
if (!subpath) {
|
|
1322
1322
|
// istanbul ignore next
|
|
1323
|
-
throw fail
|
|
1323
|
+
throw fail("assertion failed: subpath expected");
|
|
1324
1324
|
}
|
|
1325
1325
|
if (!newParent) {
|
|
1326
1326
|
// istanbul ignore next
|
|
1327
|
-
throw fail
|
|
1327
|
+
throw fail("assertion failed: parent expected");
|
|
1328
1328
|
}
|
|
1329
1329
|
if (parentChanged) {
|
|
1330
1330
|
// istanbul ignore next
|
|
1331
|
-
throw fail
|
|
1331
|
+
throw fail("assertion failed: scalar nodes cannot change their parent");
|
|
1332
1332
|
}
|
|
1333
1333
|
}
|
|
1334
1334
|
this.environment = undefined; // use parent's
|
|
@@ -1462,6 +1462,12 @@ var ObjectNode = /** @class */ (function (_super) {
|
|
|
1462
1462
|
writable: true,
|
|
1463
1463
|
value: void 0
|
|
1464
1464
|
});
|
|
1465
|
+
Object.defineProperty(_this, "hasSnapshotPostProcessor", {
|
|
1466
|
+
enumerable: true,
|
|
1467
|
+
configurable: true,
|
|
1468
|
+
writable: true,
|
|
1469
|
+
value: false
|
|
1470
|
+
});
|
|
1465
1471
|
Object.defineProperty(_this, "_applyPatches", {
|
|
1466
1472
|
enumerable: true,
|
|
1467
1473
|
configurable: true,
|
|
@@ -1563,7 +1569,7 @@ var ObjectNode = /** @class */ (function (_super) {
|
|
|
1563
1569
|
}
|
|
1564
1570
|
}
|
|
1565
1571
|
if (typeof id !== "string" && typeof id !== "number") {
|
|
1566
|
-
throw fail
|
|
1572
|
+
throw fail("Instance identifier '" + _this.identifierAttribute + "' for type '" + _this.type.name + "' must be a string or a number");
|
|
1567
1573
|
}
|
|
1568
1574
|
// normalize internal identifier to string
|
|
1569
1575
|
_this.identifier = normalizeIdentifier(id);
|
|
@@ -1616,7 +1622,7 @@ var ObjectNode = /** @class */ (function (_super) {
|
|
|
1616
1622
|
if (devMode()) {
|
|
1617
1623
|
if (this.state !== NodeLifeCycle.INITIALIZING) {
|
|
1618
1624
|
// istanbul ignore next
|
|
1619
|
-
throw fail
|
|
1625
|
+
throw fail("assertion failed: the creation of the observable instance must be done on the initializing phase");
|
|
1620
1626
|
}
|
|
1621
1627
|
}
|
|
1622
1628
|
this._observableInstanceState = 1 /* CREATING */;
|
|
@@ -1739,20 +1745,20 @@ var ObjectNode = /** @class */ (function (_super) {
|
|
|
1739
1745
|
if (devMode()) {
|
|
1740
1746
|
if (!subpath) {
|
|
1741
1747
|
// istanbul ignore next
|
|
1742
|
-
throw fail
|
|
1748
|
+
throw fail("assertion failed: subpath expected");
|
|
1743
1749
|
}
|
|
1744
1750
|
if (!newParent) {
|
|
1745
1751
|
// istanbul ignore next
|
|
1746
|
-
throw fail
|
|
1752
|
+
throw fail("assertion failed: new parent expected");
|
|
1747
1753
|
}
|
|
1748
1754
|
if (this.parent && parentChanged) {
|
|
1749
|
-
throw fail
|
|
1755
|
+
throw fail("A node cannot exists twice in the state tree. Failed to add " + this + " to path '" + newParent.path + "/" + subpath + "'.");
|
|
1750
1756
|
}
|
|
1751
1757
|
if (!this.parent && newParent.root === this) {
|
|
1752
|
-
throw fail
|
|
1758
|
+
throw fail("A state tree is not allowed to contain itself. Cannot assign " + this + " to path '" + newParent.path + "/" + subpath + "'");
|
|
1753
1759
|
}
|
|
1754
1760
|
if (!this.parent && !!this.environment && this.environment !== newParent.root.environment) {
|
|
1755
|
-
throw fail
|
|
1761
|
+
throw fail("A state tree cannot be made part of another state tree as long as their environments are different.");
|
|
1756
1762
|
}
|
|
1757
1763
|
}
|
|
1758
1764
|
if (parentChanged) {
|
|
@@ -1792,6 +1798,9 @@ var ObjectNode = /** @class */ (function (_super) {
|
|
|
1792
1798
|
Object.defineProperty(ObjectNode.prototype, "snapshot", {
|
|
1793
1799
|
// advantage of using computed for a snapshot is that nicely respects transactions etc.
|
|
1794
1800
|
get: function () {
|
|
1801
|
+
if (this.hasSnapshotPostProcessor) {
|
|
1802
|
+
this.createObservableInstanceIfNeeded();
|
|
1803
|
+
}
|
|
1795
1804
|
return this._snapshotComputed.get();
|
|
1796
1805
|
},
|
|
1797
1806
|
enumerable: false,
|
|
@@ -1855,7 +1864,7 @@ var ObjectNode = /** @class */ (function (_super) {
|
|
|
1855
1864
|
var error = this._getAssertAliveError(context);
|
|
1856
1865
|
switch (livelinessChecking) {
|
|
1857
1866
|
case "error":
|
|
1858
|
-
throw fail
|
|
1867
|
+
throw fail(error);
|
|
1859
1868
|
case "warn":
|
|
1860
1869
|
warnError(error);
|
|
1861
1870
|
}
|
|
@@ -1941,7 +1950,7 @@ var ObjectNode = /** @class */ (function (_super) {
|
|
|
1941
1950
|
value: function (context) {
|
|
1942
1951
|
this.assertAlive(context);
|
|
1943
1952
|
if (!this.isRunningAction() && this.isProtected) {
|
|
1944
|
-
throw fail
|
|
1953
|
+
throw fail("Cannot modify '" + this + "', the object is protected and can only be modified by using an action.");
|
|
1945
1954
|
}
|
|
1946
1955
|
}
|
|
1947
1956
|
});
|
|
@@ -2008,7 +2017,7 @@ var ObjectNode = /** @class */ (function (_super) {
|
|
|
2008
2017
|
writable: true,
|
|
2009
2018
|
value: function () {
|
|
2010
2019
|
if (!this.isAlive)
|
|
2011
|
-
throw fail
|
|
2020
|
+
throw fail("Error while detaching, node is not alive.");
|
|
2012
2021
|
this.clearParent();
|
|
2013
2022
|
}
|
|
2014
2023
|
});
|
|
@@ -2144,7 +2153,7 @@ var ObjectNode = /** @class */ (function (_super) {
|
|
|
2144
2153
|
this._internalEventsRegister("dispose" /* Dispose */, disposer, true);
|
|
2145
2154
|
return;
|
|
2146
2155
|
}
|
|
2147
|
-
throw fail
|
|
2156
|
+
throw fail("cannot add a disposer when it is already registered for execution");
|
|
2148
2157
|
}
|
|
2149
2158
|
});
|
|
2150
2159
|
Object.defineProperty(ObjectNode.prototype, "removeDisposer", {
|
|
@@ -2153,7 +2162,7 @@ var ObjectNode = /** @class */ (function (_super) {
|
|
|
2153
2162
|
writable: true,
|
|
2154
2163
|
value: function (disposer) {
|
|
2155
2164
|
if (!this._internalEventsHas("dispose" /* Dispose */, disposer)) {
|
|
2156
|
-
throw fail
|
|
2165
|
+
throw fail("cannot remove a disposer which was never registered for execution");
|
|
2157
2166
|
}
|
|
2158
2167
|
this._internalEventsUnregister("dispose" /* Dispose */, disposer);
|
|
2159
2168
|
}
|
|
@@ -2399,7 +2408,7 @@ var BaseType = /** @class */ (function () {
|
|
|
2399
2408
|
writable: true,
|
|
2400
2409
|
value: function (node, applyPostProcess) {
|
|
2401
2410
|
// istanbul ignore next
|
|
2402
|
-
throw fail
|
|
2411
|
+
throw fail("unimplemented method");
|
|
2403
2412
|
}
|
|
2404
2413
|
});
|
|
2405
2414
|
Object.defineProperty(BaseType.prototype, "isAssignableFrom", {
|
|
@@ -2437,7 +2446,7 @@ var BaseType = /** @class */ (function () {
|
|
|
2437
2446
|
Object.defineProperty(BaseType.prototype, "Type", {
|
|
2438
2447
|
get: function () {
|
|
2439
2448
|
// istanbul ignore next
|
|
2440
|
-
throw fail
|
|
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`");
|
|
2441
2450
|
},
|
|
2442
2451
|
enumerable: false,
|
|
2443
2452
|
configurable: true
|
|
@@ -2445,7 +2454,7 @@ var BaseType = /** @class */ (function () {
|
|
|
2445
2454
|
Object.defineProperty(BaseType.prototype, "TypeWithoutSTN", {
|
|
2446
2455
|
get: function () {
|
|
2447
2456
|
// istanbul ignore next
|
|
2448
|
-
throw fail
|
|
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`");
|
|
2449
2458
|
},
|
|
2450
2459
|
enumerable: false,
|
|
2451
2460
|
configurable: true
|
|
@@ -2453,7 +2462,7 @@ var BaseType = /** @class */ (function () {
|
|
|
2453
2462
|
Object.defineProperty(BaseType.prototype, "SnapshotType", {
|
|
2454
2463
|
get: function () {
|
|
2455
2464
|
// istanbul ignore next
|
|
2456
|
-
throw fail
|
|
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`");
|
|
2457
2466
|
},
|
|
2458
2467
|
enumerable: false,
|
|
2459
2468
|
configurable: true
|
|
@@ -2461,7 +2470,7 @@ var BaseType = /** @class */ (function () {
|
|
|
2461
2470
|
Object.defineProperty(BaseType.prototype, "CreationType", {
|
|
2462
2471
|
get: function () {
|
|
2463
2472
|
// istanbul ignore next
|
|
2464
|
-
throw fail
|
|
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`");
|
|
2465
2474
|
},
|
|
2466
2475
|
enumerable: false,
|
|
2467
2476
|
configurable: true
|
|
@@ -2951,7 +2960,7 @@ function applyAction(target, actions) {
|
|
|
2951
2960
|
function baseApplyAction(target, action) {
|
|
2952
2961
|
var resolvedTarget = tryResolve(target, action.path || "");
|
|
2953
2962
|
if (!resolvedTarget)
|
|
2954
|
-
throw fail
|
|
2963
|
+
throw fail("Invalid action path: " + (action.path || ""));
|
|
2955
2964
|
var node = getStateTreeNode(resolvedTarget);
|
|
2956
2965
|
// Reserved functions
|
|
2957
2966
|
if (action.name === "@APPLY_PATCHES") {
|
|
@@ -2961,7 +2970,7 @@ function baseApplyAction(target, action) {
|
|
|
2961
2970
|
return applySnapshot.call(null, resolvedTarget, action.args[0]);
|
|
2962
2971
|
}
|
|
2963
2972
|
if (!(typeof resolvedTarget[action.name] === "function"))
|
|
2964
|
-
throw fail
|
|
2973
|
+
throw fail("Action '" + action.name + "' does not exist in '" + node.path + "'");
|
|
2965
2974
|
return resolvedTarget[action.name].apply(resolvedTarget, action.args ? action.args.map(function (v) { return deserializeArgument(node, v); }) : []);
|
|
2966
2975
|
}
|
|
2967
2976
|
/**
|
|
@@ -3322,11 +3331,11 @@ function runMiddleWares(node, baseCall, originalFn) {
|
|
|
3322
3331
|
if (devMode()) {
|
|
3323
3332
|
if (!nextInvoked && !abortInvoked) {
|
|
3324
3333
|
var node2 = getStateTreeNode(call.tree);
|
|
3325
|
-
throw fail
|
|
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.");
|
|
3326
3335
|
}
|
|
3327
3336
|
else if (nextInvoked && abortInvoked) {
|
|
3328
3337
|
var node2 = getStateTreeNode(call.tree);
|
|
3329
|
-
throw fail
|
|
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.");
|
|
3330
3339
|
}
|
|
3331
3340
|
}
|
|
3332
3341
|
return result;
|
|
@@ -3473,7 +3482,7 @@ function typecheckInternal(type, value) {
|
|
|
3473
3482
|
function typecheck(type, value) {
|
|
3474
3483
|
var errors = type.validate(value, [{ path: "", type: type }]);
|
|
3475
3484
|
if (errors.length > 0) {
|
|
3476
|
-
throw fail
|
|
3485
|
+
throw fail(validationErrorsToString(type, value, errors));
|
|
3477
3486
|
}
|
|
3478
3487
|
}
|
|
3479
3488
|
function validationErrorsToString(type, value, errors) {
|
|
@@ -3544,7 +3553,7 @@ var IdentifierCache = /** @class */ (function () {
|
|
|
3544
3553
|
}
|
|
3545
3554
|
var set = this.cache.get(identifier);
|
|
3546
3555
|
if (set.indexOf(node) !== -1)
|
|
3547
|
-
throw fail
|
|
3556
|
+
throw fail("Already registered");
|
|
3548
3557
|
set.push(node);
|
|
3549
3558
|
if (lastCacheUpdate) {
|
|
3550
3559
|
this.updateLastCacheModificationPerId(identifier);
|
|
@@ -3643,7 +3652,7 @@ var IdentifierCache = /** @class */ (function () {
|
|
|
3643
3652
|
case 1:
|
|
3644
3653
|
return matches[0];
|
|
3645
3654
|
default:
|
|
3646
|
-
throw fail
|
|
3655
|
+
throw fail("Cannot resolve a reference to type '" + type.name + "' with id: '" + identifier + "' unambigously, there are multiple candidates: " + matches
|
|
3647
3656
|
.map(function (n) { return n.path; })
|
|
3648
3657
|
.join(", "));
|
|
3649
3658
|
}
|
|
@@ -3661,7 +3670,7 @@ function createObjectNode(type, parent, subpath, environment, initialValue) {
|
|
|
3661
3670
|
if (existingNode) {
|
|
3662
3671
|
if (existingNode.parent) {
|
|
3663
3672
|
// istanbul ignore next
|
|
3664
|
-
throw fail
|
|
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 + "'");
|
|
3665
3674
|
}
|
|
3666
3675
|
if (parent) {
|
|
3667
3676
|
existingNode.setParent(parent, subpath);
|
|
@@ -3724,7 +3733,7 @@ function assertIsStateTreeNode(value, argNumber) {
|
|
|
3724
3733
|
function getStateTreeNode(value) {
|
|
3725
3734
|
if (!isStateTreeNode(value)) {
|
|
3726
3735
|
// istanbul ignore next
|
|
3727
|
-
throw fail
|
|
3736
|
+
throw fail("Value " + value + " is no MST Node");
|
|
3728
3737
|
}
|
|
3729
3738
|
return value.$treenode;
|
|
3730
3739
|
}
|
|
@@ -3750,7 +3759,7 @@ var doubleDot = function (_) { return ".."; };
|
|
|
3750
3759
|
function getRelativePathBetweenNodes(base, target) {
|
|
3751
3760
|
// PRE condition target is (a child of) base!
|
|
3752
3761
|
if (base.root !== target.root) {
|
|
3753
|
-
throw fail
|
|
3762
|
+
throw fail("Cannot calculate relative path: objects '" + base + "' and '" + target + "' are not part of the same object tree");
|
|
3754
3763
|
}
|
|
3755
3764
|
var baseParts = splitJsonPath(base.path);
|
|
3756
3765
|
var targetParts = splitJsonPath(target.path);
|
|
@@ -3807,7 +3816,7 @@ function resolveNodeByPathParts(base, pathParts, failIfResolveFails) {
|
|
|
3807
3816
|
}
|
|
3808
3817
|
}
|
|
3809
3818
|
}
|
|
3810
|
-
throw fail
|
|
3819
|
+
throw fail("Could not resolve '" + part + "' in path '" + (joinJsonPath(pathParts.slice(0, i)) || "/") + "' while resolving '" + joinJsonPath(pathParts) + "'");
|
|
3811
3820
|
}
|
|
3812
3821
|
}
|
|
3813
3822
|
catch (e) {
|
|
@@ -3883,7 +3892,7 @@ Object.freeze(mobxShallow);
|
|
|
3883
3892
|
* @internal
|
|
3884
3893
|
* @hidden
|
|
3885
3894
|
*/
|
|
3886
|
-
function fail
|
|
3895
|
+
function fail(message) {
|
|
3887
3896
|
if (message === void 0) { message = "Illegal state"; }
|
|
3888
3897
|
return new Error("[mobx-state-tree] " + message);
|
|
3889
3898
|
}
|
|
@@ -4290,7 +4299,7 @@ function assertArg(value, fn, typeName, argNumber) {
|
|
|
4290
4299
|
if (devMode()) {
|
|
4291
4300
|
if (!fn(value)) {
|
|
4292
4301
|
// istanbul ignore next
|
|
4293
|
-
throw fail
|
|
4302
|
+
throw fail("expected " + typeName + " as argument " + asArray(argNumber).join(" or ") + ", got " + value + " instead");
|
|
4294
4303
|
}
|
|
4295
4304
|
}
|
|
4296
4305
|
}
|
|
@@ -4435,11 +4444,11 @@ function createFlowSpawner(name, generator) {
|
|
|
4435
4444
|
var runId = getNextActionId();
|
|
4436
4445
|
var parentContext = getCurrentActionContext();
|
|
4437
4446
|
if (!parentContext) {
|
|
4438
|
-
throw fail
|
|
4447
|
+
throw fail("a mst flow must always have a parent context");
|
|
4439
4448
|
}
|
|
4440
4449
|
var parentActionContext = getParentActionContext(parentContext);
|
|
4441
4450
|
if (!parentActionContext) {
|
|
4442
|
-
throw fail
|
|
4451
|
+
throw fail("a mst flow must always have a parent action context");
|
|
4443
4452
|
}
|
|
4444
4453
|
var contextBase = {
|
|
4445
4454
|
name: name,
|
|
@@ -4510,7 +4519,7 @@ function createFlowSpawner(name, generator) {
|
|
|
4510
4519
|
// TODO: support more type of values? See https://github.com/tj/co/blob/249bbdc72da24ae44076afd716349d2089b31c4c/index.js#L100
|
|
4511
4520
|
if (!ret.value || typeof ret.value.then !== "function") {
|
|
4512
4521
|
// istanbul ignore next
|
|
4513
|
-
throw fail
|
|
4522
|
+
throw fail("Only promises can be yielded to `async`, got: " + ret);
|
|
4514
4523
|
}
|
|
4515
4524
|
return ret.value.then(onFulfilled, onRejected);
|
|
4516
4525
|
}
|
|
@@ -4526,7 +4535,7 @@ function createFlowSpawner(name, generator) {
|
|
|
4526
4535
|
*/
|
|
4527
4536
|
function splitPatch(patch) {
|
|
4528
4537
|
if (!("oldValue" in patch))
|
|
4529
|
-
throw fail
|
|
4538
|
+
throw fail("Patches without `oldValue` field cannot be inversed");
|
|
4530
4539
|
return [stripPatch(patch), invertPatch(patch)];
|
|
4531
4540
|
}
|
|
4532
4541
|
/**
|
|
@@ -4627,7 +4636,7 @@ function splitJsonPath(path) {
|
|
|
4627
4636
|
stringStartsWith(path, "./") ||
|
|
4628
4637
|
stringStartsWith(path, "../");
|
|
4629
4638
|
if (!valid) {
|
|
4630
|
-
throw fail
|
|
4639
|
+
throw fail("a json path must be either rooted, empty or relative, but got '" + path + "'");
|
|
4631
4640
|
}
|
|
4632
4641
|
// '/a/b/c' -> ["a", "b", "c"]
|
|
4633
4642
|
// '../../b/c' -> ["..", "..", "b", "c"]
|
|
@@ -4704,9 +4713,9 @@ var SnapshotProcessor = /** @class */ (function (_super) {
|
|
|
4704
4713
|
enumerable: false,
|
|
4705
4714
|
configurable: true,
|
|
4706
4715
|
writable: true,
|
|
4707
|
-
value: function (sn) {
|
|
4716
|
+
value: function (sn, node) {
|
|
4708
4717
|
if (this._processors.postProcessor) {
|
|
4709
|
-
return this._processors.postProcessor.call(null, sn);
|
|
4718
|
+
return this._processors.postProcessor.call(null, sn, node.storedValue);
|
|
4710
4719
|
}
|
|
4711
4720
|
return sn;
|
|
4712
4721
|
}
|
|
@@ -4719,10 +4728,11 @@ var SnapshotProcessor = /** @class */ (function (_super) {
|
|
|
4719
4728
|
var _this = this;
|
|
4720
4729
|
// the node has to use these methods rather than the original type ones
|
|
4721
4730
|
proxyNodeTypeMethods(node.type, this, "create");
|
|
4731
|
+
if (node instanceof ObjectNode) {
|
|
4732
|
+
node.hasSnapshotPostProcessor = !!this._processors.postProcessor;
|
|
4733
|
+
}
|
|
4722
4734
|
var oldGetSnapshot = node.getSnapshot;
|
|
4723
|
-
node.getSnapshot = function () {
|
|
4724
|
-
return _this.postProcessSnapshot(oldGetSnapshot.call(node));
|
|
4725
|
-
};
|
|
4735
|
+
node.getSnapshot = function () { return _this.postProcessSnapshot(oldGetSnapshot.call(node), node); };
|
|
4726
4736
|
if (!isUnionType(this._subtype)) {
|
|
4727
4737
|
node.getReconciliationType = function () {
|
|
4728
4738
|
return _this;
|
|
@@ -4762,7 +4772,7 @@ var SnapshotProcessor = /** @class */ (function (_super) {
|
|
|
4762
4772
|
value: function (node, applyPostProcess) {
|
|
4763
4773
|
if (applyPostProcess === void 0) { applyPostProcess = true; }
|
|
4764
4774
|
var sn = this._subtype.getSnapshot(node);
|
|
4765
|
-
return applyPostProcess ? this.postProcessSnapshot(sn) : sn;
|
|
4775
|
+
return applyPostProcess ? this.postProcessSnapshot(sn, node) : sn;
|
|
4766
4776
|
}
|
|
4767
4777
|
});
|
|
4768
4778
|
Object.defineProperty(SnapshotProcessor.prototype, "isValidSnapshot", {
|
|
@@ -4853,15 +4863,17 @@ function proxyNodeTypeMethods(nodeType, snapshotProcessorType) {
|
|
|
4853
4863
|
* interface BackendTodo {
|
|
4854
4864
|
* text: string | null
|
|
4855
4865
|
* }
|
|
4866
|
+
*
|
|
4856
4867
|
* const Todo2 = types.snapshotProcessor(Todo1, {
|
|
4857
4868
|
* // from snapshot to instance
|
|
4858
|
-
* preProcessor(
|
|
4869
|
+
* preProcessor(snapshot: BackendTodo) {
|
|
4859
4870
|
* return {
|
|
4860
4871
|
* text: sn.text || "";
|
|
4861
4872
|
* }
|
|
4862
4873
|
* },
|
|
4874
|
+
*
|
|
4863
4875
|
* // from instance to snapshot
|
|
4864
|
-
* postProcessor(
|
|
4876
|
+
* postProcessor(snapshot, node): BackendTodo {
|
|
4865
4877
|
* return {
|
|
4866
4878
|
* text: !sn.text ? null : sn.text
|
|
4867
4879
|
* }
|
|
@@ -4972,28 +4984,28 @@ var MSTMap = /** @class */ (function (_super) {
|
|
|
4972
4984
|
writable: true,
|
|
4973
4985
|
value: function (value) {
|
|
4974
4986
|
if (!value)
|
|
4975
|
-
throw fail
|
|
4987
|
+
throw fail("Map.put cannot be used to set empty values");
|
|
4976
4988
|
if (isStateTreeNode(value)) {
|
|
4977
4989
|
var node = getStateTreeNode(value);
|
|
4978
4990
|
if (devMode()) {
|
|
4979
4991
|
if (!node.identifierAttribute) {
|
|
4980
|
-
throw fail
|
|
4992
|
+
throw fail(needsIdentifierError);
|
|
4981
4993
|
}
|
|
4982
4994
|
}
|
|
4983
4995
|
if (node.identifier === null) {
|
|
4984
|
-
throw fail
|
|
4996
|
+
throw fail(needsIdentifierError);
|
|
4985
4997
|
}
|
|
4986
4998
|
this.set(node.identifier, value);
|
|
4987
4999
|
return value;
|
|
4988
5000
|
}
|
|
4989
5001
|
else if (!isMutable(value)) {
|
|
4990
|
-
throw fail
|
|
5002
|
+
throw fail("Map.put can only be used to store complex values");
|
|
4991
5003
|
}
|
|
4992
5004
|
else {
|
|
4993
5005
|
var mapNode = getStateTreeNode(this);
|
|
4994
5006
|
var mapType = mapNode.type;
|
|
4995
5007
|
if (mapType.identifierMode !== MapIdentifierMode.YES) {
|
|
4996
|
-
throw fail
|
|
5008
|
+
throw fail(needsIdentifierError);
|
|
4997
5009
|
}
|
|
4998
5010
|
var idAttr = mapType.mapIdentifierAttribute;
|
|
4999
5011
|
var id = value[idAttr];
|
|
@@ -5086,7 +5098,7 @@ var MapType = /** @class */ (function (_super) {
|
|
|
5086
5098
|
if (!type.identifierAttribute)
|
|
5087
5099
|
return current;
|
|
5088
5100
|
if (current && current !== type.identifierAttribute) {
|
|
5089
|
-
throw fail
|
|
5101
|
+
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");
|
|
5090
5102
|
}
|
|
5091
5103
|
return type.identifierAttribute;
|
|
5092
5104
|
}, undefined);
|
|
@@ -5165,7 +5177,7 @@ var MapType = /** @class */ (function (_super) {
|
|
|
5165
5177
|
value: function (node, key) {
|
|
5166
5178
|
var childNode = node.storedValue.get("" + key);
|
|
5167
5179
|
if (!childNode)
|
|
5168
|
-
throw fail
|
|
5180
|
+
throw fail("Not a child " + key);
|
|
5169
5181
|
return childNode;
|
|
5170
5182
|
}
|
|
5171
5183
|
});
|
|
@@ -5210,7 +5222,7 @@ var MapType = /** @class */ (function (_super) {
|
|
|
5210
5222
|
if (this.identifierMode === MapIdentifierMode.YES && node instanceof ObjectNode) {
|
|
5211
5223
|
var identifier = node.identifier;
|
|
5212
5224
|
if (identifier !== expected)
|
|
5213
|
-
throw fail
|
|
5225
|
+
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 + "'");
|
|
5214
5226
|
}
|
|
5215
5227
|
}
|
|
5216
5228
|
});
|
|
@@ -5508,7 +5520,7 @@ var ArrayType = /** @class */ (function (_super) {
|
|
|
5508
5520
|
var index = Number(key);
|
|
5509
5521
|
if (index < node.storedValue.length)
|
|
5510
5522
|
return node.storedValue[index];
|
|
5511
|
-
throw fail
|
|
5523
|
+
throw fail("Not a child: " + key);
|
|
5512
5524
|
}
|
|
5513
5525
|
});
|
|
5514
5526
|
Object.defineProperty(ArrayType.prototype, "willChange", {
|
|
@@ -5733,7 +5745,7 @@ function reconcileArrayChildren(parent, childType, oldNodes, newValues, newPaths
|
|
|
5733
5745
|
// check if already belongs to the same parent. if so, avoid pushing item in. only swapping can occur.
|
|
5734
5746
|
if (isStateTreeNode(newValue) && getStateTreeNode(newValue).parent === parent) {
|
|
5735
5747
|
// this node is owned by this parent, but not in the reconcilable set, so it must be double
|
|
5736
|
-
throw fail
|
|
5748
|
+
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 + "'");
|
|
5737
5749
|
}
|
|
5738
5750
|
nothingChanged = false;
|
|
5739
5751
|
var newNode = valueAsNode(childType, parent, newPath, newValue);
|
|
@@ -5849,7 +5861,7 @@ function toPropertiesObject(declaredProps) {
|
|
|
5849
5861
|
var alreadySeenKeys = new Set();
|
|
5850
5862
|
keysList.forEach(function (key) {
|
|
5851
5863
|
if (alreadySeenKeys.has(key)) {
|
|
5852
|
-
throw fail
|
|
5864
|
+
throw fail(key + " is declared twice in the model. Model should not contain the same keys");
|
|
5853
5865
|
}
|
|
5854
5866
|
alreadySeenKeys.add(key);
|
|
5855
5867
|
});
|
|
@@ -5857,17 +5869,17 @@ function toPropertiesObject(declaredProps) {
|
|
|
5857
5869
|
return keysList.reduce(function (props, key) {
|
|
5858
5870
|
// warn if user intended a HOOK
|
|
5859
5871
|
if (key in Hook) {
|
|
5860
|
-
throw fail
|
|
5872
|
+
throw fail("Hook '" + key + "' was defined as property. Hooks should be defined as part of the actions");
|
|
5861
5873
|
}
|
|
5862
5874
|
// the user intended to use a view
|
|
5863
5875
|
var descriptor = Object.getOwnPropertyDescriptor(declaredProps, key);
|
|
5864
5876
|
if ("get" in descriptor) {
|
|
5865
|
-
throw fail
|
|
5877
|
+
throw fail("Getters are not supported as properties. Please use views instead");
|
|
5866
5878
|
}
|
|
5867
5879
|
// undefined and null are not valid
|
|
5868
5880
|
var value = descriptor.value;
|
|
5869
5881
|
if (value === null || value === undefined) {
|
|
5870
|
-
throw fail
|
|
5882
|
+
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)`?");
|
|
5871
5883
|
}
|
|
5872
5884
|
// its a primitive, convert to its type
|
|
5873
5885
|
else if (isPrimitive(value)) {
|
|
@@ -5884,14 +5896,14 @@ function toPropertiesObject(declaredProps) {
|
|
|
5884
5896
|
else if (isType(value)) ;
|
|
5885
5897
|
// its a function, maybe the user wanted a view?
|
|
5886
5898
|
else if (devMode() && typeof value === "function") {
|
|
5887
|
-
throw fail
|
|
5899
|
+
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?");
|
|
5888
5900
|
}
|
|
5889
5901
|
// no other complex values
|
|
5890
5902
|
else if (devMode() && typeof value === "object") {
|
|
5891
|
-
throw fail
|
|
5903
|
+
throw fail("Invalid type definition for property '" + key + "', it looks like you passed an object. Try passing another model type or a types.frozen.");
|
|
5892
5904
|
}
|
|
5893
5905
|
else {
|
|
5894
|
-
throw fail
|
|
5906
|
+
throw fail("Invalid type definition for property '" + key + "', cannot infer a type from a value like '" + value + "' (" + typeof value + ")");
|
|
5895
5907
|
}
|
|
5896
5908
|
return props;
|
|
5897
5909
|
}, declaredProps);
|
|
@@ -6004,7 +6016,7 @@ var ModelType = /** @class */ (function (_super) {
|
|
|
6004
6016
|
this.forAllProps(function (propName, propType) {
|
|
6005
6017
|
if (propType.flags & TypeFlags.Identifier) {
|
|
6006
6018
|
if (identifierAttribute)
|
|
6007
|
-
throw fail
|
|
6019
|
+
throw fail("Cannot define property '" + propName + "' as object identifier, property '" + identifierAttribute + "' is already defined as identifier property");
|
|
6008
6020
|
identifierAttribute = propName;
|
|
6009
6021
|
}
|
|
6010
6022
|
});
|
|
@@ -6045,15 +6057,15 @@ var ModelType = /** @class */ (function (_super) {
|
|
|
6045
6057
|
value: function (self, actions) {
|
|
6046
6058
|
// check if return is correct
|
|
6047
6059
|
if (!isPlainObject(actions))
|
|
6048
|
-
throw fail
|
|
6060
|
+
throw fail("actions initializer should return a plain object containing actions");
|
|
6049
6061
|
// bind actions to the object created
|
|
6050
6062
|
Object.keys(actions).forEach(function (name) {
|
|
6051
6063
|
// warn if preprocessor was given
|
|
6052
6064
|
if (name === PRE_PROCESS_SNAPSHOT)
|
|
6053
|
-
throw fail
|
|
6065
|
+
throw fail("Cannot define action '" + PRE_PROCESS_SNAPSHOT + "', it should be defined using 'type.preProcessSnapshot(fn)' instead");
|
|
6054
6066
|
// warn if postprocessor was given
|
|
6055
6067
|
if (name === POST_PROCESS_SNAPSHOT)
|
|
6056
|
-
throw fail
|
|
6068
|
+
throw fail("Cannot define action '" + POST_PROCESS_SNAPSHOT + "', it should be defined using 'type.postProcessSnapshot(fn)' instead");
|
|
6057
6069
|
var action2 = actions[name];
|
|
6058
6070
|
// apply hook composition
|
|
6059
6071
|
var baseAction = self[name];
|
|
@@ -6083,7 +6095,7 @@ var ModelType = /** @class */ (function (_super) {
|
|
|
6083
6095
|
value: function (fn) {
|
|
6084
6096
|
var _this = this;
|
|
6085
6097
|
if (typeof fn !== "function") {
|
|
6086
|
-
throw fail
|
|
6098
|
+
throw fail("You passed an " + typeof fn + " to volatile state as an argument, when function is expected");
|
|
6087
6099
|
}
|
|
6088
6100
|
var stateInitializer = function (self) {
|
|
6089
6101
|
_this.instantiateVolatileState(self, fn(self));
|
|
@@ -6099,7 +6111,7 @@ var ModelType = /** @class */ (function (_super) {
|
|
|
6099
6111
|
value: function (self, state) {
|
|
6100
6112
|
// check views return
|
|
6101
6113
|
if (!isPlainObject(state))
|
|
6102
|
-
throw fail
|
|
6114
|
+
throw fail("volatile state initializer should return a plain object containing state");
|
|
6103
6115
|
mobx.set(self, state);
|
|
6104
6116
|
}
|
|
6105
6117
|
});
|
|
@@ -6112,7 +6124,7 @@ var ModelType = /** @class */ (function (_super) {
|
|
|
6112
6124
|
var initializer = function (self) {
|
|
6113
6125
|
var _a = fn(self), actions = _a.actions, views = _a.views, state = _a.state, rest = __rest(_a, ["actions", "views", "state"]);
|
|
6114
6126
|
for (var key in rest)
|
|
6115
|
-
throw fail
|
|
6127
|
+
throw fail("The `extend` function should return an object with a subset of the fields 'actions', 'views' and 'state'. Found invalid key '" + key + "'");
|
|
6116
6128
|
if (state)
|
|
6117
6129
|
_this.instantiateVolatileState(self, state);
|
|
6118
6130
|
if (views)
|
|
@@ -6144,7 +6156,7 @@ var ModelType = /** @class */ (function (_super) {
|
|
|
6144
6156
|
value: function (self, views) {
|
|
6145
6157
|
// check views return
|
|
6146
6158
|
if (!isPlainObject(views))
|
|
6147
|
-
throw fail
|
|
6159
|
+
throw fail("views initializer should return a plain object containing views");
|
|
6148
6160
|
Object.getOwnPropertyNames(views).forEach(function (key) {
|
|
6149
6161
|
var _a;
|
|
6150
6162
|
// is this a computed property?
|
|
@@ -6157,7 +6169,7 @@ var ModelType = /** @class */ (function (_super) {
|
|
|
6157
6169
|
(!devMode() ? addHiddenFinalProp : addHiddenWritableProp)(self, key, descriptor.value);
|
|
6158
6170
|
}
|
|
6159
6171
|
else {
|
|
6160
|
-
throw fail
|
|
6172
|
+
throw fail("A view member should either be a function or getter based property");
|
|
6161
6173
|
}
|
|
6162
6174
|
});
|
|
6163
6175
|
}
|
|
@@ -6273,11 +6285,11 @@ var ModelType = /** @class */ (function (_super) {
|
|
|
6273
6285
|
value: function (node, key) {
|
|
6274
6286
|
var _a;
|
|
6275
6287
|
if (!(key in this.properties))
|
|
6276
|
-
throw fail
|
|
6288
|
+
throw fail("Not a value property: " + key);
|
|
6277
6289
|
var adm = mobx._getAdministration(node.storedValue, key);
|
|
6278
6290
|
var childNode = (_a = adm.raw) === null || _a === void 0 ? void 0 : _a.call(adm);
|
|
6279
6291
|
if (!childNode)
|
|
6280
|
-
throw fail
|
|
6292
|
+
throw fail("Node not available for property " + key);
|
|
6281
6293
|
return childNode;
|
|
6282
6294
|
}
|
|
6283
6295
|
});
|
|
@@ -6296,7 +6308,7 @@ var ModelType = /** @class */ (function (_super) {
|
|
|
6296
6308
|
atom.reportObserved();
|
|
6297
6309
|
}
|
|
6298
6310
|
catch (e) {
|
|
6299
|
-
throw fail
|
|
6311
|
+
throw fail(name + " property is declared twice");
|
|
6300
6312
|
}
|
|
6301
6313
|
res[name] = _this.getChildNode(node, name).snapshot;
|
|
6302
6314
|
});
|
|
@@ -6324,7 +6336,7 @@ var ModelType = /** @class */ (function (_super) {
|
|
|
6324
6336
|
writable: true,
|
|
6325
6337
|
value: function (node, subpath, patch) {
|
|
6326
6338
|
if (!(patch.op === "replace" || patch.op === "add")) {
|
|
6327
|
-
throw fail
|
|
6339
|
+
throw fail("object does not support operation " + patch.op);
|
|
6328
6340
|
}
|
|
6329
6341
|
node.storedValue[subpath] = patch.value;
|
|
6330
6342
|
}
|
|
@@ -6436,7 +6448,7 @@ function model() {
|
|
|
6436
6448
|
args[_i] = arguments[_i];
|
|
6437
6449
|
}
|
|
6438
6450
|
if (devMode() && typeof args[0] !== "string" && args[1]) {
|
|
6439
|
-
throw fail
|
|
6451
|
+
throw fail("Model creation failed. First argument must be a string when two arguments are provided");
|
|
6440
6452
|
}
|
|
6441
6453
|
var name = typeof args[0] === "string" ? args.shift() : "AnonymousModel";
|
|
6442
6454
|
var properties = args.shift() || {};
|
|
@@ -6683,7 +6695,7 @@ function getPrimitiveFactoryFromValue(value) {
|
|
|
6683
6695
|
if (value instanceof Date)
|
|
6684
6696
|
return DatePrimitive;
|
|
6685
6697
|
}
|
|
6686
|
-
throw fail
|
|
6698
|
+
throw fail("Cannot determine primitive type from value " + value);
|
|
6687
6699
|
}
|
|
6688
6700
|
/**
|
|
6689
6701
|
* Returns if a given value represents a primitive type.
|
|
@@ -7003,7 +7015,7 @@ var Union = /** @class */ (function (_super) {
|
|
|
7003
7015
|
value: function (parent, subpath, environment, initialValue) {
|
|
7004
7016
|
var type = this.determineType(initialValue, undefined);
|
|
7005
7017
|
if (!type)
|
|
7006
|
-
throw fail
|
|
7018
|
+
throw fail("No matching type for union " + this.describe()); // can happen in prod builds
|
|
7007
7019
|
return type.instantiate(parent, subpath, environment, initialValue);
|
|
7008
7020
|
}
|
|
7009
7021
|
});
|
|
@@ -7014,7 +7026,7 @@ var Union = /** @class */ (function (_super) {
|
|
|
7014
7026
|
value: function (current, newValue, parent, subpath) {
|
|
7015
7027
|
var type = this.determineType(newValue, current.getReconciliationType());
|
|
7016
7028
|
if (!type)
|
|
7017
|
-
throw fail
|
|
7029
|
+
throw fail("No matching type for union " + this.describe()); // can happen in prod builds
|
|
7018
7030
|
return type.reconcile(current, newValue, parent, subpath);
|
|
7019
7031
|
}
|
|
7020
7032
|
});
|
|
@@ -7229,7 +7241,7 @@ var OptionalValue = /** @class */ (function (_super) {
|
|
|
7229
7241
|
function checkOptionalPreconditions(type, defaultValueOrFunction) {
|
|
7230
7242
|
// make sure we never pass direct instances
|
|
7231
7243
|
if (typeof defaultValueOrFunction !== "function" && isStateTreeNode(defaultValueOrFunction)) {
|
|
7232
|
-
throw fail
|
|
7244
|
+
throw fail("default value cannot be an instance, pass a snapshot or a function that creates an instance/snapshot instead");
|
|
7233
7245
|
}
|
|
7234
7246
|
assertIsType(type, 1);
|
|
7235
7247
|
if (devMode()) {
|
|
@@ -7368,10 +7380,10 @@ var Late = /** @class */ (function (_super) {
|
|
|
7368
7380
|
throw e;
|
|
7369
7381
|
}
|
|
7370
7382
|
if (mustSucceed && t === undefined)
|
|
7371
|
-
throw fail
|
|
7383
|
+
throw fail("Late type seems to be used too early, the definition (still) returns undefined");
|
|
7372
7384
|
if (t) {
|
|
7373
7385
|
if (devMode() && !isType(t))
|
|
7374
|
-
throw fail
|
|
7386
|
+
throw fail("Failed to determine subtype, make sure types.late returns a type definition.");
|
|
7375
7387
|
this._subType = t;
|
|
7376
7388
|
}
|
|
7377
7389
|
}
|
|
@@ -7458,7 +7470,7 @@ function late(nameOrType, maybeType) {
|
|
|
7458
7470
|
// checks that the type is actually a late type
|
|
7459
7471
|
if (devMode()) {
|
|
7460
7472
|
if (!(typeof type === "function" && type.length === 0))
|
|
7461
|
-
throw fail
|
|
7473
|
+
throw fail("Invalid late type, expected a function with zero arguments that returns a type, got: " +
|
|
7462
7474
|
type);
|
|
7463
7475
|
}
|
|
7464
7476
|
return new Late(name, type);
|
|
@@ -7741,15 +7753,15 @@ var StoredReference = /** @class */ (function () {
|
|
|
7741
7753
|
else if (isStateTreeNode(value)) {
|
|
7742
7754
|
var targetNode = getStateTreeNode(value);
|
|
7743
7755
|
if (!targetNode.identifierAttribute)
|
|
7744
|
-
throw fail
|
|
7756
|
+
throw fail("Can only store references with a defined identifier attribute.");
|
|
7745
7757
|
var id = targetNode.unnormalizedIdentifier;
|
|
7746
7758
|
if (id === null || id === undefined) {
|
|
7747
|
-
throw fail
|
|
7759
|
+
throw fail("Can only store references to tree nodes with a defined identifier.");
|
|
7748
7760
|
}
|
|
7749
7761
|
this.identifier = id;
|
|
7750
7762
|
}
|
|
7751
7763
|
else {
|
|
7752
|
-
throw fail
|
|
7764
|
+
throw fail("Can only store references to tree nodes or identifiers, got: '" + value + "'");
|
|
7753
7765
|
}
|
|
7754
7766
|
}
|
|
7755
7767
|
Object.defineProperty(StoredReference.prototype, "updateResolvedReference", {
|
|
@@ -8131,7 +8143,7 @@ function reference(subType, options) {
|
|
|
8131
8143
|
if (devMode()) {
|
|
8132
8144
|
if (arguments.length === 2 && typeof arguments[1] === "string") {
|
|
8133
8145
|
// istanbul ignore next
|
|
8134
|
-
throw fail
|
|
8146
|
+
throw fail("References with base path are no longer supported. Please remove the base path.");
|
|
8135
8147
|
}
|
|
8136
8148
|
}
|
|
8137
8149
|
var getSetOptions = options ? options : undefined;
|
|
@@ -8141,7 +8153,7 @@ function reference(subType, options) {
|
|
|
8141
8153
|
if (getSetOptions && (getSetOptions.get || getSetOptions.set)) {
|
|
8142
8154
|
if (devMode()) {
|
|
8143
8155
|
if (!getSetOptions.get || !getSetOptions.set) {
|
|
8144
|
-
throw fail
|
|
8156
|
+
throw fail("reference options must either contain both a 'get' and a 'set' method or none of them");
|
|
8145
8157
|
}
|
|
8146
8158
|
}
|
|
8147
8159
|
return new CustomReferenceType(subType, {
|
|
@@ -8219,7 +8231,7 @@ var BaseIdentifierType = /** @class */ (function (_super) {
|
|
|
8219
8231
|
writable: true,
|
|
8220
8232
|
value: function (parent, subpath, environment, initialValue) {
|
|
8221
8233
|
if (!parent || !(parent.type instanceof ModelType))
|
|
8222
|
-
throw fail
|
|
8234
|
+
throw fail("Identifier types can only be instantiated as direct child of a model type");
|
|
8223
8235
|
return createScalarNode(this, parent, subpath, environment, initialValue);
|
|
8224
8236
|
}
|
|
8225
8237
|
});
|
|
@@ -8230,7 +8242,7 @@ var BaseIdentifierType = /** @class */ (function (_super) {
|
|
|
8230
8242
|
value: function (current, newValue, parent, subpath) {
|
|
8231
8243
|
// we don't consider detaching here since identifier are scalar nodes, and scalar nodes cannot be detached
|
|
8232
8244
|
if (current.storedValue !== newValue)
|
|
8233
|
-
throw fail
|
|
8245
|
+
throw fail("Tried to change identifier from '" + current.storedValue + "' to '" + newValue + "'. Changing identifiers is not allowed.");
|
|
8234
8246
|
current.setParent(parent, subpath);
|
|
8235
8247
|
return current;
|
|
8236
8248
|
}
|