@jbrowse/mobx-state-tree 5.4.7 → 5.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/core/type/type-checker.d.ts +9 -0
- package/dist/core/type/type-checker.js.map +1 -1
- package/dist/core/type/type.js.map +1 -1
- package/dist/internal.d.ts +1 -0
- package/dist/internal.js.map +1 -1
- package/dist/mobx-state-tree.js +311 -11
- package/dist/mobx-state-tree.module.js +311 -11
- package/dist/mobx-state-tree.umd.js +311 -11
- package/dist/types/complex-types/array.js.map +1 -1
- package/dist/types/complex-types/map.js.map +1 -1
- package/dist/types/complex-types/model.d.ts +1 -1
- package/dist/types/complex-types/model.js.map +1 -1
- package/dist/types/index.d.ts +2 -1
- package/dist/types/index.js.map +1 -1
- package/dist/types/utility-types/resilient.d.ts +18 -0
- package/dist/types/utility-types/resilient.js.map +1 -0
- package/dist/types/utility-types/union.d.ts +3 -0
- package/dist/types/utility-types/union.js.map +1 -1
- package/dist/utils.js.map +1 -1
- package/package.json +14 -11
|
@@ -27,8 +27,17 @@ export declare function prettyPrintValue(value: any): string;
|
|
|
27
27
|
/**
|
|
28
28
|
* @internal
|
|
29
29
|
* @hidden
|
|
30
|
+
* Pushes a new entry onto the context array (mutates in place for performance).
|
|
31
|
+
* Returns the same context array for chaining.
|
|
30
32
|
*/
|
|
31
33
|
export declare function getContextForPath(context: IValidationContext, path: string, type: IAnyType): IValidationContext;
|
|
34
|
+
/**
|
|
35
|
+
* @internal
|
|
36
|
+
* @hidden
|
|
37
|
+
* Pops the last entry from the context array (mutates in place).
|
|
38
|
+
* Must be called after validation to restore context state.
|
|
39
|
+
*/
|
|
40
|
+
export declare function popContext(context: IValidationContext): void;
|
|
32
41
|
/**
|
|
33
42
|
* @internal
|
|
34
43
|
* @hidden
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"type-checker.js","sourceRoot":"","sources":["../../../src/core/type/type-checker.ts"],"names":[],"mappings":"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D,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACtB,MAAM,IAAI,CAAC,wBAAwB,CAAC,IAAI,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC,CAAA;IAC3D,CAAC;AACH,CAAC;AAED,SAAS,wBAAwB,CAC/B,IAAQ,EACR,KAA4B,EAC5B,MAA0B;IAE1B,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACxB,OAAO,SAAS,CAAA;IAClB,CAAC;IAED,OAAO,CACL,0BAA0B,iBAAiB,CAAC,gBAAgB,CAAC,KAAK,CAAC,CAAC,SAClE,IAAI,CAAC,IACP,aAAa,GAAG,MAAM,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CACzD,CAAA;AACH,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"type.js","sourceRoot":"","sources":["../../../src/core/type/type.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAE7B,OAAO,EAEL,SAAS,EACT,IAAI,EACJ,gBAAgB,EAChB,oBAAoB,EACpB,OAAO,EACP,SAAS,EACT,eAAe,EACf,mBAAmB,EACnB,gBAAgB,EAChB,gBAAgB,EAChB,iBAAiB,EAClB,MAAM,mBAAmB,CAAA;
|
|
1
|
+
{"version":3,"file":"type.js","sourceRoot":"","sources":["../../../src/core/type/type.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAE7B,OAAO,EAEL,SAAS,EACT,IAAI,EACJ,gBAAgB,EAChB,oBAAoB,EACpB,OAAO,EACP,SAAS,EACT,eAAe,EACf,mBAAmB,EACnB,gBAAgB,EAChB,gBAAgB,EAChB,iBAAiB,EAClB,MAAM,mBAAmB,CAAA;AAE1B,4FAA4F;AAC5F,0DAA0D;AAC1D,MAAM,eAAe,GAAG,IAAI,OAAO,EAGhC,CAAA;AAeH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,GAAG,CAAA;IACZ,CAAC;IAED,WAAW;QACT,OAAO,IAAI,CAAA;IACb,CAAC;CACF;AAED;;;;;GAKG;AACH,MAAM,UAAU,MAAM,CAAC,KAAU;IAC/B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,IAAI,KAAK,CAAC,MAAM,KAAK,IAAI,CAAA;AACpE,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,YAAY,CAAC,IAAc,EAAE,SAA4B;IACvE,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,sBAAsB,EAAE,SAAS,CAAC,CAAA;AAC5D,CAAC"}
|
package/dist/internal.d.ts
CHANGED
|
@@ -35,4 +35,5 @@ export * from "./types/utility-types/frozen.ts";
|
|
|
35
35
|
export * from "./types/utility-types/reference.ts";
|
|
36
36
|
export * from "./types/utility-types/identifier.ts";
|
|
37
37
|
export * from "./types/utility-types/custom.ts";
|
|
38
|
+
export * from "./types/utility-types/resilient.ts";
|
|
38
39
|
export * from "./types/index.ts";
|
package/dist/internal.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"internal.js","sourceRoot":"","sources":["../src/internal.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,cAAc,mCAAmC,CAAA;AACjD,cAAc,qBAAqB,CAAA;AACnC,cAAc,0BAA0B,CAAA;AACxC,cAAc,yBAAyB,CAAA;AACvC,cAAc,4BAA4B,CAAA;AAC1C,cAAc,4BAA4B,CAAA;AAC1C,cAAc,qBAAqB,CAAA;AACnC,cAAc,oDAAoD,CAAA;AAClE,cAAc,kDAAkD,CAAA;AAChE,cAAc,4BAA4B,CAAA;AAC1C,cAAc,kBAAkB,CAAA;AAChC,cAAc,yBAAyB,CAAA;AACvC,cAAc,6BAA6B,CAAA;AAC3C,cAAc,iCAAiC,CAAA;AAC/C,cAAc,4BAA4B,CAAA;AAC1C,cAAc,2BAA2B,CAAA;AACzC,cAAc,mBAAmB,CAAA;AACjC,cAAc,gBAAgB,C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cAAc,gCAAgC,CAAA;AAC9C,cAAc,gCAAgC,CAAA;AAC9C,cAAc,uBAAuB,CAAA;AACrC,cAAc,kCAAkC,CAAA;AAChD,cAAc,qCAAqC,CAAA;AACnD,cAAc,sCAAsC,CAAA;AACpD,cAAc,gCAAgC,CAAA;AAC9C,cAAc,mCAAmC,CAAA;AACjD,cAAc,gCAAgC,CAAA;AAC9C,cAAc,+BAA+B,CAAA;AAC7C,cAAc,+BAA+B,CAAA;AAC7C,cAAc,iCAAiC,CAAA;AAC/C,cAAc,oCAAoC,CAAA;AAClD,cAAc,qCAAqC,CAAA;AACnD,cAAc,iCAAiC,CAAA;AAC/C,cAAc,oCAAoC,CAAA;AAClD,cAAc,kBAAkB,CAAA"}
|
package/dist/mobx-state-tree.js
CHANGED
|
@@ -1656,6 +1656,9 @@ ObjectNode.prototype.createObservableInstance = mobx.action(ObjectNode.prototype
|
|
|
1656
1656
|
ObjectNode.prototype.detach = mobx.action(ObjectNode.prototype.detach);
|
|
1657
1657
|
ObjectNode.prototype.die = mobx.action(ObjectNode.prototype.die);
|
|
1658
1658
|
|
|
1659
|
+
// Cache for validation results to avoid re-validating the same object against the same type
|
|
1660
|
+
// Uses WeakMap so cached objects can be garbage collected
|
|
1661
|
+
const validationCache = new WeakMap();
|
|
1659
1662
|
/**
|
|
1660
1663
|
* @internal
|
|
1661
1664
|
* @hidden
|
|
@@ -1731,7 +1734,27 @@ class BaseType {
|
|
|
1731
1734
|
: typeCheckFailure(context, value);
|
|
1732
1735
|
// it is tempting to compare snapshots, but in that case we should always clone on assignments...
|
|
1733
1736
|
}
|
|
1734
|
-
|
|
1737
|
+
// check cache for object values (only at root level to avoid context mismatches)
|
|
1738
|
+
if (typeof value === "object" && value !== null && context.length === 1) {
|
|
1739
|
+
const typeCache = validationCache.get(value);
|
|
1740
|
+
if (typeCache) {
|
|
1741
|
+
const cached = typeCache.get(this);
|
|
1742
|
+
if (cached !== undefined) {
|
|
1743
|
+
return cached;
|
|
1744
|
+
}
|
|
1745
|
+
}
|
|
1746
|
+
}
|
|
1747
|
+
const result = this.isValidSnapshot(value, context);
|
|
1748
|
+
// cache result for object values (only at root level)
|
|
1749
|
+
if (typeof value === "object" && value !== null && context.length === 1) {
|
|
1750
|
+
let typeCache = validationCache.get(value);
|
|
1751
|
+
if (!typeCache) {
|
|
1752
|
+
typeCache = new WeakMap();
|
|
1753
|
+
validationCache.set(value, typeCache);
|
|
1754
|
+
}
|
|
1755
|
+
typeCache.set(this, result);
|
|
1756
|
+
}
|
|
1757
|
+
return result;
|
|
1735
1758
|
}
|
|
1736
1759
|
is(thing) {
|
|
1737
1760
|
return this.validate(thing, [{ path: "", type: this }]).length === 0;
|
|
@@ -2596,9 +2619,21 @@ function toErrorString(error) {
|
|
|
2596
2619
|
/**
|
|
2597
2620
|
* @internal
|
|
2598
2621
|
* @hidden
|
|
2622
|
+
* Pushes a new entry onto the context array (mutates in place for performance).
|
|
2623
|
+
* Returns the same context array for chaining.
|
|
2599
2624
|
*/
|
|
2600
2625
|
function getContextForPath(context, path, type) {
|
|
2601
|
-
|
|
2626
|
+
context.push({ path, type });
|
|
2627
|
+
return context;
|
|
2628
|
+
}
|
|
2629
|
+
/**
|
|
2630
|
+
* @internal
|
|
2631
|
+
* @hidden
|
|
2632
|
+
* Pops the last entry from the context array (mutates in place).
|
|
2633
|
+
* Must be called after validation to restore context state.
|
|
2634
|
+
*/
|
|
2635
|
+
function popContext(context) {
|
|
2636
|
+
context.pop();
|
|
2602
2637
|
}
|
|
2603
2638
|
/**
|
|
2604
2639
|
* @internal
|
|
@@ -2612,14 +2647,15 @@ function typeCheckSuccess() {
|
|
|
2612
2647
|
* @hidden
|
|
2613
2648
|
*/
|
|
2614
2649
|
function typeCheckFailure(context, value, message) {
|
|
2615
|
-
|
|
2650
|
+
// Clone context since it may be mutated after this error is created
|
|
2651
|
+
return [{ context: context.slice(), value, message }];
|
|
2616
2652
|
}
|
|
2617
2653
|
/**
|
|
2618
2654
|
* @internal
|
|
2619
2655
|
* @hidden
|
|
2620
2656
|
*/
|
|
2621
2657
|
function flattenTypeErrors(errors) {
|
|
2622
|
-
return errors.
|
|
2658
|
+
return errors.flat();
|
|
2623
2659
|
}
|
|
2624
2660
|
// TODO; doublecheck: typecheck should only needed to be invoked from: type.create and array / map / value.property will change
|
|
2625
2661
|
/**
|
|
@@ -3174,6 +3210,8 @@ function addHiddenWritableProp(object, propName, value) {
|
|
|
3174
3210
|
*/
|
|
3175
3211
|
class EventHandler {
|
|
3176
3212
|
handlers = [];
|
|
3213
|
+
emitting = false;
|
|
3214
|
+
pendingUnregisters = null;
|
|
3177
3215
|
get hasSubscribers() {
|
|
3178
3216
|
return this.handlers.length > 0;
|
|
3179
3217
|
}
|
|
@@ -3192,6 +3230,14 @@ class EventHandler {
|
|
|
3192
3230
|
return this.handlers.indexOf(fn) >= 0;
|
|
3193
3231
|
}
|
|
3194
3232
|
unregister(fn) {
|
|
3233
|
+
if (this.emitting) {
|
|
3234
|
+
// defer unregistration until emit is done
|
|
3235
|
+
if (!this.pendingUnregisters) {
|
|
3236
|
+
this.pendingUnregisters = [];
|
|
3237
|
+
}
|
|
3238
|
+
this.pendingUnregisters.push(fn);
|
|
3239
|
+
return;
|
|
3240
|
+
}
|
|
3195
3241
|
const index = this.handlers.indexOf(fn);
|
|
3196
3242
|
if (index >= 0) {
|
|
3197
3243
|
this.handlers.splice(index, 1);
|
|
@@ -3201,9 +3247,26 @@ class EventHandler {
|
|
|
3201
3247
|
this.handlers.length = 0;
|
|
3202
3248
|
}
|
|
3203
3249
|
emit(...args) {
|
|
3204
|
-
//
|
|
3205
|
-
|
|
3206
|
-
|
|
3250
|
+
// use emitting flag to defer unregistrations instead of copying array
|
|
3251
|
+
this.emitting = true;
|
|
3252
|
+
try {
|
|
3253
|
+
for (const f of this.handlers) {
|
|
3254
|
+
f(...args);
|
|
3255
|
+
}
|
|
3256
|
+
}
|
|
3257
|
+
finally {
|
|
3258
|
+
this.emitting = false;
|
|
3259
|
+
// process any deferred unregistrations
|
|
3260
|
+
if (this.pendingUnregisters) {
|
|
3261
|
+
for (const fn of this.pendingUnregisters) {
|
|
3262
|
+
const index = this.handlers.indexOf(fn);
|
|
3263
|
+
if (index >= 0) {
|
|
3264
|
+
this.handlers.splice(index, 1);
|
|
3265
|
+
}
|
|
3266
|
+
}
|
|
3267
|
+
this.pendingUnregisters = null;
|
|
3268
|
+
}
|
|
3269
|
+
}
|
|
3207
3270
|
}
|
|
3208
3271
|
}
|
|
3209
3272
|
/**
|
|
@@ -4123,7 +4186,15 @@ class MapType extends ComplexType {
|
|
|
4123
4186
|
if (!isPlainObject(value)) {
|
|
4124
4187
|
return typeCheckFailure(context, value, "Value is not a plain object");
|
|
4125
4188
|
}
|
|
4126
|
-
|
|
4189
|
+
for (const key of Object.keys(value)) {
|
|
4190
|
+
getContextForPath(context, key, this._subType);
|
|
4191
|
+
const errors = this._subType.validate(value[key], context);
|
|
4192
|
+
popContext(context);
|
|
4193
|
+
if (errors.length > 0) {
|
|
4194
|
+
return errors;
|
|
4195
|
+
}
|
|
4196
|
+
}
|
|
4197
|
+
return typeCheckSuccess();
|
|
4127
4198
|
}
|
|
4128
4199
|
getDefaultSnapshot() {
|
|
4129
4200
|
return EMPTY_OBJECT;
|
|
@@ -4336,7 +4407,15 @@ class ArrayType extends ComplexType {
|
|
|
4336
4407
|
if (!isArray(value)) {
|
|
4337
4408
|
return typeCheckFailure(context, value, "Value is not an array");
|
|
4338
4409
|
}
|
|
4339
|
-
|
|
4410
|
+
for (let i = 0; i < value.length; i++) {
|
|
4411
|
+
getContextForPath(context, "" + i, this._subType);
|
|
4412
|
+
const errors = this._subType.validate(value[i], context);
|
|
4413
|
+
popContext(context);
|
|
4414
|
+
if (errors.length > 0) {
|
|
4415
|
+
return errors;
|
|
4416
|
+
}
|
|
4417
|
+
}
|
|
4418
|
+
return typeCheckSuccess();
|
|
4340
4419
|
}
|
|
4341
4420
|
getDefaultSnapshot() {
|
|
4342
4421
|
return EMPTY_ARRAY;
|
|
@@ -4886,7 +4965,16 @@ class ModelType extends ComplexType {
|
|
|
4886
4965
|
if (!isPlainObject(snapshot)) {
|
|
4887
4966
|
return typeCheckFailure(context, snapshot, "Value is not a plain object");
|
|
4888
4967
|
}
|
|
4889
|
-
|
|
4968
|
+
for (const key of this.propertyNames) {
|
|
4969
|
+
const propType = this.properties[key];
|
|
4970
|
+
getContextForPath(context, key, propType);
|
|
4971
|
+
const errors = propType.validate(snapshot[key], context);
|
|
4972
|
+
popContext(context);
|
|
4973
|
+
if (errors.length > 0) {
|
|
4974
|
+
return errors;
|
|
4975
|
+
}
|
|
4976
|
+
}
|
|
4977
|
+
return typeCheckSuccess();
|
|
4890
4978
|
}
|
|
4891
4979
|
forAllProps(fn) {
|
|
4892
4980
|
this.propertyNames.forEach(key => fn(key, this.properties[key]));
|
|
@@ -5352,6 +5440,23 @@ class Union extends BaseType {
|
|
|
5352
5440
|
if (this._dispatcher) {
|
|
5353
5441
|
return this._dispatcher(value);
|
|
5354
5442
|
}
|
|
5443
|
+
// fast path: when type checking is disabled, try quick structural matching first
|
|
5444
|
+
if (!isTypeCheckingEnabled()) {
|
|
5445
|
+
const quickMatch = this.tryQuickMatch(value, reconcileCurrentType);
|
|
5446
|
+
if (quickMatch) {
|
|
5447
|
+
return quickMatch;
|
|
5448
|
+
}
|
|
5449
|
+
// for plain object snapshots that didn't match via quick path, try all types
|
|
5450
|
+
// with quick matching before falling back to full validation
|
|
5451
|
+
// (state tree nodes must go through full validation for type identity checks)
|
|
5452
|
+
if (isPlainObject(value) && !isStateTreeNode(value)) {
|
|
5453
|
+
for (const type of this._types) {
|
|
5454
|
+
if (this.snapshotLooksLikeType(value, type)) {
|
|
5455
|
+
return type;
|
|
5456
|
+
}
|
|
5457
|
+
}
|
|
5458
|
+
}
|
|
5459
|
+
}
|
|
5355
5460
|
// find the most accomodating type
|
|
5356
5461
|
// if we are using reconciliation try the current node type first (fix for #1045)
|
|
5357
5462
|
if (reconcileCurrentType) {
|
|
@@ -5366,6 +5471,84 @@ class Union extends BaseType {
|
|
|
5366
5471
|
return this._types.find(type => type.is(value));
|
|
5367
5472
|
}
|
|
5368
5473
|
}
|
|
5474
|
+
tryQuickMatch(value, reconcileCurrentType) {
|
|
5475
|
+
// state tree nodes need full type compatibility checking
|
|
5476
|
+
// (e.g., A.is(B.create()) must return false even if snapshots are compatible)
|
|
5477
|
+
if (isStateTreeNode(value)) {
|
|
5478
|
+
return undefined;
|
|
5479
|
+
}
|
|
5480
|
+
// for non-object values, try primitive matching
|
|
5481
|
+
if (!isPlainObject(value)) {
|
|
5482
|
+
return this.tryMatchPrimitive(value);
|
|
5483
|
+
}
|
|
5484
|
+
// for objects, try structural matching against model types
|
|
5485
|
+
const typesToCheck = reconcileCurrentType
|
|
5486
|
+
? [
|
|
5487
|
+
reconcileCurrentType,
|
|
5488
|
+
...this._types.filter(t => t !== reconcileCurrentType)
|
|
5489
|
+
]
|
|
5490
|
+
: this._types;
|
|
5491
|
+
for (const type of typesToCheck) {
|
|
5492
|
+
if (this.snapshotLooksLikeType(value, type)) {
|
|
5493
|
+
return type;
|
|
5494
|
+
}
|
|
5495
|
+
}
|
|
5496
|
+
return undefined;
|
|
5497
|
+
}
|
|
5498
|
+
tryMatchPrimitive(value) {
|
|
5499
|
+
const valueType = typeof value;
|
|
5500
|
+
for (const type of this._types) {
|
|
5501
|
+
const flags = type.flags;
|
|
5502
|
+
if ((valueType === "string" && flags & TypeFlags.String) ||
|
|
5503
|
+
(valueType === "number" &&
|
|
5504
|
+
flags &
|
|
5505
|
+
(TypeFlags.Number |
|
|
5506
|
+
TypeFlags.Integer |
|
|
5507
|
+
TypeFlags.Float |
|
|
5508
|
+
TypeFlags.Finite)) ||
|
|
5509
|
+
(valueType === "boolean" && flags & TypeFlags.Boolean) ||
|
|
5510
|
+
(value === null && flags & TypeFlags.Null) ||
|
|
5511
|
+
(value === undefined && flags & TypeFlags.Undefined)) {
|
|
5512
|
+
return type;
|
|
5513
|
+
}
|
|
5514
|
+
// for literals, check exact value match
|
|
5515
|
+
if (flags & TypeFlags.Literal) {
|
|
5516
|
+
if (type.is(value)) {
|
|
5517
|
+
return type;
|
|
5518
|
+
}
|
|
5519
|
+
}
|
|
5520
|
+
}
|
|
5521
|
+
return undefined;
|
|
5522
|
+
}
|
|
5523
|
+
snapshotLooksLikeType(value, type) {
|
|
5524
|
+
// for model types, check if snapshot has all the required property keys
|
|
5525
|
+
// and that any literal-typed properties match exactly
|
|
5526
|
+
if (type instanceof ModelType) {
|
|
5527
|
+
const props = type.properties;
|
|
5528
|
+
// use cached propertyNames from ModelType instead of Object.keys()
|
|
5529
|
+
for (const key of type.propertyNames) {
|
|
5530
|
+
const propType = props[key];
|
|
5531
|
+
const isOptional = propType.flags & TypeFlags.Optional;
|
|
5532
|
+
const propValue = value[key];
|
|
5533
|
+
// check required properties exist and are not undefined
|
|
5534
|
+
// (unless the type accepts undefined, which Optional types do)
|
|
5535
|
+
if (!isOptional) {
|
|
5536
|
+
if (!(key in value) || propValue === undefined) {
|
|
5537
|
+
return false;
|
|
5538
|
+
}
|
|
5539
|
+
}
|
|
5540
|
+
// for literal types, verify the value matches exactly
|
|
5541
|
+
// this is critical for discriminated unions
|
|
5542
|
+
if (propType.flags & TypeFlags.Literal) {
|
|
5543
|
+
if (!propType.is(propValue)) {
|
|
5544
|
+
return false;
|
|
5545
|
+
}
|
|
5546
|
+
}
|
|
5547
|
+
}
|
|
5548
|
+
return true;
|
|
5549
|
+
}
|
|
5550
|
+
return false;
|
|
5551
|
+
}
|
|
5369
5552
|
isValidSnapshot(value, context) {
|
|
5370
5553
|
if (this._dispatcher) {
|
|
5371
5554
|
return this._dispatcher(value).validate(value, context);
|
|
@@ -6455,6 +6638,122 @@ class CustomType extends SimpleType {
|
|
|
6455
6638
|
}
|
|
6456
6639
|
}
|
|
6457
6640
|
|
|
6641
|
+
class Resilient extends BaseType {
|
|
6642
|
+
_subtype;
|
|
6643
|
+
_fallbackType;
|
|
6644
|
+
_createFallbackSnapshot;
|
|
6645
|
+
get flags() {
|
|
6646
|
+
return this._subtype.flags;
|
|
6647
|
+
}
|
|
6648
|
+
constructor(_subtype, _fallbackType, _createFallbackSnapshot) {
|
|
6649
|
+
super(`resilient(${_subtype.name})`);
|
|
6650
|
+
this._subtype = _subtype;
|
|
6651
|
+
this._fallbackType = _fallbackType;
|
|
6652
|
+
this._createFallbackSnapshot = _createFallbackSnapshot;
|
|
6653
|
+
}
|
|
6654
|
+
describe() {
|
|
6655
|
+
return `resilient(${this._subtype.describe()})`;
|
|
6656
|
+
}
|
|
6657
|
+
_instantiateFallback(parent, subpath, environment, originalSnapshot, originalError) {
|
|
6658
|
+
let fallbackSnapshot;
|
|
6659
|
+
try {
|
|
6660
|
+
fallbackSnapshot = this._createFallbackSnapshot(originalError, originalSnapshot);
|
|
6661
|
+
}
|
|
6662
|
+
catch (e) {
|
|
6663
|
+
throw fail(`resilient: createFallbackSnapshot threw while handling error for '${this._subtype.name}': ${originalError}. createFallbackSnapshot error: ${e}`);
|
|
6664
|
+
}
|
|
6665
|
+
try {
|
|
6666
|
+
return this._fallbackType.instantiate(parent, subpath, environment, fallbackSnapshot);
|
|
6667
|
+
}
|
|
6668
|
+
catch (e) {
|
|
6669
|
+
throw fail(`resilient: fallback type '${this._fallbackType.name}' failed to instantiate while handling error for '${this._subtype.name}': ${originalError}. Fallback error: ${e}`);
|
|
6670
|
+
}
|
|
6671
|
+
}
|
|
6672
|
+
instantiate(parent, subpath, environment, initialValue) {
|
|
6673
|
+
if (isStateTreeNode(initialValue)) {
|
|
6674
|
+
return this._subtype.instantiate(parent, subpath, environment, initialValue);
|
|
6675
|
+
}
|
|
6676
|
+
try {
|
|
6677
|
+
return this._subtype.instantiate(parent, subpath, environment, initialValue);
|
|
6678
|
+
}
|
|
6679
|
+
catch (e) {
|
|
6680
|
+
return this._instantiateFallback(parent, subpath, environment, initialValue, e);
|
|
6681
|
+
}
|
|
6682
|
+
}
|
|
6683
|
+
reconcile(current, newValue, parent, subpath) {
|
|
6684
|
+
if (isStateTreeNode(newValue)) {
|
|
6685
|
+
return this._subtype.reconcile(current, newValue, parent, subpath);
|
|
6686
|
+
}
|
|
6687
|
+
if (this._fallbackType.isAssignableFrom(current.type)) {
|
|
6688
|
+
try {
|
|
6689
|
+
return this._subtype.instantiate(parent, subpath, undefined, newValue);
|
|
6690
|
+
}
|
|
6691
|
+
catch (e) {
|
|
6692
|
+
return this._fallbackType.reconcile(current, this._createFallbackSnapshot(e, newValue), parent, subpath);
|
|
6693
|
+
}
|
|
6694
|
+
}
|
|
6695
|
+
try {
|
|
6696
|
+
return this._subtype.reconcile(current, newValue, parent, subpath);
|
|
6697
|
+
}
|
|
6698
|
+
catch (e) {
|
|
6699
|
+
current.die();
|
|
6700
|
+
return this._instantiateFallback(parent, subpath, undefined, newValue, e);
|
|
6701
|
+
}
|
|
6702
|
+
}
|
|
6703
|
+
isValidSnapshot(_value, _context) {
|
|
6704
|
+
return typeCheckSuccess();
|
|
6705
|
+
}
|
|
6706
|
+
is(thing) {
|
|
6707
|
+
if (isType(thing)) {
|
|
6708
|
+
return (this._subtype.isAssignableFrom(thing) ||
|
|
6709
|
+
this._fallbackType.isAssignableFrom(thing));
|
|
6710
|
+
}
|
|
6711
|
+
try {
|
|
6712
|
+
if (this._subtype.is(thing)) {
|
|
6713
|
+
return true;
|
|
6714
|
+
}
|
|
6715
|
+
}
|
|
6716
|
+
catch (_e) {
|
|
6717
|
+
// subtype.is() may throw (e.g. union dispatcher)
|
|
6718
|
+
}
|
|
6719
|
+
try {
|
|
6720
|
+
return this._fallbackType.is(thing);
|
|
6721
|
+
}
|
|
6722
|
+
catch (_e) {
|
|
6723
|
+
return false;
|
|
6724
|
+
}
|
|
6725
|
+
}
|
|
6726
|
+
isAssignableFrom(type) {
|
|
6727
|
+
return (this._subtype.isAssignableFrom(type) ||
|
|
6728
|
+
this._fallbackType.isAssignableFrom(type));
|
|
6729
|
+
}
|
|
6730
|
+
getSubTypes() {
|
|
6731
|
+
return [this._subtype, this._fallbackType];
|
|
6732
|
+
}
|
|
6733
|
+
getSnapshot(node) {
|
|
6734
|
+
return node.snapshot;
|
|
6735
|
+
}
|
|
6736
|
+
}
|
|
6737
|
+
/**
|
|
6738
|
+
* `types.resilient` - Wraps a type so that instantiation errors are caught
|
|
6739
|
+
* and a fallback type is used instead. This is useful for loading data that
|
|
6740
|
+
* may contain unknown or invalid subtrees (e.g., plugin types that are not
|
|
6741
|
+
* installed) without crashing the entire state tree.
|
|
6742
|
+
*
|
|
6743
|
+
* The `createFallbackSnapshot` callback receives the caught error and the
|
|
6744
|
+
* original snapshot, and must return a valid snapshot for the fallback type.
|
|
6745
|
+
*
|
|
6746
|
+
* @param type The type to wrap.
|
|
6747
|
+
* @param fallbackType The fallback type to use when instantiation fails.
|
|
6748
|
+
* @param createFallbackSnapshot Callback that produces a fallback snapshot from the error and original snapshot.
|
|
6749
|
+
* @returns A resilient type.
|
|
6750
|
+
*/
|
|
6751
|
+
function resilient(type, fallbackType, createFallbackSnapshot) {
|
|
6752
|
+
assertIsType(type, 1);
|
|
6753
|
+
assertIsType(fallbackType, 2);
|
|
6754
|
+
return new Resilient(type, fallbackType, createFallbackSnapshot);
|
|
6755
|
+
}
|
|
6756
|
+
|
|
6458
6757
|
// we import the types to re-export them inside types.
|
|
6459
6758
|
const types = {
|
|
6460
6759
|
enumeration,
|
|
@@ -6485,7 +6784,8 @@ const types = {
|
|
|
6485
6784
|
lazy,
|
|
6486
6785
|
undefined: undefinedType,
|
|
6487
6786
|
null: nullType,
|
|
6488
|
-
snapshotProcessor
|
|
6787
|
+
snapshotProcessor,
|
|
6788
|
+
resilient
|
|
6489
6789
|
};
|
|
6490
6790
|
|
|
6491
6791
|
exports.addDisposer = addDisposer;
|