@jbrowse/mobx-state-tree 5.7.1 → 5.8.7

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.
Files changed (253) hide show
  1. package/README.md +0 -10
  2. package/dist/index.d.ts +2135 -2
  3. package/dist/mobx-state-tree.cjs +6894 -0
  4. package/dist/mobx-state-tree.cjs.map +1 -0
  5. package/dist/mobx-state-tree.mjs +6814 -0
  6. package/dist/mobx-state-tree.mjs.map +1 -0
  7. package/package.json +30 -26
  8. package/dist/core/action.d.ts +0 -87
  9. package/dist/core/action.js +0 -228
  10. package/dist/core/action.js.map +0 -1
  11. package/dist/core/actionContext.d.ts +0 -27
  12. package/dist/core/actionContext.js +0 -42
  13. package/dist/core/actionContext.js.map +0 -1
  14. package/dist/core/flow.d.ts +0 -69
  15. package/dist/core/flow.js +0 -180
  16. package/dist/core/flow.js.map +0 -1
  17. package/dist/core/json-patch.d.ts +0 -46
  18. package/dist/core/json-patch.js +0 -133
  19. package/dist/core/json-patch.js.map +0 -1
  20. package/dist/core/mst-operations.d.ts +0 -459
  21. package/dist/core/mst-operations.js +0 -885
  22. package/dist/core/mst-operations.js.map +0 -1
  23. package/dist/core/node/BaseNode.d.ts +0 -62
  24. package/dist/core/node/BaseNode.js +0 -152
  25. package/dist/core/node/BaseNode.js.map +0 -1
  26. package/dist/core/node/Hook.d.ts +0 -17
  27. package/dist/core/node/Hook.js +0 -15
  28. package/dist/core/node/Hook.js.map +0 -1
  29. package/dist/core/node/create-node.d.ts +0 -16
  30. package/dist/core/node/create-node.js +0 -41
  31. package/dist/core/node/create-node.js.map +0 -1
  32. package/dist/core/node/identifier-cache.d.ts +0 -19
  33. package/dist/core/node/identifier-cache.js +0 -115
  34. package/dist/core/node/identifier-cache.js.map +0 -1
  35. package/dist/core/node/livelinessChecking.d.ts +0 -37
  36. package/dist/core/node/livelinessChecking.js +0 -38
  37. package/dist/core/node/livelinessChecking.js.map +0 -1
  38. package/dist/core/node/node-utils.d.ts +0 -83
  39. package/dist/core/node/node-utils.js +0 -165
  40. package/dist/core/node/node-utils.js.map +0 -1
  41. package/dist/core/node/object-node.d.ts +0 -101
  42. package/dist/core/node/object-node.js +0 -546
  43. package/dist/core/node/object-node.js.map +0 -1
  44. package/dist/core/node/scalar-node.d.ts +0 -21
  45. package/dist/core/node/scalar-node.js +0 -90
  46. package/dist/core/node/scalar-node.js.map +0 -1
  47. package/dist/core/process.d.ts +0 -50
  48. package/dist/core/process.js +0 -39
  49. package/dist/core/process.js.map +0 -1
  50. package/dist/core/type/type-checker.d.ts +0 -69
  51. package/dist/core/type/type-checker.js +0 -154
  52. package/dist/core/type/type-checker.js.map +0 -1
  53. package/dist/core/type/type.d.ts +0 -317
  54. package/dist/core/type/type.js +0 -251
  55. package/dist/core/type/type.js.map +0 -1
  56. package/dist/index.js +0 -85
  57. package/dist/index.js.map +0 -1
  58. package/dist/internal.d.ts +0 -39
  59. package/dist/internal.js +0 -60
  60. package/dist/internal.js.map +0 -1
  61. package/dist/middlewares/create-action-tracking-middleware.d.ts +0 -24
  62. package/dist/middlewares/create-action-tracking-middleware.js +0 -81
  63. package/dist/middlewares/create-action-tracking-middleware.js.map +0 -1
  64. package/dist/middlewares/createActionTrackingMiddleware2.d.ts +0 -34
  65. package/dist/middlewares/createActionTrackingMiddleware2.js +0 -133
  66. package/dist/middlewares/createActionTrackingMiddleware2.js.map +0 -1
  67. package/dist/middlewares/on-action.d.ts +0 -87
  68. package/dist/middlewares/on-action.js +0 -215
  69. package/dist/middlewares/on-action.js.map +0 -1
  70. package/dist/package.json +0 -1
  71. package/dist/types/complex-types/array.d.ts +0 -81
  72. package/dist/types/complex-types/array.js +0 -353
  73. package/dist/types/complex-types/array.js.map +0 -1
  74. package/dist/types/complex-types/map.d.ts +0 -111
  75. package/dist/types/complex-types/map.js +0 -362
  76. package/dist/types/complex-types/map.js.map +0 -1
  77. package/dist/types/complex-types/model.d.ts +0 -193
  78. package/dist/types/complex-types/model.js +0 -478
  79. package/dist/types/complex-types/model.js.map +0 -1
  80. package/dist/types/index.d.ts +0 -33
  81. package/dist/types/index.js +0 -38
  82. package/dist/types/index.js.map +0 -1
  83. package/dist/types/primitives.d.ts +0 -125
  84. package/dist/types/primitives.js +0 -183
  85. package/dist/types/primitives.js.map +0 -1
  86. package/dist/types/utility-types/custom.d.ts +0 -75
  87. package/dist/types/utility-types/custom.js +0 -111
  88. package/dist/types/utility-types/custom.js.map +0 -1
  89. package/dist/types/utility-types/enumeration.d.ts +0 -5
  90. package/dist/types/utility-types/enumeration.js +0 -34
  91. package/dist/types/utility-types/enumeration.js.map +0 -1
  92. package/dist/types/utility-types/frozen.d.ts +0 -24
  93. package/dist/types/utility-types/frozen.js +0 -98
  94. package/dist/types/utility-types/frozen.js.map +0 -1
  95. package/dist/types/utility-types/identifier.d.ts +0 -87
  96. package/dist/types/utility-types/identifier.js +0 -130
  97. package/dist/types/utility-types/identifier.js.map +0 -1
  98. package/dist/types/utility-types/late.d.ts +0 -10
  99. package/dist/types/utility-types/late.js +0 -110
  100. package/dist/types/utility-types/late.js.map +0 -1
  101. package/dist/types/utility-types/lazy.d.ts +0 -23
  102. package/dist/types/utility-types/lazy.js +0 -77
  103. package/dist/types/utility-types/lazy.js.map +0 -1
  104. package/dist/types/utility-types/literal.d.ts +0 -38
  105. package/dist/types/utility-types/literal.js +0 -64
  106. package/dist/types/utility-types/literal.js.map +0 -1
  107. package/dist/types/utility-types/maybe.d.ts +0 -26
  108. package/dist/types/utility-types/maybe.js +0 -30
  109. package/dist/types/utility-types/maybe.js.map +0 -1
  110. package/dist/types/utility-types/optional.d.ts +0 -42
  111. package/dist/types/utility-types/optional.js +0 -141
  112. package/dist/types/utility-types/optional.js.map +0 -1
  113. package/dist/types/utility-types/reference.d.ts +0 -90
  114. package/dist/types/utility-types/reference.js +0 -393
  115. package/dist/types/utility-types/reference.js.map +0 -1
  116. package/dist/types/utility-types/refinement.d.ts +0 -10
  117. package/dist/types/utility-types/refinement.js +0 -86
  118. package/dist/types/utility-types/refinement.js.map +0 -1
  119. package/dist/types/utility-types/resilient.d.ts +0 -18
  120. package/dist/types/utility-types/resilient.js +0 -121
  121. package/dist/types/utility-types/resilient.js.map +0 -1
  122. package/dist/types/utility-types/snapshotProcessor.d.ts +0 -63
  123. package/dist/types/utility-types/snapshotProcessor.js +0 -162
  124. package/dist/types/utility-types/snapshotProcessor.js.map +0 -1
  125. package/dist/types/utility-types/union.d.ts +0 -78
  126. package/dist/types/utility-types/union.js +0 -246
  127. package/dist/types/utility-types/union.js.map +0 -1
  128. package/dist/utils.d.ts +0 -230
  129. package/dist/utils.js +0 -483
  130. package/dist/utils.js.map +0 -1
  131. package/esm/core/action.d.ts +0 -87
  132. package/esm/core/action.js +0 -219
  133. package/esm/core/action.js.map +0 -1
  134. package/esm/core/actionContext.d.ts +0 -27
  135. package/esm/core/actionContext.js +0 -37
  136. package/esm/core/actionContext.js.map +0 -1
  137. package/esm/core/flow.d.ts +0 -69
  138. package/esm/core/flow.js +0 -173
  139. package/esm/core/flow.js.map +0 -1
  140. package/esm/core/json-patch.d.ts +0 -46
  141. package/esm/core/json-patch.js +0 -125
  142. package/esm/core/json-patch.js.map +0 -1
  143. package/esm/core/mst-operations.d.ts +0 -459
  144. package/esm/core/mst-operations.js +0 -844
  145. package/esm/core/mst-operations.js.map +0 -1
  146. package/esm/core/node/BaseNode.d.ts +0 -62
  147. package/esm/core/node/BaseNode.js +0 -148
  148. package/esm/core/node/BaseNode.js.map +0 -1
  149. package/esm/core/node/Hook.d.ts +0 -17
  150. package/esm/core/node/Hook.js +0 -12
  151. package/esm/core/node/Hook.js.map +0 -1
  152. package/esm/core/node/create-node.d.ts +0 -16
  153. package/esm/core/node/create-node.js +0 -36
  154. package/esm/core/node/create-node.js.map +0 -1
  155. package/esm/core/node/identifier-cache.d.ts +0 -19
  156. package/esm/core/node/identifier-cache.js +0 -111
  157. package/esm/core/node/identifier-cache.js.map +0 -1
  158. package/esm/core/node/livelinessChecking.d.ts +0 -37
  159. package/esm/core/node/livelinessChecking.js +0 -33
  160. package/esm/core/node/livelinessChecking.js.map +0 -1
  161. package/esm/core/node/node-utils.d.ts +0 -83
  162. package/esm/core/node/node-utils.js +0 -153
  163. package/esm/core/node/node-utils.js.map +0 -1
  164. package/esm/core/node/object-node.d.ts +0 -101
  165. package/esm/core/node/object-node.js +0 -542
  166. package/esm/core/node/object-node.js.map +0 -1
  167. package/esm/core/node/scalar-node.d.ts +0 -21
  168. package/esm/core/node/scalar-node.js +0 -86
  169. package/esm/core/node/scalar-node.js.map +0 -1
  170. package/esm/core/process.d.ts +0 -50
  171. package/esm/core/process.js +0 -35
  172. package/esm/core/process.js.map +0 -1
  173. package/esm/core/type/type-checker.d.ts +0 -69
  174. package/esm/core/type/type-checker.js +0 -144
  175. package/esm/core/type/type-checker.js.map +0 -1
  176. package/esm/core/type/type.d.ts +0 -317
  177. package/esm/core/type/type.js +0 -243
  178. package/esm/core/type/type.js.map +0 -1
  179. package/esm/index.d.ts +0 -2
  180. package/esm/index.js +0 -2
  181. package/esm/index.js.map +0 -1
  182. package/esm/internal.d.ts +0 -39
  183. package/esm/internal.js +0 -44
  184. package/esm/internal.js.map +0 -1
  185. package/esm/middlewares/create-action-tracking-middleware.d.ts +0 -24
  186. package/esm/middlewares/create-action-tracking-middleware.js +0 -78
  187. package/esm/middlewares/create-action-tracking-middleware.js.map +0 -1
  188. package/esm/middlewares/createActionTrackingMiddleware2.d.ts +0 -34
  189. package/esm/middlewares/createActionTrackingMiddleware2.js +0 -130
  190. package/esm/middlewares/createActionTrackingMiddleware2.js.map +0 -1
  191. package/esm/middlewares/on-action.d.ts +0 -87
  192. package/esm/middlewares/on-action.js +0 -210
  193. package/esm/middlewares/on-action.js.map +0 -1
  194. package/esm/types/complex-types/array.d.ts +0 -81
  195. package/esm/types/complex-types/array.js +0 -347
  196. package/esm/types/complex-types/array.js.map +0 -1
  197. package/esm/types/complex-types/map.d.ts +0 -111
  198. package/esm/types/complex-types/map.js +0 -356
  199. package/esm/types/complex-types/map.js.map +0 -1
  200. package/esm/types/complex-types/model.d.ts +0 -193
  201. package/esm/types/complex-types/model.js +0 -471
  202. package/esm/types/complex-types/model.js.map +0 -1
  203. package/esm/types/index.d.ts +0 -33
  204. package/esm/types/index.js +0 -35
  205. package/esm/types/index.js.map +0 -1
  206. package/esm/types/primitives.d.ts +0 -125
  207. package/esm/types/primitives.js +0 -177
  208. package/esm/types/primitives.js.map +0 -1
  209. package/esm/types/utility-types/custom.d.ts +0 -75
  210. package/esm/types/utility-types/custom.js +0 -106
  211. package/esm/types/utility-types/custom.js.map +0 -1
  212. package/esm/types/utility-types/enumeration.d.ts +0 -5
  213. package/esm/types/utility-types/enumeration.js +0 -31
  214. package/esm/types/utility-types/enumeration.js.map +0 -1
  215. package/esm/types/utility-types/frozen.d.ts +0 -24
  216. package/esm/types/utility-types/frozen.js +0 -92
  217. package/esm/types/utility-types/frozen.js.map +0 -1
  218. package/esm/types/utility-types/identifier.d.ts +0 -87
  219. package/esm/types/utility-types/identifier.js +0 -121
  220. package/esm/types/utility-types/identifier.js.map +0 -1
  221. package/esm/types/utility-types/late.d.ts +0 -10
  222. package/esm/types/utility-types/late.js +0 -106
  223. package/esm/types/utility-types/late.js.map +0 -1
  224. package/esm/types/utility-types/lazy.d.ts +0 -23
  225. package/esm/types/utility-types/lazy.js +0 -72
  226. package/esm/types/utility-types/lazy.js.map +0 -1
  227. package/esm/types/utility-types/literal.d.ts +0 -38
  228. package/esm/types/utility-types/literal.js +0 -58
  229. package/esm/types/utility-types/literal.js.map +0 -1
  230. package/esm/types/utility-types/maybe.d.ts +0 -26
  231. package/esm/types/utility-types/maybe.js +0 -26
  232. package/esm/types/utility-types/maybe.js.map +0 -1
  233. package/esm/types/utility-types/optional.d.ts +0 -42
  234. package/esm/types/utility-types/optional.js +0 -135
  235. package/esm/types/utility-types/optional.js.map +0 -1
  236. package/esm/types/utility-types/reference.d.ts +0 -90
  237. package/esm/types/utility-types/reference.js +0 -383
  238. package/esm/types/utility-types/reference.js.map +0 -1
  239. package/esm/types/utility-types/refinement.d.ts +0 -10
  240. package/esm/types/utility-types/refinement.js +0 -82
  241. package/esm/types/utility-types/refinement.js.map +0 -1
  242. package/esm/types/utility-types/resilient.d.ts +0 -18
  243. package/esm/types/utility-types/resilient.js +0 -118
  244. package/esm/types/utility-types/resilient.js.map +0 -1
  245. package/esm/types/utility-types/snapshotProcessor.d.ts +0 -63
  246. package/esm/types/utility-types/snapshotProcessor.js +0 -159
  247. package/esm/types/utility-types/snapshotProcessor.js.map +0 -1
  248. package/esm/types/utility-types/union.d.ts +0 -78
  249. package/esm/types/utility-types/union.js +0 -240
  250. package/esm/types/utility-types/union.js.map +0 -1
  251. package/esm/utils.d.ts +0 -230
  252. package/esm/utils.js +0 -449
  253. package/esm/utils.js.map +0 -1
@@ -1,90 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ScalarNode = void 0;
4
- const mobx_1 = require("mobx");
5
- const BaseNode_ts_1 = require("./BaseNode.js");
6
- const internal_ts_1 = require("../../internal.js");
7
- /**
8
- * @internal
9
- * @hidden
10
- */
11
- class ScalarNode extends BaseNode_ts_1.BaseNode {
12
- constructor(simpleType, parent, subpath, environment, initialSnapshot) {
13
- super(simpleType, parent, subpath, environment);
14
- try {
15
- this.storedValue = simpleType.createNewInstance(initialSnapshot);
16
- }
17
- catch (e) {
18
- // short-cut to die the instance, to avoid the snapshot computed starting to throw...
19
- this.state = internal_ts_1.NodeLifeCycle.DEAD;
20
- throw e;
21
- }
22
- this.state = internal_ts_1.NodeLifeCycle.CREATED;
23
- // for scalar nodes there's no point in firing this event since it would fire on the constructor, before
24
- // anybody can actually register for/listen to it
25
- // this.fireHook(Hook.AfterCreate)
26
- this.finalizeCreation();
27
- }
28
- get root() {
29
- // future optimization: store root ref in the node and maintain it
30
- if (!this.parent) {
31
- throw (0, internal_ts_1.fail)(`This scalar node is not part of a tree`);
32
- }
33
- return this.parent.root;
34
- }
35
- setParent(newParent, subpath) {
36
- const parentChanged = this.parent !== newParent;
37
- const subpathChanged = this.subpath !== subpath;
38
- if (!parentChanged && !subpathChanged) {
39
- return;
40
- }
41
- if ((0, internal_ts_1.devMode)()) {
42
- if (!subpath) {
43
- // istanbul ignore next
44
- throw (0, internal_ts_1.fail)("assertion failed: subpath expected");
45
- }
46
- if (!newParent) {
47
- // istanbul ignore next
48
- throw (0, internal_ts_1.fail)("assertion failed: parent expected");
49
- }
50
- if (parentChanged) {
51
- // istanbul ignore next
52
- throw (0, internal_ts_1.fail)("assertion failed: scalar nodes cannot change their parent");
53
- }
54
- }
55
- this.environment = undefined; // use parent's
56
- this.baseSetParent(this.parent, subpath);
57
- }
58
- get snapshot() {
59
- return (0, internal_ts_1.freeze)(this.getSnapshot());
60
- }
61
- getSnapshot() {
62
- return this.type.getSnapshot(this);
63
- }
64
- toString() {
65
- const path = (this.isAlive ? this.path : this.pathUponDeath) || "<root>";
66
- return `${this.type.name}@${path}${this.isAlive ? "" : " [dead]"}`;
67
- }
68
- die() {
69
- if (!this.isAlive || this.state === internal_ts_1.NodeLifeCycle.DETACHING) {
70
- return;
71
- }
72
- this.aboutToDie();
73
- this.finalizeDeath();
74
- }
75
- finalizeCreation() {
76
- this.baseFinalizeCreation();
77
- }
78
- aboutToDie() {
79
- this.baseAboutToDie();
80
- }
81
- finalizeDeath() {
82
- this.baseFinalizeDeath();
83
- }
84
- fireHook(name) {
85
- this.fireInternalHook(name);
86
- }
87
- }
88
- exports.ScalarNode = ScalarNode;
89
- ScalarNode.prototype.die = (0, mobx_1.action)(ScalarNode.prototype.die);
90
- //# sourceMappingURL=scalar-node.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"scalar-node.js","sourceRoot":"","sources":["../../../src/core/node/scalar-node.ts"],"names":[],"mappings":";;;AAAA,+BAA6B;AAE7B,+CAAwC;AAExC,mDAO0B;AAE1B;;;GAGG;AACH,MAAa,UAAoB,SAAQ,sBAAiB;IASxD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AC7B,CAAC;CACF;AAxGD,gCAwGC;AACD,UAAU,CAAC,SAAS,CAAC,GAAG,GAAG,IAAA,aAAM,EAAC,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"]}
@@ -1,50 +0,0 @@
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>;
@@ -1,39 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.process = process;
4
- exports.createProcessSpawner = createProcessSpawner;
5
- const internal_ts_1 = require("../internal.js");
6
- // based on: https://github.com/mobxjs/mobx-utils/blob/master/src/async-action.ts
7
- /*
8
- All contents of this file are deprecated.
9
-
10
- The term `process` has been replaced with `flow` to avoid conflicts with the
11
- global `process` object.
12
-
13
- Refer to `flow.ts` for any further changes to this implementation.
14
- */
15
- const DEPRECATION_MESSAGE = "See https://github.com/mobxjs/mobx-state-tree/issues/399 for more information. " +
16
- "Note that the middleware event types starting with `process` now start with `flow`.";
17
- /**
18
- * @hidden
19
- *
20
- * @deprecated has been renamed to `flow()`.
21
- * See https://github.com/mobxjs/mobx-state-tree/issues/399 for more information.
22
- * Note that the middleware event types starting with `process` now start with `flow`.
23
- *
24
- * @returns {Promise}
25
- */
26
- function process(asyncAction) {
27
- (0, internal_ts_1.deprecated)("process", "`process()` has been renamed to `flow()`. " + DEPRECATION_MESSAGE);
28
- return (0, internal_ts_1.flow)(asyncAction);
29
- }
30
- /**
31
- * @internal
32
- * @hidden
33
- */
34
- function createProcessSpawner(name, generator) {
35
- (0, internal_ts_1.deprecated)("process", "`createProcessSpawner()` has been renamed to `createFlowSpawner()`. " +
36
- DEPRECATION_MESSAGE);
37
- return (0, internal_ts_1.createFlowSpawner)(name, generator);
38
- }
39
- //# sourceMappingURL=process.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"process.js","sourceRoot":"","sources":["../../src/core/process.ts"],"names":[],"mappings":";;AAyHA,0BAMC;AAMD,oDAOC;AA5ID,gDAAoE;AAEpE,iFAAiF;AACjF;;;;;;;EAOE;AAEF,MAAM,mBAAmB,GACvB,iFAAiF;IACjF,qFAAqF,CAAA;AAkGvF;;;;;;;;GAQG;AACH,SAAgB,OAAO,CAAC,WAAgB;IACtC,IAAA,wBAAU,EACR,SAAS,EACT,4CAA4C,GAAG,mBAAmB,CACnE,CAAA;IACD,OAAO,IAAA,kBAAI,EAAC,WAAW,CAAC,CAAA;AAC1B,CAAC;AAED;;;GAGG;AACH,SAAgB,oBAAoB,CAAC,IAAY,EAAE,SAAmB;IACpE,IAAA,wBAAU,EACR,SAAS,EACT,sEAAsE;QACpE,mBAAmB,CACtB,CAAA;IACD,OAAO,IAAA,+BAAiB,EAAC,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"]}
@@ -1,69 +0,0 @@
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;
@@ -1,154 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.prettyPrintValue = prettyPrintValue;
4
- exports.getContextForPath = getContextForPath;
5
- exports.popContext = popContext;
6
- exports.typeCheckSuccess = typeCheckSuccess;
7
- exports.typeCheckFailure = typeCheckFailure;
8
- exports.flattenTypeErrors = flattenTypeErrors;
9
- exports.typecheckInternal = typecheckInternal;
10
- exports.typecheck = typecheck;
11
- const internal_ts_1 = require("../../internal.js");
12
- const MAX_STRINGIFY_DEPTH = 3;
13
- function safeStringify(value) {
14
- try {
15
- const ancestors = [];
16
- return JSON.stringify(value, function (_key, val) {
17
- if (val !== null && typeof val === "object") {
18
- while (ancestors.length > 0 &&
19
- ancestors[ancestors.length - 1] !== this) {
20
- ancestors.pop();
21
- }
22
- if (ancestors.length >= MAX_STRINGIFY_DEPTH) {
23
- return Array.isArray(val) ? "[…]" : "{…}";
24
- }
25
- ancestors.push(val);
26
- }
27
- return val;
28
- });
29
- }
30
- catch (e) {
31
- // istanbul ignore next
32
- return `<Unserializable: ${e}>`;
33
- }
34
- }
35
- /**
36
- * @internal
37
- * @hidden
38
- */
39
- function prettyPrintValue(value) {
40
- return typeof value === "function"
41
- ? `<function${value.name ? " " + value.name : ""}>`
42
- : (0, internal_ts_1.isStateTreeNode)(value)
43
- ? `<${value}>`
44
- : `\`${safeStringify(value)}\``;
45
- }
46
- function shortenPrintValue(valueInString) {
47
- return valueInString.length < 280
48
- ? valueInString
49
- : `${valueInString.substring(0, 272)}......${valueInString.substring(valueInString.length - 8)}`;
50
- }
51
- function toErrorString(error) {
52
- const { value } = error;
53
- const type = error.context[error.context.length - 1].type;
54
- const fullPath = error.context
55
- .map(({ path }) => path)
56
- .filter(path => path.length > 0)
57
- .join("/");
58
- const pathPrefix = fullPath.length > 0 ? `at path "/${fullPath}" ` : ``;
59
- const currentTypename = (0, internal_ts_1.isStateTreeNode)(value)
60
- ? `value of type ${(0, internal_ts_1.getStateTreeNode)(value).type.name}:`
61
- : (0, internal_ts_1.isPrimitive)(value)
62
- ? "value"
63
- : "snapshot";
64
- const isSnapshotCompatible = type && (0, internal_ts_1.isStateTreeNode)(value) && type.is((0, internal_ts_1.getStateTreeNode)(value).snapshot);
65
- return (`${pathPrefix}${currentTypename} ${shortenPrintValue(prettyPrintValue(value))} is not assignable ${type ? `to type: \`${type.name}\`` : ``}` +
66
- (error.message ? ` (${error.message})` : "") +
67
- (type
68
- ? (0, internal_ts_1.isPrimitiveType)(type) || (0, internal_ts_1.isPrimitive)(value)
69
- ? `.`
70
- : `, expected an instance of \`${type.name}\` or a snapshot like \`${shortenPrintValue(type.describe())}\` instead.` +
71
- (isSnapshotCompatible
72
- ? " (Note that a snapshot of the provided value is compatible with the targeted type)"
73
- : "")
74
- : `.`));
75
- }
76
- /**
77
- * @internal
78
- * @hidden
79
- * Pushes a new entry onto the context array (mutates in place for performance).
80
- * Returns the same context array for chaining.
81
- */
82
- function getContextForPath(context, path, type) {
83
- context.push({ path, type });
84
- return context;
85
- }
86
- /**
87
- * @internal
88
- * @hidden
89
- * Pops the last entry from the context array (mutates in place).
90
- * Must be called after validation to restore context state.
91
- */
92
- function popContext(context) {
93
- context.pop();
94
- }
95
- /**
96
- * @internal
97
- * @hidden
98
- */
99
- function typeCheckSuccess() {
100
- return internal_ts_1.EMPTY_ARRAY;
101
- }
102
- /**
103
- * @internal
104
- * @hidden
105
- */
106
- function typeCheckFailure(context, value, message) {
107
- // Clone context since it may be mutated after this error is created
108
- return [{ context: context.slice(), value, message }];
109
- }
110
- /**
111
- * @internal
112
- * @hidden
113
- */
114
- function flattenTypeErrors(errors) {
115
- return errors.flat();
116
- }
117
- // TODO; doublecheck: typecheck should only needed to be invoked from: type.create and array / map / value.property will change
118
- /**
119
- * @internal
120
- * @hidden
121
- */
122
- function typecheckInternal(type, value) {
123
- // runs typeChecking if it is in dev-mode or through a process.env.ENABLE_TYPE_CHECK flag
124
- if ((0, internal_ts_1.isTypeCheckingEnabled)()) {
125
- typecheck(type, value);
126
- }
127
- }
128
- /**
129
- * Run's the typechecker for the given type on the given value, which can be a snapshot or an instance.
130
- * Throws if the given value is not according the provided type specification.
131
- * Use this if you need typechecks even in a production build (by default all automatic runtime type checks will be skipped in production builds)
132
- *
133
- * @param type Type to check against.
134
- * @param value Value to be checked, either a snapshot or an instance.
135
- */
136
- function typecheck(type, value) {
137
- const errors = type.validate(value, [{ path: "", type }]);
138
- if (errors.length > 0) {
139
- throw (0, internal_ts_1.fail)(validationErrorsToString(type, value, errors));
140
- }
141
- }
142
- const MAX_ERRORS_REPORTED = 10;
143
- function validationErrorsToString(type, value, errors) {
144
- if (errors.length === 0) {
145
- return undefined;
146
- }
147
- const shown = errors.slice(0, MAX_ERRORS_REPORTED).map(toErrorString);
148
- const overflow = errors.length - shown.length;
149
- if (overflow > 0) {
150
- shown.push(`(… and ${overflow} more error${overflow === 1 ? "" : "s"})`);
151
- }
152
- return (`Error while converting ${shortenPrintValue(prettyPrintValue(value))} to \`${type.name}\`:\n\n ` + shown.join("\n "));
153
- }
154
- //# sourceMappingURL=type-checker.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"type-checker.js","sourceRoot":"","sources":["../../../src/core/type/type-checker.ts"],"names":[],"mappings":";;AAkEA,4CAMC;AAkDD,8CAOC;AAQD,gCAEC;AAMD,4CAEC;AAMD,4CAOC;AAMD,8CAIC;AAOD,8CAQC;AAUD,8BASC;AA5MD,mDAU0B;AA0B1B,MAAM,mBAAmB,GAAG,CAAC,CAAA;AAE7B,SAAS,aAAa,CAAC,KAAU;IAC/B,IAAI,CAAC;QACH,MAAM,SAAS,GAAU,EAAE,CAAA;QAC3B,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,UAAU,IAAI,EAAE,GAAG;YAC9C,IAAI,GAAG,KAAK,IAAI,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE,CAAC;gBAC5C,OACE,SAAS,CAAC,MAAM,GAAG,CAAC;oBACpB,SAAS,CAAC,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC,KAAK,IAAI,EACxC,CAAC;oBACD,SAAS,CAAC,GAAG,EAAE,CAAA;gBACjB,CAAC;gBACD,IAAI,SAAS,CAAC,MAAM,IAAI,mBAAmB,EAAE,CAAC;oBAC5C,OAAO,K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IAAA,kBAAI,EAAC,wBAAwB,CAAC,IAAI,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC,CAAA;IAC3D,CAAC;AACH,CAAC;AAED,MAAM,mBAAmB,GAAG,EAAE,CAAA;AAE9B,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,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,mBAAmB,CAAC,CAAC,GAAG,CAAC,aAAa,CAAC,CAAA;IACrE,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,GAAG,KAAK,CAAC,MAAM,CAAA;IAC7C,IAAI,QAAQ,GAAG,CAAC,EAAE,CAAC;QACjB,KAAK,CAAC,IAAI,CAAC,UAAU,QAAQ,cAAc,QAAQ,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,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"]}