@jbrowse/mobx-state-tree 5.6.9 → 5.7.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/action.js.map +1 -1
- package/dist/core/actionContext.js.map +1 -1
- package/dist/core/flow.js.map +1 -1
- package/dist/core/json-patch.js.map +1 -1
- package/dist/core/mst-operations.js.map +1 -1
- package/dist/core/node/BaseNode.js.map +1 -1
- package/dist/core/node/Hook.js.map +1 -1
- package/dist/core/node/create-node.js.map +1 -1
- package/dist/core/node/identifier-cache.js.map +1 -1
- package/dist/core/node/livelinessChecking.js.map +1 -1
- package/dist/core/node/node-utils.js.map +1 -1
- package/dist/core/node/object-node.d.ts +3 -1
- package/dist/core/node/object-node.js +2 -1
- package/dist/core/node/object-node.js.map +1 -1
- package/dist/core/node/scalar-node.d.ts +3 -1
- package/dist/core/node/scalar-node.js +2 -1
- package/dist/core/node/scalar-node.js.map +1 -1
- package/dist/core/process.js.map +1 -1
- package/dist/core/type/type-checker.js.map +1 -1
- package/dist/core/type/type.js.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/internal.js.map +1 -1
- package/dist/middlewares/create-action-tracking-middleware.js.map +1 -1
- package/dist/middlewares/createActionTrackingMiddleware2.js.map +1 -1
- package/dist/middlewares/on-action.js.map +1 -1
- package/dist/package.json +1 -0
- package/dist/types/complex-types/array.d.ts +2 -1
- package/dist/types/complex-types/array.js +2 -1
- package/dist/types/complex-types/array.js.map +1 -1
- package/dist/types/complex-types/map.d.ts +2 -1
- package/dist/types/complex-types/map.js +2 -1
- package/dist/types/complex-types/map.js.map +1 -1
- package/dist/types/complex-types/model.d.ts +2 -1
- package/dist/types/complex-types/model.js +2 -1
- package/dist/types/complex-types/model.js.map +1 -1
- package/dist/types/index.js.map +1 -1
- package/dist/types/primitives.d.ts +2 -1
- package/dist/types/primitives.js +2 -1
- package/dist/types/primitives.js.map +1 -1
- package/dist/types/utility-types/custom.d.ts +2 -1
- package/dist/types/utility-types/custom.js +2 -1
- package/dist/types/utility-types/custom.js.map +1 -1
- package/dist/types/utility-types/enumeration.js.map +1 -1
- package/dist/types/utility-types/frozen.d.ts +2 -1
- package/dist/types/utility-types/frozen.js +2 -1
- package/dist/types/utility-types/frozen.js.map +1 -1
- package/dist/types/utility-types/identifier.d.ts +2 -1
- package/dist/types/utility-types/identifier.js +2 -1
- package/dist/types/utility-types/identifier.js.map +1 -1
- package/dist/types/utility-types/late.js +2 -1
- package/dist/types/utility-types/late.js.map +1 -1
- package/dist/types/utility-types/lazy.d.ts +2 -1
- package/dist/types/utility-types/lazy.js +2 -1
- package/dist/types/utility-types/lazy.js.map +1 -1
- package/dist/types/utility-types/literal.d.ts +2 -1
- package/dist/types/utility-types/literal.js +2 -1
- package/dist/types/utility-types/literal.js.map +1 -1
- package/dist/types/utility-types/maybe.js.map +1 -1
- package/dist/types/utility-types/optional.d.ts +2 -1
- package/dist/types/utility-types/optional.js +2 -1
- package/dist/types/utility-types/optional.js.map +1 -1
- package/dist/types/utility-types/reference.d.ts +2 -1
- package/dist/types/utility-types/reference.js +2 -1
- package/dist/types/utility-types/reference.js.map +1 -1
- package/dist/types/utility-types/refinement.js +2 -1
- package/dist/types/utility-types/refinement.js.map +1 -1
- package/dist/types/utility-types/resilient.js +2 -1
- package/dist/types/utility-types/resilient.js.map +1 -1
- package/dist/types/utility-types/snapshotProcessor.js +3 -2
- package/dist/types/utility-types/snapshotProcessor.js.map +1 -1
- package/dist/types/utility-types/union.d.ts +2 -1
- package/dist/types/utility-types/union.js +2 -1
- package/dist/types/utility-types/union.js.map +1 -1
- package/dist/utils.js.map +1 -1
- package/esm/core/action.d.ts +87 -0
- package/esm/core/action.js +219 -0
- package/esm/core/action.js.map +1 -0
- package/esm/core/actionContext.d.ts +27 -0
- package/esm/core/actionContext.js +37 -0
- package/esm/core/actionContext.js.map +1 -0
- package/esm/core/flow.d.ts +69 -0
- package/esm/core/flow.js +173 -0
- package/esm/core/flow.js.map +1 -0
- package/esm/core/json-patch.d.ts +46 -0
- package/esm/core/json-patch.js +125 -0
- package/esm/core/json-patch.js.map +1 -0
- package/esm/core/mst-operations.d.ts +459 -0
- package/esm/core/mst-operations.js +844 -0
- package/esm/core/mst-operations.js.map +1 -0
- package/esm/core/node/BaseNode.d.ts +62 -0
- package/esm/core/node/BaseNode.js +148 -0
- package/esm/core/node/BaseNode.js.map +1 -0
- package/esm/core/node/Hook.d.ts +17 -0
- package/esm/core/node/Hook.js +12 -0
- package/esm/core/node/Hook.js.map +1 -0
- package/esm/core/node/create-node.d.ts +16 -0
- package/esm/core/node/create-node.js +36 -0
- package/esm/core/node/create-node.js.map +1 -0
- package/esm/core/node/identifier-cache.d.ts +19 -0
- package/esm/core/node/identifier-cache.js +111 -0
- package/esm/core/node/identifier-cache.js.map +1 -0
- package/esm/core/node/livelinessChecking.d.ts +37 -0
- package/esm/core/node/livelinessChecking.js +33 -0
- package/esm/core/node/livelinessChecking.js.map +1 -0
- package/esm/core/node/node-utils.d.ts +83 -0
- package/esm/core/node/node-utils.js +153 -0
- package/esm/core/node/node-utils.js.map +1 -0
- package/esm/core/node/object-node.d.ts +101 -0
- package/esm/core/node/object-node.js +542 -0
- package/esm/core/node/object-node.js.map +1 -0
- package/esm/core/node/scalar-node.d.ts +21 -0
- package/esm/core/node/scalar-node.js +86 -0
- package/esm/core/node/scalar-node.js.map +1 -0
- package/esm/core/process.d.ts +50 -0
- package/esm/core/process.js +35 -0
- package/esm/core/process.js.map +1 -0
- package/esm/core/type/type-checker.d.ts +69 -0
- package/esm/core/type/type-checker.js +144 -0
- package/esm/core/type/type-checker.js.map +1 -0
- package/esm/core/type/type.d.ts +317 -0
- package/esm/core/type/type.js +243 -0
- package/esm/core/type/type.js.map +1 -0
- package/esm/index.d.ts +2 -0
- package/esm/index.js +2 -0
- package/esm/index.js.map +1 -0
- package/esm/internal.d.ts +39 -0
- package/esm/internal.js +44 -0
- package/esm/internal.js.map +1 -0
- package/esm/middlewares/create-action-tracking-middleware.d.ts +24 -0
- package/esm/middlewares/create-action-tracking-middleware.js +78 -0
- package/esm/middlewares/create-action-tracking-middleware.js.map +1 -0
- package/esm/middlewares/createActionTrackingMiddleware2.d.ts +34 -0
- package/esm/middlewares/createActionTrackingMiddleware2.js +130 -0
- package/esm/middlewares/createActionTrackingMiddleware2.js.map +1 -0
- package/esm/middlewares/on-action.d.ts +87 -0
- package/esm/middlewares/on-action.js +210 -0
- package/esm/middlewares/on-action.js.map +1 -0
- package/esm/types/complex-types/array.d.ts +81 -0
- package/esm/types/complex-types/array.js +347 -0
- package/esm/types/complex-types/array.js.map +1 -0
- package/esm/types/complex-types/map.d.ts +111 -0
- package/esm/types/complex-types/map.js +356 -0
- package/esm/types/complex-types/map.js.map +1 -0
- package/esm/types/complex-types/model.d.ts +193 -0
- package/esm/types/complex-types/model.js +471 -0
- package/esm/types/complex-types/model.js.map +1 -0
- package/esm/types/index.d.ts +33 -0
- package/esm/types/index.js +35 -0
- package/esm/types/index.js.map +1 -0
- package/esm/types/primitives.d.ts +125 -0
- package/esm/types/primitives.js +177 -0
- package/esm/types/primitives.js.map +1 -0
- package/esm/types/utility-types/custom.d.ts +75 -0
- package/esm/types/utility-types/custom.js +106 -0
- package/esm/types/utility-types/custom.js.map +1 -0
- package/esm/types/utility-types/enumeration.d.ts +5 -0
- package/esm/types/utility-types/enumeration.js +31 -0
- package/esm/types/utility-types/enumeration.js.map +1 -0
- package/esm/types/utility-types/frozen.d.ts +24 -0
- package/esm/types/utility-types/frozen.js +92 -0
- package/esm/types/utility-types/frozen.js.map +1 -0
- package/esm/types/utility-types/identifier.d.ts +87 -0
- package/esm/types/utility-types/identifier.js +121 -0
- package/esm/types/utility-types/identifier.js.map +1 -0
- package/esm/types/utility-types/late.d.ts +10 -0
- package/esm/types/utility-types/late.js +106 -0
- package/esm/types/utility-types/late.js.map +1 -0
- package/esm/types/utility-types/lazy.d.ts +23 -0
- package/esm/types/utility-types/lazy.js +72 -0
- package/esm/types/utility-types/lazy.js.map +1 -0
- package/esm/types/utility-types/literal.d.ts +38 -0
- package/esm/types/utility-types/literal.js +58 -0
- package/esm/types/utility-types/literal.js.map +1 -0
- package/esm/types/utility-types/maybe.d.ts +26 -0
- package/esm/types/utility-types/maybe.js +26 -0
- package/esm/types/utility-types/maybe.js.map +1 -0
- package/esm/types/utility-types/optional.d.ts +42 -0
- package/esm/types/utility-types/optional.js +135 -0
- package/esm/types/utility-types/optional.js.map +1 -0
- package/esm/types/utility-types/reference.d.ts +90 -0
- package/esm/types/utility-types/reference.js +383 -0
- package/esm/types/utility-types/reference.js.map +1 -0
- package/esm/types/utility-types/refinement.d.ts +10 -0
- package/esm/types/utility-types/refinement.js +82 -0
- package/esm/types/utility-types/refinement.js.map +1 -0
- package/esm/types/utility-types/resilient.d.ts +18 -0
- package/esm/types/utility-types/resilient.js +118 -0
- package/esm/types/utility-types/resilient.js.map +1 -0
- package/esm/types/utility-types/snapshotProcessor.d.ts +63 -0
- package/esm/types/utility-types/snapshotProcessor.js +159 -0
- package/esm/types/utility-types/snapshotProcessor.js.map +1 -0
- package/esm/types/utility-types/union.d.ts +78 -0
- package/esm/types/utility-types/union.js +240 -0
- package/esm/types/utility-types/union.js.map +1 -0
- package/esm/utils.d.ts +230 -0
- package/esm/utils.js +449 -0
- package/esm/utils.js.map +1 -0
- package/package.json +23 -22
- package/dist/mobx-state-tree.js +0 -85
- package/dist/mobx-state-tree.module.js +0 -83
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { action } from "mobx";
|
|
2
|
+
import { BaseNode } from "./BaseNode.js";
|
|
3
|
+
import { NodeLifeCycle, devMode, fail, freeze } from "../../internal.js";
|
|
4
|
+
/**
|
|
5
|
+
* @internal
|
|
6
|
+
* @hidden
|
|
7
|
+
*/
|
|
8
|
+
export class ScalarNode extends BaseNode {
|
|
9
|
+
constructor(simpleType, parent, subpath, environment, initialSnapshot) {
|
|
10
|
+
super(simpleType, parent, subpath, environment);
|
|
11
|
+
try {
|
|
12
|
+
this.storedValue = simpleType.createNewInstance(initialSnapshot);
|
|
13
|
+
}
|
|
14
|
+
catch (e) {
|
|
15
|
+
// short-cut to die the instance, to avoid the snapshot computed starting to throw...
|
|
16
|
+
this.state = NodeLifeCycle.DEAD;
|
|
17
|
+
throw e;
|
|
18
|
+
}
|
|
19
|
+
this.state = NodeLifeCycle.CREATED;
|
|
20
|
+
// for scalar nodes there's no point in firing this event since it would fire on the constructor, before
|
|
21
|
+
// anybody can actually register for/listen to it
|
|
22
|
+
// this.fireHook(Hook.AfterCreate)
|
|
23
|
+
this.finalizeCreation();
|
|
24
|
+
}
|
|
25
|
+
get root() {
|
|
26
|
+
// future optimization: store root ref in the node and maintain it
|
|
27
|
+
if (!this.parent) {
|
|
28
|
+
throw fail(`This scalar node is not part of a tree`);
|
|
29
|
+
}
|
|
30
|
+
return this.parent.root;
|
|
31
|
+
}
|
|
32
|
+
setParent(newParent, subpath) {
|
|
33
|
+
const parentChanged = this.parent !== newParent;
|
|
34
|
+
const subpathChanged = this.subpath !== subpath;
|
|
35
|
+
if (!parentChanged && !subpathChanged) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
if (devMode()) {
|
|
39
|
+
if (!subpath) {
|
|
40
|
+
// istanbul ignore next
|
|
41
|
+
throw fail("assertion failed: subpath expected");
|
|
42
|
+
}
|
|
43
|
+
if (!newParent) {
|
|
44
|
+
// istanbul ignore next
|
|
45
|
+
throw fail("assertion failed: parent expected");
|
|
46
|
+
}
|
|
47
|
+
if (parentChanged) {
|
|
48
|
+
// istanbul ignore next
|
|
49
|
+
throw fail("assertion failed: scalar nodes cannot change their parent");
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
this.environment = undefined; // use parent's
|
|
53
|
+
this.baseSetParent(this.parent, subpath);
|
|
54
|
+
}
|
|
55
|
+
get snapshot() {
|
|
56
|
+
return freeze(this.getSnapshot());
|
|
57
|
+
}
|
|
58
|
+
getSnapshot() {
|
|
59
|
+
return this.type.getSnapshot(this);
|
|
60
|
+
}
|
|
61
|
+
toString() {
|
|
62
|
+
const path = (this.isAlive ? this.path : this.pathUponDeath) || "<root>";
|
|
63
|
+
return `${this.type.name}@${path}${this.isAlive ? "" : " [dead]"}`;
|
|
64
|
+
}
|
|
65
|
+
die() {
|
|
66
|
+
if (!this.isAlive || this.state === NodeLifeCycle.DETACHING) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
this.aboutToDie();
|
|
70
|
+
this.finalizeDeath();
|
|
71
|
+
}
|
|
72
|
+
finalizeCreation() {
|
|
73
|
+
this.baseFinalizeCreation();
|
|
74
|
+
}
|
|
75
|
+
aboutToDie() {
|
|
76
|
+
this.baseAboutToDie();
|
|
77
|
+
}
|
|
78
|
+
finalizeDeath() {
|
|
79
|
+
this.baseFinalizeDeath();
|
|
80
|
+
}
|
|
81
|
+
fireHook(name) {
|
|
82
|
+
this.fireInternalHook(name);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
ScalarNode.prototype.die = action(ScalarNode.prototype.die);
|
|
86
|
+
//# sourceMappingURL=scalar-node.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scalar-node.js","sourceRoot":"","sources":["../../../src/core/node/scalar-node.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAE7B,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAExC,OAAO,EAGL,aAAa,EACb,OAAO,EACP,IAAI,EACJ,MAAM,EACP,MAAM,mBAAmB,CAAA;AAE1B;;;GAGG;AACH,MAAM,OAAO,UAAoB,SAAQ,QAAiB;IASxD,YACE,UAA+B,EAC/B,MAA4B,EAC5B,OAAe,EACf,WAAgB,EAChB,eAAkB;QAElB,KAAK,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,CAAC,CAAA;QAC/C,IAAI,CAAC;YACH,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC,iB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C,CAAA;IAC1C,CAAC;IAED,IAAI,QAAQ;QACV,OAAO,MAAM,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,CAAA;IACnC,CAAC;IAED,WAAW;QACT,OAAO,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAA;IACpC,CAAC;IAED,QAAQ;QACN,MAAM,IAAI,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,IAAI,QAAQ,CAAA;QACxE,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,IAAI,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,EAAE,CAAA;IACpE,CAAC;IAED,GAAG;QACD,IAAI,CAAC,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,KAAK,KAAK,aAAa,CAAC,SAAS,EAAE,CAAC;YAC5D,OAAM;QACR,CAAC;QACD,IAAI,CAAC,UAAU,EAAE,CAAA;QACjB,IAAI,CAAC,aAAa,EAAE,CAAA;IACtB,CAAC;IAED,gBAAgB;QACd,IAAI,CAAC,oBAAoB,EAAE,CAAA;IAC7B,CAAC;IAED,UAAU;QACR,IAAI,CAAC,cAAc,EAAE,CAAA;IACvB,CAAC;IAED,aAAa;QACX,IAAI,CAAC,iBAAiB,EAAE,CAAA;IAC1B,CAAC;IAES,QAAQ,CAAC,IAAU;QAC3B,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAA;IAC7B,CAAC;CACF;AACD,UAAU,CAAC,SAAS,CAAC,GAAG,GAAG,MAAM,CAAC,UAAU,CAAC,SAAS,CAAC,GAAG,CAAC,CAAA","sourcesContent":["import { action } from \"mobx\"\n\nimport { BaseNode } from \"./BaseNode.ts\"\nimport { SimpleType } from \"../type/type.ts\"\nimport {\n type AnyObjectNode,\n Hook,\n NodeLifeCycle,\n devMode,\n fail,\n freeze\n} from \"../../internal.ts\"\n\n/**\n * @internal\n * @hidden\n */\nexport class ScalarNode<C, S, T> extends BaseNode<C, S, T> {\n // note about hooks:\n // - afterCreate is not emmited in scalar nodes, since it would be emitted in the\n // constructor, before it can be subscribed by anybody\n // - afterCreationFinalization could be emitted, but there's no need for it right now\n // - beforeDetach is never emitted for scalar nodes, since they cannot be detached\n\n declare readonly type: SimpleType<C, S, T>\n\n constructor(\n simpleType: SimpleType<C, S, T>,\n parent: AnyObjectNode | null,\n subpath: string,\n environment: any,\n initialSnapshot: C\n ) {\n super(simpleType, parent, subpath, environment)\n try {\n this.storedValue = simpleType.createNewInstance(initialSnapshot)\n } catch (e) {\n // short-cut to die the instance, to avoid the snapshot computed starting to throw...\n this.state = NodeLifeCycle.DEAD\n throw e\n }\n\n this.state = NodeLifeCycle.CREATED\n // for scalar nodes there's no point in firing this event since it would fire on the constructor, before\n // anybody can actually register for/listen to it\n // this.fireHook(Hook.AfterCreate)\n\n this.finalizeCreation()\n }\n\n get root(): AnyObjectNode {\n // future optimization: store root ref in the node and maintain it\n if (!this.parent) {\n throw fail(`This scalar node is not part of a tree`)\n }\n return this.parent.root\n }\n\n setParent(newParent: AnyObjectNode, subpath: string): void {\n const parentChanged = this.parent !== newParent\n const subpathChanged = this.subpath !== subpath\n\n if (!parentChanged && !subpathChanged) {\n return\n }\n\n if (devMode()) {\n if (!subpath) {\n // istanbul ignore next\n throw fail(\"assertion failed: subpath expected\")\n }\n if (!newParent) {\n // istanbul ignore next\n throw fail(\"assertion failed: parent expected\")\n }\n if (parentChanged) {\n // istanbul ignore next\n throw fail(\"assertion failed: scalar nodes cannot change their parent\")\n }\n }\n\n this.environment = undefined // use parent's\n this.baseSetParent(this.parent, subpath)\n }\n\n get snapshot(): S {\n return freeze(this.getSnapshot())\n }\n\n getSnapshot(): S {\n return this.type.getSnapshot(this)\n }\n\n toString(): string {\n const path = (this.isAlive ? this.path : this.pathUponDeath) || \"<root>\"\n return `${this.type.name}@${path}${this.isAlive ? \"\" : \" [dead]\"}`\n }\n\n die(): void {\n if (!this.isAlive || this.state === NodeLifeCycle.DETACHING) {\n return\n }\n this.aboutToDie()\n this.finalizeDeath()\n }\n\n finalizeCreation(): void {\n this.baseFinalizeCreation()\n }\n\n aboutToDie(): void {\n this.baseAboutToDie()\n }\n\n finalizeDeath(): void {\n this.baseFinalizeDeath()\n }\n\n protected fireHook(name: Hook): void {\n this.fireInternalHook(name)\n }\n}\nScalarNode.prototype.die = action(ScalarNode.prototype.die)\n"]}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @deprecated has been renamed to `flow()`.
|
|
3
|
+
* @hidden
|
|
4
|
+
*/
|
|
5
|
+
export declare function process<R>(generator: () => IterableIterator<any>): () => Promise<R>;
|
|
6
|
+
/**
|
|
7
|
+
* @deprecated has been renamed to `flow()`.
|
|
8
|
+
* @hidden
|
|
9
|
+
*/
|
|
10
|
+
export declare function process<A1>(generator: (a1: A1) => IterableIterator<any>): (a1: A1) => Promise<any>;
|
|
11
|
+
/**
|
|
12
|
+
* @deprecated has been renamed to `flow()`.
|
|
13
|
+
* @hidden
|
|
14
|
+
*/
|
|
15
|
+
export declare function process<A1, A2>(generator: (a1: A1, a2: A2) => IterableIterator<any>): (a1: A1, a2: A2) => Promise<any>;
|
|
16
|
+
/**
|
|
17
|
+
* @deprecated has been renamed to `flow()`.
|
|
18
|
+
* @hidden
|
|
19
|
+
*/
|
|
20
|
+
export declare function process<A1, A2, A3>(generator: (a1: A1, a2: A2, a3: A3) => IterableIterator<any>): (a1: A1, a2: A2, a3: A3) => Promise<any>;
|
|
21
|
+
/**
|
|
22
|
+
* @deprecated has been renamed to `flow()`.
|
|
23
|
+
* @hidden
|
|
24
|
+
*/
|
|
25
|
+
export declare function process<A1, A2, A3, A4>(generator: (a1: A1, a2: A2, a3: A3, a4: A4) => IterableIterator<any>): (a1: A1, a2: A2, a3: A3, a4: A4) => Promise<any>;
|
|
26
|
+
/**
|
|
27
|
+
* @deprecated has been renamed to `flow()`.
|
|
28
|
+
* @hidden
|
|
29
|
+
*/
|
|
30
|
+
export declare function process<A1, A2, A3, A4, A5>(generator: (a1: A1, a2: A2, a3: A3, a4: A4, a5: A5) => IterableIterator<any>): (a1: A1, a2: A2, a3: A3, a4: A4, a5: A5) => Promise<any>;
|
|
31
|
+
/**
|
|
32
|
+
* @deprecated has been renamed to `flow()`.
|
|
33
|
+
* @hidden
|
|
34
|
+
*/
|
|
35
|
+
export declare function process<A1, A2, A3, A4, A5, A6>(generator: (a1: A1, a2: A2, a3: A3, a4: A4, a5: A5, a6: A6) => IterableIterator<any>): (a1: A1, a2: A2, a3: A3, a4: A4, a5: A5, a6: A6) => Promise<any>;
|
|
36
|
+
/**
|
|
37
|
+
* @deprecated has been renamed to `flow()`.
|
|
38
|
+
* @hidden
|
|
39
|
+
*/
|
|
40
|
+
export declare function process<A1, A2, A3, A4, A5, A6, A7>(generator: (a1: A1, a2: A2, a3: A3, a4: A4, a5: A5, a6: A6, a7: A7) => IterableIterator<any>): (a1: A1, a2: A2, a3: A3, a4: A4, a5: A5, a6: A6, a7: A7) => Promise<any>;
|
|
41
|
+
/**
|
|
42
|
+
* @deprecated has been renamed to `flow()`.
|
|
43
|
+
* @hidden
|
|
44
|
+
*/
|
|
45
|
+
export declare function process<A1, A2, A3, A4, A5, A6, A7, A8>(generator: (a1: A1, a2: A2, a3: A3, a4: A4, a5: A5, a6: A6, a7: A7, a8: A8) => IterableIterator<any>): (a1: A1, a2: A2, a3: A3, a4: A4, a5: A5, a6: A6, a7: A7, a8: A8) => Promise<any>;
|
|
46
|
+
/**
|
|
47
|
+
* @internal
|
|
48
|
+
* @hidden
|
|
49
|
+
*/
|
|
50
|
+
export declare function createProcessSpawner(name: string, generator: Function): (this: any, ...flowArgs: any[]) => Promise<unknown>;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { createFlowSpawner, deprecated, flow } from "../internal.js";
|
|
2
|
+
// based on: https://github.com/mobxjs/mobx-utils/blob/master/src/async-action.ts
|
|
3
|
+
/*
|
|
4
|
+
All contents of this file are deprecated.
|
|
5
|
+
|
|
6
|
+
The term `process` has been replaced with `flow` to avoid conflicts with the
|
|
7
|
+
global `process` object.
|
|
8
|
+
|
|
9
|
+
Refer to `flow.ts` for any further changes to this implementation.
|
|
10
|
+
*/
|
|
11
|
+
const DEPRECATION_MESSAGE = "See https://github.com/mobxjs/mobx-state-tree/issues/399 for more information. " +
|
|
12
|
+
"Note that the middleware event types starting with `process` now start with `flow`.";
|
|
13
|
+
/**
|
|
14
|
+
* @hidden
|
|
15
|
+
*
|
|
16
|
+
* @deprecated has been renamed to `flow()`.
|
|
17
|
+
* See https://github.com/mobxjs/mobx-state-tree/issues/399 for more information.
|
|
18
|
+
* Note that the middleware event types starting with `process` now start with `flow`.
|
|
19
|
+
*
|
|
20
|
+
* @returns {Promise}
|
|
21
|
+
*/
|
|
22
|
+
export function process(asyncAction) {
|
|
23
|
+
deprecated("process", "`process()` has been renamed to `flow()`. " + DEPRECATION_MESSAGE);
|
|
24
|
+
return flow(asyncAction);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* @internal
|
|
28
|
+
* @hidden
|
|
29
|
+
*/
|
|
30
|
+
export function createProcessSpawner(name, generator) {
|
|
31
|
+
deprecated("process", "`createProcessSpawner()` has been renamed to `createFlowSpawner()`. " +
|
|
32
|
+
DEPRECATION_MESSAGE);
|
|
33
|
+
return createFlowSpawner(name, generator);
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=process.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"process.js","sourceRoot":"","sources":["../../src/core/process.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAA;AAEpE,iFAAiF;AACjF;;;;;;;EAOE;AAEF,MAAM,mBAAmB,GACvB,iFAAiF;IACjF,qFAAqF,CAAA;AAkGvF;;;;;;;;GAQG;AACH,MAAM,UAAU,OAAO,CAAC,WAAgB;IACtC,UAAU,CACR,SAAS,EACT,4CAA4C,GAAG,mBAAmB,CACnE,CAAA;IACD,OAAO,IAAI,CAAC,WAAW,CAAC,CAAA;AAC1B,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,oBAAoB,CAAC,IAAY,EAAE,SAAmB;IACpE,UAAU,CACR,SAAS,EACT,sEAAsE;QACpE,mBAAmB,CACtB,CAAA;IACD,OAAO,iBAAiB,CAAC,IAAI,EAAE,SAAS,CAAC,CAAA;AAC3C,CAAC","sourcesContent":["import { createFlowSpawner, deprecated, flow } from \"../internal.ts\"\n\n// based on: https://github.com/mobxjs/mobx-utils/blob/master/src/async-action.ts\n/*\n All contents of this file are deprecated.\n\n The term `process` has been replaced with `flow` to avoid conflicts with the\n global `process` object.\n\n Refer to `flow.ts` for any further changes to this implementation.\n*/\n\nconst DEPRECATION_MESSAGE =\n \"See https://github.com/mobxjs/mobx-state-tree/issues/399 for more information. \" +\n \"Note that the middleware event types starting with `process` now start with `flow`.\"\n\n/**\n * @deprecated has been renamed to `flow()`.\n * @hidden\n */\nexport function process<R>(\n generator: () => IterableIterator<any>\n): () => Promise<R>\n/**\n * @deprecated has been renamed to `flow()`.\n * @hidden\n */\nexport function process<A1>(\n generator: (a1: A1) => IterableIterator<any>\n): (a1: A1) => Promise<any>\n/**\n * @deprecated has been renamed to `flow()`.\n * @hidden\n */\nexport function process<A1, A2>(\n generator: (a1: A1, a2: A2) => IterableIterator<any>\n): (a1: A1, a2: A2) => Promise<any>\n/**\n * @deprecated has been renamed to `flow()`.\n * @hidden\n */\nexport function process<A1, A2, A3>(\n generator: (a1: A1, a2: A2, a3: A3) => IterableIterator<any>\n): (a1: A1, a2: A2, a3: A3) => Promise<any>\n/**\n * @deprecated has been renamed to `flow()`.\n * @hidden\n */\nexport function process<A1, A2, A3, A4>(\n generator: (a1: A1, a2: A2, a3: A3, a4: A4) => IterableIterator<any>\n): (a1: A1, a2: A2, a3: A3, a4: A4) => Promise<any>\n/**\n * @deprecated has been renamed to `flow()`.\n * @hidden\n */\nexport function process<A1, A2, A3, A4, A5>(\n generator: (a1: A1, a2: A2, a3: A3, a4: A4, a5: A5) => IterableIterator<any>\n): (a1: A1, a2: A2, a3: A3, a4: A4, a5: A5) => Promise<any>\n/**\n * @deprecated has been renamed to `flow()`.\n * @hidden\n */\nexport function process<A1, A2, A3, A4, A5, A6>(\n generator: (\n a1: A1,\n a2: A2,\n a3: A3,\n a4: A4,\n a5: A5,\n a6: A6\n ) => IterableIterator<any>\n): (a1: A1, a2: A2, a3: A3, a4: A4, a5: A5, a6: A6) => Promise<any>\n/**\n * @deprecated has been renamed to `flow()`.\n * @hidden\n */\nexport function process<A1, A2, A3, A4, A5, A6, A7>(\n generator: (\n a1: A1,\n a2: A2,\n a3: A3,\n a4: A4,\n a5: A5,\n a6: A6,\n a7: A7\n ) => IterableIterator<any>\n): (a1: A1, a2: A2, a3: A3, a4: A4, a5: A5, a6: A6, a7: A7) => Promise<any>\n/**\n * @deprecated has been renamed to `flow()`.\n * @hidden\n */\nexport function process<A1, A2, A3, A4, A5, A6, A7, A8>(\n generator: (\n a1: A1,\n a2: A2,\n a3: A3,\n a4: A4,\n a5: A5,\n a6: A6,\n a7: A7,\n a8: A8\n ) => IterableIterator<any>\n): (\n a1: A1,\n a2: A2,\n a3: A3,\n a4: A4,\n a5: A5,\n a6: A6,\n a7: A7,\n a8: A8\n) => Promise<any>\n/**\n * @hidden\n *\n * @deprecated has been renamed to `flow()`.\n * See https://github.com/mobxjs/mobx-state-tree/issues/399 for more information.\n * Note that the middleware event types starting with `process` now start with `flow`.\n *\n * @returns {Promise}\n */\nexport function process(asyncAction: any): any {\n deprecated(\n \"process\",\n \"`process()` has been renamed to `flow()`. \" + DEPRECATION_MESSAGE\n )\n return flow(asyncAction)\n}\n\n/**\n * @internal\n * @hidden\n */\nexport function createProcessSpawner(name: string, generator: Function) {\n deprecated(\n \"process\",\n \"`createProcessSpawner()` has been renamed to `createFlowSpawner()`. \" +\n DEPRECATION_MESSAGE\n )\n return createFlowSpawner(name, generator)\n}\n"]}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { type ExtractCSTWithSTN, type IAnyType } from "../../internal.ts";
|
|
2
|
+
/** Validation context entry, this is, where the validation should run against which type */
|
|
3
|
+
export interface IValidationContextEntry {
|
|
4
|
+
/** Subpath where the validation should be run, or an empty string to validate it all */
|
|
5
|
+
path: string;
|
|
6
|
+
/** Type to validate the subpath against */
|
|
7
|
+
type: IAnyType;
|
|
8
|
+
}
|
|
9
|
+
/** Array of validation context entries */
|
|
10
|
+
export type IValidationContext = IValidationContextEntry[];
|
|
11
|
+
/** Type validation error */
|
|
12
|
+
export interface IValidationError {
|
|
13
|
+
/** Validation context */
|
|
14
|
+
context: IValidationContext;
|
|
15
|
+
/** Value that was being validated, either a snapshot or an instance */
|
|
16
|
+
value: any;
|
|
17
|
+
/** Error message */
|
|
18
|
+
message?: string;
|
|
19
|
+
}
|
|
20
|
+
/** Type validation result, which is an array of type validation errors */
|
|
21
|
+
export type IValidationResult = IValidationError[];
|
|
22
|
+
/**
|
|
23
|
+
* @internal
|
|
24
|
+
* @hidden
|
|
25
|
+
*/
|
|
26
|
+
export declare function prettyPrintValue(value: any): string;
|
|
27
|
+
/**
|
|
28
|
+
* @internal
|
|
29
|
+
* @hidden
|
|
30
|
+
* Pushes a new entry onto the context array (mutates in place for performance).
|
|
31
|
+
* Returns the same context array for chaining.
|
|
32
|
+
*/
|
|
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;
|
|
41
|
+
/**
|
|
42
|
+
* @internal
|
|
43
|
+
* @hidden
|
|
44
|
+
*/
|
|
45
|
+
export declare function typeCheckSuccess(): IValidationResult;
|
|
46
|
+
/**
|
|
47
|
+
* @internal
|
|
48
|
+
* @hidden
|
|
49
|
+
*/
|
|
50
|
+
export declare function typeCheckFailure(context: IValidationContext, value: any, message?: string): IValidationResult;
|
|
51
|
+
/**
|
|
52
|
+
* @internal
|
|
53
|
+
* @hidden
|
|
54
|
+
*/
|
|
55
|
+
export declare function flattenTypeErrors(errors: IValidationResult[]): IValidationResult;
|
|
56
|
+
/**
|
|
57
|
+
* @internal
|
|
58
|
+
* @hidden
|
|
59
|
+
*/
|
|
60
|
+
export declare function typecheckInternal<IT extends IAnyType>(type: IAnyType, value: ExtractCSTWithSTN<IT>): void;
|
|
61
|
+
/**
|
|
62
|
+
* Run's the typechecker for the given type on the given value, which can be a snapshot or an instance.
|
|
63
|
+
* Throws if the given value is not according the provided type specification.
|
|
64
|
+
* Use this if you need typechecks even in a production build (by default all automatic runtime type checks will be skipped in production builds)
|
|
65
|
+
*
|
|
66
|
+
* @param type Type to check against.
|
|
67
|
+
* @param value Value to be checked, either a snapshot or an instance.
|
|
68
|
+
*/
|
|
69
|
+
export declare function typecheck<IT extends IAnyType>(type: IT, value: ExtractCSTWithSTN<IT>): void;
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { EMPTY_ARRAY, fail, getStateTreeNode, isPrimitive, isPrimitiveType, isStateTreeNode, isTypeCheckingEnabled } from "../../internal.js";
|
|
2
|
+
const MAX_STRINGIFY_DEPTH = 3;
|
|
3
|
+
function safeStringify(value) {
|
|
4
|
+
try {
|
|
5
|
+
const ancestors = [];
|
|
6
|
+
return JSON.stringify(value, function (_key, val) {
|
|
7
|
+
if (val !== null && typeof val === "object") {
|
|
8
|
+
while (ancestors.length > 0 &&
|
|
9
|
+
ancestors[ancestors.length - 1] !== this) {
|
|
10
|
+
ancestors.pop();
|
|
11
|
+
}
|
|
12
|
+
if (ancestors.length >= MAX_STRINGIFY_DEPTH) {
|
|
13
|
+
return Array.isArray(val) ? "[…]" : "{…}";
|
|
14
|
+
}
|
|
15
|
+
ancestors.push(val);
|
|
16
|
+
}
|
|
17
|
+
return val;
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
catch (e) {
|
|
21
|
+
// istanbul ignore next
|
|
22
|
+
return `<Unserializable: ${e}>`;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* @internal
|
|
27
|
+
* @hidden
|
|
28
|
+
*/
|
|
29
|
+
export function prettyPrintValue(value) {
|
|
30
|
+
return typeof value === "function"
|
|
31
|
+
? `<function${value.name ? " " + value.name : ""}>`
|
|
32
|
+
: isStateTreeNode(value)
|
|
33
|
+
? `<${value}>`
|
|
34
|
+
: `\`${safeStringify(value)}\``;
|
|
35
|
+
}
|
|
36
|
+
function shortenPrintValue(valueInString) {
|
|
37
|
+
return valueInString.length < 280
|
|
38
|
+
? valueInString
|
|
39
|
+
: `${valueInString.substring(0, 272)}......${valueInString.substring(valueInString.length - 8)}`;
|
|
40
|
+
}
|
|
41
|
+
function toErrorString(error) {
|
|
42
|
+
const { value } = error;
|
|
43
|
+
const type = error.context[error.context.length - 1].type;
|
|
44
|
+
const fullPath = error.context
|
|
45
|
+
.map(({ path }) => path)
|
|
46
|
+
.filter(path => path.length > 0)
|
|
47
|
+
.join("/");
|
|
48
|
+
const pathPrefix = fullPath.length > 0 ? `at path "/${fullPath}" ` : ``;
|
|
49
|
+
const currentTypename = isStateTreeNode(value)
|
|
50
|
+
? `value of type ${getStateTreeNode(value).type.name}:`
|
|
51
|
+
: isPrimitive(value)
|
|
52
|
+
? "value"
|
|
53
|
+
: "snapshot";
|
|
54
|
+
const isSnapshotCompatible = type && isStateTreeNode(value) && type.is(getStateTreeNode(value).snapshot);
|
|
55
|
+
return (`${pathPrefix}${currentTypename} ${shortenPrintValue(prettyPrintValue(value))} is not assignable ${type ? `to type: \`${type.name}\`` : ``}` +
|
|
56
|
+
(error.message ? ` (${error.message})` : "") +
|
|
57
|
+
(type
|
|
58
|
+
? isPrimitiveType(type) || isPrimitive(value)
|
|
59
|
+
? `.`
|
|
60
|
+
: `, expected an instance of \`${type.name}\` or a snapshot like \`${shortenPrintValue(type.describe())}\` instead.` +
|
|
61
|
+
(isSnapshotCompatible
|
|
62
|
+
? " (Note that a snapshot of the provided value is compatible with the targeted type)"
|
|
63
|
+
: "")
|
|
64
|
+
: `.`));
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* @internal
|
|
68
|
+
* @hidden
|
|
69
|
+
* Pushes a new entry onto the context array (mutates in place for performance).
|
|
70
|
+
* Returns the same context array for chaining.
|
|
71
|
+
*/
|
|
72
|
+
export function getContextForPath(context, path, type) {
|
|
73
|
+
context.push({ path, type });
|
|
74
|
+
return context;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* @internal
|
|
78
|
+
* @hidden
|
|
79
|
+
* Pops the last entry from the context array (mutates in place).
|
|
80
|
+
* Must be called after validation to restore context state.
|
|
81
|
+
*/
|
|
82
|
+
export function popContext(context) {
|
|
83
|
+
context.pop();
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* @internal
|
|
87
|
+
* @hidden
|
|
88
|
+
*/
|
|
89
|
+
export function typeCheckSuccess() {
|
|
90
|
+
return EMPTY_ARRAY;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* @internal
|
|
94
|
+
* @hidden
|
|
95
|
+
*/
|
|
96
|
+
export function typeCheckFailure(context, value, message) {
|
|
97
|
+
// Clone context since it may be mutated after this error is created
|
|
98
|
+
return [{ context: context.slice(), value, message }];
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* @internal
|
|
102
|
+
* @hidden
|
|
103
|
+
*/
|
|
104
|
+
export function flattenTypeErrors(errors) {
|
|
105
|
+
return errors.flat();
|
|
106
|
+
}
|
|
107
|
+
// TODO; doublecheck: typecheck should only needed to be invoked from: type.create and array / map / value.property will change
|
|
108
|
+
/**
|
|
109
|
+
* @internal
|
|
110
|
+
* @hidden
|
|
111
|
+
*/
|
|
112
|
+
export function typecheckInternal(type, value) {
|
|
113
|
+
// runs typeChecking if it is in dev-mode or through a process.env.ENABLE_TYPE_CHECK flag
|
|
114
|
+
if (isTypeCheckingEnabled()) {
|
|
115
|
+
typecheck(type, value);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Run's the typechecker for the given type on the given value, which can be a snapshot or an instance.
|
|
120
|
+
* Throws if the given value is not according the provided type specification.
|
|
121
|
+
* Use this if you need typechecks even in a production build (by default all automatic runtime type checks will be skipped in production builds)
|
|
122
|
+
*
|
|
123
|
+
* @param type Type to check against.
|
|
124
|
+
* @param value Value to be checked, either a snapshot or an instance.
|
|
125
|
+
*/
|
|
126
|
+
export function typecheck(type, value) {
|
|
127
|
+
const errors = type.validate(value, [{ path: "", type }]);
|
|
128
|
+
if (errors.length > 0) {
|
|
129
|
+
throw fail(validationErrorsToString(type, value, errors));
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
const MAX_ERRORS_REPORTED = 10;
|
|
133
|
+
function validationErrorsToString(type, value, errors) {
|
|
134
|
+
if (errors.length === 0) {
|
|
135
|
+
return undefined;
|
|
136
|
+
}
|
|
137
|
+
const shown = errors.slice(0, MAX_ERRORS_REPORTED).map(toErrorString);
|
|
138
|
+
const overflow = errors.length - shown.length;
|
|
139
|
+
if (overflow > 0) {
|
|
140
|
+
shown.push(`(… and ${overflow} more error${overflow === 1 ? "" : "s"})`);
|
|
141
|
+
}
|
|
142
|
+
return (`Error while converting ${shortenPrintValue(prettyPrintValue(value))} to \`${type.name}\`:\n\n ` + shown.join("\n "));
|
|
143
|
+
}
|
|
144
|
+
//# sourceMappingURL=type-checker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type-checker.js","sourceRoot":"","sources":["../../../src/core/type/type-checker.ts"],"names":[],"mappings":"AAAA,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,CAAC,GAAG,GAAG,CAAC,CAAA;IAC1E,CAAC;IAED,OAAO,CACL,0BAA0B,iBAAiB,CAAC,gBAAgB,CAAC,KAAK,CAAC,CAAC,SAClE,IAAI,CAAC,IACP,aAAa,GAAG,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CACrC,CAAA;AACH,CAAC","sourcesContent":["import {\n EMPTY_ARRAY,\n type ExtractCSTWithSTN,\n type IAnyType,\n fail,\n getStateTreeNode,\n isPrimitive,\n isPrimitiveType,\n isStateTreeNode,\n isTypeCheckingEnabled\n} from \"../../internal.ts\"\n\n/** Validation context entry, this is, where the validation should run against which type */\nexport interface IValidationContextEntry {\n /** Subpath where the validation should be run, or an empty string to validate it all */\n path: string\n /** Type to validate the subpath against */\n type: IAnyType\n}\n\n/** Array of validation context entries */\nexport type IValidationContext = IValidationContextEntry[]\n\n/** Type validation error */\nexport interface IValidationError {\n /** Validation context */\n context: IValidationContext\n /** Value that was being validated, either a snapshot or an instance */\n value: any\n /** Error message */\n message?: string\n}\n\n/** Type validation result, which is an array of type validation errors */\nexport type IValidationResult = IValidationError[]\n\nconst MAX_STRINGIFY_DEPTH = 3\n\nfunction safeStringify(value: any) {\n try {\n const ancestors: any[] = []\n return JSON.stringify(value, function (_key, val) {\n if (val !== null && typeof val === \"object\") {\n while (\n ancestors.length > 0 &&\n ancestors[ancestors.length - 1] !== this\n ) {\n ancestors.pop()\n }\n if (ancestors.length >= MAX_STRINGIFY_DEPTH) {\n return Array.isArray(val) ? \"[…]\" : \"{…}\"\n }\n ancestors.push(val)\n }\n return val\n })\n } catch (e) {\n // istanbul ignore next\n return `<Unserializable: ${e}>`\n }\n}\n\n/**\n * @internal\n * @hidden\n */\nexport function prettyPrintValue(value: any) {\n return typeof value === \"function\"\n ? `<function${value.name ? \" \" + value.name : \"\"}>`\n : isStateTreeNode(value)\n ? `<${value}>`\n : `\\`${safeStringify(value)}\\``\n}\n\nfunction shortenPrintValue(valueInString: string) {\n return valueInString.length < 280\n ? valueInString\n : `${valueInString.substring(0, 272)}......${valueInString.substring(valueInString.length - 8)}`\n}\n\nfunction toErrorString(error: IValidationError): string {\n const { value } = error\n const type = error.context[error.context.length - 1].type!\n const fullPath = error.context\n .map(({ path }) => path)\n .filter(path => path.length > 0)\n .join(\"/\")\n\n const pathPrefix = fullPath.length > 0 ? `at path \"/${fullPath}\" ` : ``\n\n const currentTypename = isStateTreeNode(value)\n ? `value of type ${getStateTreeNode(value).type.name}:`\n : isPrimitive(value)\n ? \"value\"\n : \"snapshot\"\n const isSnapshotCompatible =\n type && isStateTreeNode(value) && type.is(getStateTreeNode(value).snapshot)\n\n return (\n `${pathPrefix}${currentTypename} ${shortenPrintValue(prettyPrintValue(value))} is not assignable ${\n type ? `to type: \\`${type.name}\\`` : ``\n }` +\n (error.message ? ` (${error.message})` : \"\") +\n (type\n ? isPrimitiveType(type) || isPrimitive(value)\n ? `.`\n : `, expected an instance of \\`${(type as IAnyType).name}\\` or a snapshot like \\`${shortenPrintValue(\n (type as IAnyType).describe()\n )}\\` instead.` +\n (isSnapshotCompatible\n ? \" (Note that a snapshot of the provided value is compatible with the targeted type)\"\n : \"\")\n : `.`)\n )\n}\n\n/**\n * @internal\n * @hidden\n * Pushes a new entry onto the context array (mutates in place for performance).\n * Returns the same context array for chaining.\n */\nexport function getContextForPath(\n context: IValidationContext,\n path: string,\n type: IAnyType\n): IValidationContext {\n context.push({ path, type })\n return context\n}\n\n/**\n * @internal\n * @hidden\n * Pops the last entry from the context array (mutates in place).\n * Must be called after validation to restore context state.\n */\nexport function popContext(context: IValidationContext): void {\n context.pop()\n}\n\n/**\n * @internal\n * @hidden\n */\nexport function typeCheckSuccess(): IValidationResult {\n return EMPTY_ARRAY as any\n}\n\n/**\n * @internal\n * @hidden\n */\nexport function typeCheckFailure(\n context: IValidationContext,\n value: any,\n message?: string\n): IValidationResult {\n // Clone context since it may be mutated after this error is created\n return [{ context: context.slice(), value, message }]\n}\n\n/**\n * @internal\n * @hidden\n */\nexport function flattenTypeErrors(\n errors: IValidationResult[]\n): IValidationResult {\n return errors.flat()\n}\n\n// TODO; doublecheck: typecheck should only needed to be invoked from: type.create and array / map / value.property will change\n/**\n * @internal\n * @hidden\n */\nexport function typecheckInternal<IT extends IAnyType>(\n type: IAnyType,\n value: ExtractCSTWithSTN<IT>\n): void {\n // runs typeChecking if it is in dev-mode or through a process.env.ENABLE_TYPE_CHECK flag\n if (isTypeCheckingEnabled()) {\n typecheck(type, value)\n }\n}\n\n/**\n * Run's the typechecker for the given type on the given value, which can be a snapshot or an instance.\n * Throws if the given value is not according the provided type specification.\n * Use this if you need typechecks even in a production build (by default all automatic runtime type checks will be skipped in production builds)\n *\n * @param type Type to check against.\n * @param value Value to be checked, either a snapshot or an instance.\n */\nexport function typecheck<IT extends IAnyType>(\n type: IT,\n value: ExtractCSTWithSTN<IT>\n): void {\n const errors = type.validate(value, [{ path: \"\", type }])\n\n if (errors.length > 0) {\n throw fail(validationErrorsToString(type, value, errors))\n }\n}\n\nconst MAX_ERRORS_REPORTED = 10\n\nfunction validationErrorsToString<IT extends IAnyType>(\n type: IT,\n value: ExtractCSTWithSTN<IT>,\n errors: IValidationError[]\n): string | undefined {\n if (errors.length === 0) {\n return undefined\n }\n\n const shown = errors.slice(0, MAX_ERRORS_REPORTED).map(toErrorString)\n const overflow = errors.length - shown.length\n if (overflow > 0) {\n shown.push(`(… and ${overflow} more error${overflow === 1 ? \"\" : \"s\"})`)\n }\n\n return (\n `Error while converting ${shortenPrintValue(prettyPrintValue(value))} to \\`${\n type.name\n }\\`:\\n\\n ` + shown.join(\"\\n \")\n )\n}\n"]}
|