@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,38 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.setLivelinessChecking = setLivelinessChecking;
4
- exports.getLivelinessChecking = getLivelinessChecking;
5
- exports.setLivelynessChecking = setLivelynessChecking;
6
- let livelinessChecking = "warn";
7
- /**
8
- * Defines what MST should do when running into reads / writes to objects that have died.
9
- * By default it will print a warning.
10
- * Use the `"error"` option to easy debugging to see where the error was thrown and when the offending read / write took place
11
- *
12
- * @param mode `"warn"`, `"error"` or `"ignore"`
13
- */
14
- function setLivelinessChecking(mode) {
15
- livelinessChecking = mode;
16
- }
17
- /**
18
- * Returns the current liveliness checking mode.
19
- *
20
- * @returns `"warn"`, `"error"` or `"ignore"`
21
- */
22
- function getLivelinessChecking() {
23
- return livelinessChecking;
24
- }
25
- /**
26
- * @deprecated use setLivelinessChecking instead
27
- * @hidden
28
- *
29
- * Defines what MST should do when running into reads / writes to objects that have died.
30
- * By default it will print a warning.
31
- * Use the `"error"` option to easy debugging to see where the error was thrown and when the offending read / write took place
32
- *
33
- * @param mode `"warn"`, `"error"` or `"ignore"`
34
- */
35
- function setLivelynessChecking(mode) {
36
- setLivelinessChecking(mode);
37
- }
38
- //# sourceMappingURL=livelinessChecking.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"livelinessChecking.js","sourceRoot":"","sources":["../../../src/core/node/livelinessChecking.ts"],"names":[],"mappings":";;AAiBA,sDAEC;AAOD,sDAEC;AAkBD,sDAEC;AAxCD,IAAI,kBAAkB,GAAmB,MAAM,CAAA;AAE/C;;;;;;GAMG;AACH,SAAgB,qBAAqB,CAAC,IAAoB;IACxD,kBAAkB,GAAG,IAAI,CAAA;AAC3B,CAAC;AAED;;;;GAIG;AACH,SAAgB,qBAAqB;IACnC,OAAO,kBAAkB,CAAA;AAC3B,CAAC;AAQD;;;;;;;;;GASG;AACH,SAAgB,qBAAqB,CAAC,IAAoB;IACxD,qBAAqB,CAAC,IAAI,CAAC,CAAA;AAC7B,CAAC","sourcesContent":["/**\n * Defines what MST should do when running into reads / writes to objects that have died.\n * - `\"warn\"`: Print a warning (default).\n * - `\"error\"`: Throw an exception.\n * - \"`ignore`\": Do nothing.\n */\nexport type LivelinessMode = \"warn\" | \"error\" | \"ignore\"\n\nlet livelinessChecking: LivelinessMode = \"warn\"\n\n/**\n * Defines what MST should do when running into reads / writes to objects that have died.\n * By default it will print a warning.\n * Use the `\"error\"` option to easy debugging to see where the error was thrown and when the offending read / write took place\n *\n * @param mode `\"warn\"`, `\"error\"` or `\"ignore\"`\n */\nexport function setLivelinessChecking(mode: LivelinessMode) {\n livelinessChecking = mode\n}\n\n/**\n * Returns the current liveliness checking mode.\n *\n * @returns `\"warn\"`, `\"error\"` or `\"ignore\"`\n */\nexport function getLivelinessChecking(): LivelinessMode {\n return livelinessChecking\n}\n\n/**\n * @deprecated use LivelinessMode instead\n * @hidden\n */\nexport type LivelynessMode = LivelinessMode\n\n/**\n * @deprecated use setLivelinessChecking instead\n * @hidden\n *\n * Defines what MST should do when running into reads / writes to objects that have died.\n * By default it will print a warning.\n * Use the `\"error\"` option to easy debugging to see where the error was thrown and when the offending read / write took place\n *\n * @param mode `\"warn\"`, `\"error\"` or `\"ignore\"`\n */\nexport function setLivelynessChecking(mode: LivelinessMode) {\n setLivelinessChecking(mode)\n}\n"]}
@@ -1,83 +0,0 @@
1
- import type { AnyNode, AnyObjectNode, IAnyComplexType, IAnyType, IChildNodesMap, IType, Instance, STNValue } from "../../internal.ts";
2
- /**
3
- * @internal
4
- * @hidden
5
- */
6
- export declare enum NodeLifeCycle {
7
- INITIALIZING = 0,// setting up
8
- CREATED = 1,// afterCreate has run
9
- FINALIZED = 2,// afterAttach has run
10
- DETACHING = 3,// being detached from the tree
11
- DEAD = 4
12
- }
13
- /** @hidden */
14
- declare const $stateTreeNodeType: unique symbol;
15
- /**
16
- * Common interface that represents a node instance.
17
- * @hidden
18
- */
19
- export interface IStateTreeNode<IT extends IAnyType = IAnyType> {
20
- /**
21
- * @internal
22
- */
23
- readonly $treenode?: any;
24
- readonly [$stateTreeNodeType]?: [IT] | [any];
25
- }
26
- /** @hidden */
27
- export type TypeOfValue<T extends IAnyStateTreeNode> = T extends IStateTreeNode<infer IT> ? IT : never;
28
- /**
29
- * Represents any state tree node instance.
30
- * @hidden
31
- */
32
- export interface IAnyStateTreeNode extends STNValue<any, IAnyType> {
33
- }
34
- /**
35
- * Returns true if the given value is a node in a state tree.
36
- * More precisely, that is, if the value is an instance of a
37
- * `types.model`, `types.array` or `types.map`.
38
- *
39
- * @param value
40
- * @returns true if the value is a state tree node.
41
- */
42
- export declare function isStateTreeNode<IT extends IAnyComplexType = IAnyComplexType>(value: any): value is STNValue<Instance<IT>, IT>;
43
- /**
44
- * @internal
45
- * @hidden
46
- */
47
- export declare function assertIsStateTreeNode(value: IAnyStateTreeNode, argNumber: number | number[]): void;
48
- /**
49
- * @internal
50
- * @hidden
51
- */
52
- export declare function getStateTreeNode(value: IAnyStateTreeNode): AnyObjectNode;
53
- /**
54
- * @internal
55
- * @hidden
56
- */
57
- export declare function getStateTreeNodeSafe(value: IAnyStateTreeNode): AnyObjectNode | null;
58
- /**
59
- * @internal
60
- * @hidden
61
- */
62
- export declare function toJSON<S>(this: IStateTreeNode<IType<any, S, any>>): S;
63
- /**
64
- * @internal
65
- * @hidden
66
- */
67
- export declare function getRelativePathBetweenNodes(base: AnyObjectNode, target: AnyObjectNode): string;
68
- /**
69
- * @internal
70
- * @hidden
71
- */
72
- export declare function resolveNodeByPath(base: AnyObjectNode, path: string, failIfResolveFails?: boolean): AnyNode | undefined;
73
- /**
74
- * @internal
75
- * @hidden
76
- */
77
- export declare function resolveNodeByPathParts(base: AnyObjectNode, pathParts: string[], failIfResolveFails?: boolean): AnyNode | undefined;
78
- /**
79
- * @internal
80
- * @hidden
81
- */
82
- export declare function convertChildNodesToArray(childNodes: IChildNodesMap | null): AnyNode[];
83
- export {};
@@ -1,165 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.NodeLifeCycle = void 0;
4
- exports.isStateTreeNode = isStateTreeNode;
5
- exports.assertIsStateTreeNode = assertIsStateTreeNode;
6
- exports.getStateTreeNode = getStateTreeNode;
7
- exports.getStateTreeNodeSafe = getStateTreeNodeSafe;
8
- exports.toJSON = toJSON;
9
- exports.getRelativePathBetweenNodes = getRelativePathBetweenNodes;
10
- exports.resolveNodeByPath = resolveNodeByPath;
11
- exports.resolveNodeByPathParts = resolveNodeByPathParts;
12
- exports.convertChildNodesToArray = convertChildNodesToArray;
13
- const internal_ts_1 = require("../../internal.js");
14
- /**
15
- * @internal
16
- * @hidden
17
- */
18
- var NodeLifeCycle;
19
- (function (NodeLifeCycle) {
20
- NodeLifeCycle[NodeLifeCycle["INITIALIZING"] = 0] = "INITIALIZING";
21
- NodeLifeCycle[NodeLifeCycle["CREATED"] = 1] = "CREATED";
22
- NodeLifeCycle[NodeLifeCycle["FINALIZED"] = 2] = "FINALIZED";
23
- NodeLifeCycle[NodeLifeCycle["DETACHING"] = 3] = "DETACHING";
24
- NodeLifeCycle[NodeLifeCycle["DEAD"] = 4] = "DEAD"; // no coming back from this one
25
- })(NodeLifeCycle || (exports.NodeLifeCycle = NodeLifeCycle = {}));
26
- /**
27
- * Returns true if the given value is a node in a state tree.
28
- * More precisely, that is, if the value is an instance of a
29
- * `types.model`, `types.array` or `types.map`.
30
- *
31
- * @param value
32
- * @returns true if the value is a state tree node.
33
- */
34
- function isStateTreeNode(value) {
35
- return !!(value && value.$treenode);
36
- }
37
- /**
38
- * @internal
39
- * @hidden
40
- */
41
- function assertIsStateTreeNode(value, argNumber) {
42
- (0, internal_ts_1.assertArg)(value, isStateTreeNode, "mobx-state-tree node", argNumber);
43
- }
44
- /**
45
- * @internal
46
- * @hidden
47
- */
48
- function getStateTreeNode(value) {
49
- if (!isStateTreeNode(value)) {
50
- // istanbul ignore next
51
- throw (0, internal_ts_1.fail)(`Value ${value} is no MST Node`);
52
- }
53
- return value.$treenode;
54
- }
55
- /**
56
- * @internal
57
- * @hidden
58
- */
59
- function getStateTreeNodeSafe(value) {
60
- return (value && value.$treenode) || null;
61
- }
62
- /**
63
- * @internal
64
- * @hidden
65
- */
66
- function toJSON() {
67
- return getStateTreeNode(this).snapshot;
68
- }
69
- const doubleDot = (_) => "..";
70
- /**
71
- * @internal
72
- * @hidden
73
- */
74
- function getRelativePathBetweenNodes(base, target) {
75
- // PRE condition target is (a child of) base!
76
- if (base.root !== target.root) {
77
- throw (0, internal_ts_1.fail)(`Cannot calculate relative path: objects '${base}' and '${target}' are not part of the same object tree`);
78
- }
79
- const baseParts = (0, internal_ts_1.splitJsonPath)(base.path);
80
- const targetParts = (0, internal_ts_1.splitJsonPath)(target.path);
81
- let common = 0;
82
- for (; common < baseParts.length; common++) {
83
- if (baseParts[common] !== targetParts[common]) {
84
- break;
85
- }
86
- }
87
- // TODO: assert that no targetParts paths are "..", "." or ""!
88
- return (baseParts.slice(common).map(doubleDot).join("/") +
89
- (0, internal_ts_1.joinJsonPath)(targetParts.slice(common)));
90
- }
91
- /**
92
- * @internal
93
- * @hidden
94
- */
95
- function resolveNodeByPath(base, path, failIfResolveFails = true) {
96
- return resolveNodeByPathParts(base, (0, internal_ts_1.splitJsonPath)(path), failIfResolveFails);
97
- }
98
- /**
99
- * @internal
100
- * @hidden
101
- */
102
- function resolveNodeByPathParts(base, pathParts, failIfResolveFails = true) {
103
- let current = base;
104
- try {
105
- for (let i = 0; i < pathParts.length; i++) {
106
- const part = pathParts[i];
107
- if (part === "..") {
108
- current = current.parent;
109
- if (current) {
110
- continue;
111
- } // not everything has a parent
112
- }
113
- else if (part === ".") {
114
- continue;
115
- }
116
- else if (current) {
117
- if (current instanceof internal_ts_1.ScalarNode) {
118
- // check if the value of a scalar resolves to a state tree node (e.g. references)
119
- // then we can continue resolving...
120
- const value = current.value;
121
- if (isStateTreeNode(value)) {
122
- current = getStateTreeNode(value);
123
- // fall through
124
- }
125
- }
126
- if (current instanceof internal_ts_1.ObjectNode) {
127
- const subType = current.getChildType(part);
128
- if (subType) {
129
- current = current.getChildNode(part);
130
- if (current) {
131
- continue;
132
- }
133
- }
134
- }
135
- }
136
- throw (0, internal_ts_1.fail)(`Could not resolve '${part}' in path '${(0, internal_ts_1.joinJsonPath)(pathParts.slice(0, i)) || "/"}' while resolving '${(0, internal_ts_1.joinJsonPath)(pathParts)}'`);
137
- }
138
- }
139
- catch (e) {
140
- if (!failIfResolveFails) {
141
- return undefined;
142
- }
143
- throw e;
144
- }
145
- return current;
146
- }
147
- /**
148
- * @internal
149
- * @hidden
150
- */
151
- function convertChildNodesToArray(childNodes) {
152
- if (!childNodes) {
153
- return internal_ts_1.EMPTY_ARRAY;
154
- }
155
- const keys = Object.keys(childNodes);
156
- if (!keys.length) {
157
- return internal_ts_1.EMPTY_ARRAY;
158
- }
159
- const result = new Array(keys.length);
160
- keys.forEach((key, index) => {
161
- result[index] = childNodes[key];
162
- });
163
- return result;
164
- }
165
- //# sourceMappingURL=node-utils.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"node-utils.js","sourceRoot":"","sources":["../../../src/core/node/node-utils.ts"],"names":[],"mappings":";;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AAED;;;GAGG;AACH,SAAgB,wBAAwB,CACtC,UAAiC;IAEjC,IAAI,CAAC,UAAU,EAAE,CAAC;QAChB,OAAO,yBAAwB,CAAA;IACjC,CAAC;IAED,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAA;IACpC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;QACjB,OAAO,yBAAwB,CAAA;IACjC,CAAC;IAED,MAAM,MAAM,GAAG,IAAI,KAAK,CAAC,IAAI,CAAC,MAAM,CAAc,CAAA;IAClD,IAAI,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE;QAC1B,MAAM,CAAC,KAAK,CAAC,GAAG,UAAW,CAAC,GAAG,CAAC,CAAA;IAClC,CAAC,CAAC,CAAA;IACF,OAAO,MAAM,CAAA;AACf,CAAC","sourcesContent":["import {\n EMPTY_ARRAY,\n ObjectNode,\n ScalarNode,\n assertArg,\n fail,\n joinJsonPath,\n splitJsonPath\n} from \"../../internal.ts\"\n\nimport type {\n AnyNode,\n AnyObjectNode,\n IAnyComplexType,\n IAnyType,\n IChildNodesMap,\n IType,\n Instance,\n STNValue\n} from \"../../internal.ts\"\n\n/**\n * @internal\n * @hidden\n */\nexport enum NodeLifeCycle {\n INITIALIZING, // setting up\n CREATED, // afterCreate has run\n FINALIZED, // afterAttach has run\n DETACHING, // being detached from the tree\n DEAD // no coming back from this one\n}\n\n/** @hidden */\ndeclare const $stateTreeNodeType: unique symbol\n\n/**\n * Common interface that represents a node instance.\n * @hidden\n */\nexport interface IStateTreeNode<IT extends IAnyType = IAnyType> {\n /**\n * @internal\n */\n readonly $treenode?: any\n\n // fake, will never be present, just for typing\n // we use this weird trick to solve an issue with reference types\n readonly [$stateTreeNodeType]?: [IT] | [any]\n}\n\n/** @hidden */\nexport type TypeOfValue<T extends IAnyStateTreeNode> =\n T extends IStateTreeNode<infer IT> ? IT : never\n\n/**\n * Represents any state tree node instance.\n * @hidden\n */\nexport interface IAnyStateTreeNode extends STNValue<any, IAnyType> {}\n\n/**\n * Returns true if the given value is a node in a state tree.\n * More precisely, that is, if the value is an instance of a\n * `types.model`, `types.array` or `types.map`.\n *\n * @param value\n * @returns true if the value is a state tree node.\n */\nexport function isStateTreeNode<IT extends IAnyComplexType = IAnyComplexType>(\n value: any\n): value is STNValue<Instance<IT>, IT> {\n return !!(value && value.$treenode)\n}\n\n/**\n * @internal\n * @hidden\n */\nexport function assertIsStateTreeNode(\n value: IAnyStateTreeNode,\n argNumber: number | number[]\n): void {\n assertArg(value, isStateTreeNode, \"mobx-state-tree node\", argNumber)\n}\n\n/**\n * @internal\n * @hidden\n */\nexport function getStateTreeNode(value: IAnyStateTreeNode): AnyObjectNode {\n if (!isStateTreeNode(value)) {\n // istanbul ignore next\n throw fail(`Value ${value} is no MST Node`)\n }\n return value.$treenode!\n}\n\n/**\n * @internal\n * @hidden\n */\nexport function getStateTreeNodeSafe(\n value: IAnyStateTreeNode\n): AnyObjectNode | null {\n return (value && value.$treenode) || null\n}\n\n/**\n * @internal\n * @hidden\n */\nexport function toJSON<S>(this: IStateTreeNode<IType<any, S, any>>): S {\n return getStateTreeNode(this).snapshot\n}\n\nconst doubleDot = (_: any) => \"..\"\n\n/**\n * @internal\n * @hidden\n */\nexport function getRelativePathBetweenNodes(\n base: AnyObjectNode,\n target: AnyObjectNode\n): string {\n // PRE condition target is (a child of) base!\n if (base.root !== target.root) {\n throw fail(\n `Cannot calculate relative path: objects '${base}' and '${target}' are not part of the same object tree`\n )\n }\n\n const baseParts = splitJsonPath(base.path)\n const targetParts = splitJsonPath(target.path)\n let common = 0\n for (; common < baseParts.length; common++) {\n if (baseParts[common] !== targetParts[common]) {\n break\n }\n }\n // TODO: assert that no targetParts paths are \"..\", \".\" or \"\"!\n return (\n baseParts.slice(common).map(doubleDot).join(\"/\") +\n joinJsonPath(targetParts.slice(common))\n )\n}\n\n/**\n * @internal\n * @hidden\n */\nexport function resolveNodeByPath(\n base: AnyObjectNode,\n path: string,\n failIfResolveFails: boolean = true\n): AnyNode | undefined {\n return resolveNodeByPathParts(base, splitJsonPath(path), failIfResolveFails)\n}\n\n/**\n * @internal\n * @hidden\n */\nexport function resolveNodeByPathParts(\n base: AnyObjectNode,\n pathParts: string[],\n failIfResolveFails: boolean = true\n): AnyNode | undefined {\n let current: AnyNode | null = base\n try {\n for (let i = 0; i < pathParts.length; i++) {\n const part = pathParts[i]\n if (part === \"..\") {\n current = current!.parent\n if (current) {\n continue\n } // not everything has a parent\n } else if (part === \".\") {\n continue\n } else if (current) {\n if (current instanceof ScalarNode) {\n // check if the value of a scalar resolves to a state tree node (e.g. references)\n // then we can continue resolving...\n const value: any = current.value\n if (isStateTreeNode(value)) {\n current = getStateTreeNode(value)\n // fall through\n }\n }\n if (current instanceof ObjectNode) {\n const subType = current.getChildType(part)\n if (subType) {\n current = current.getChildNode(part)\n if (current) {\n continue\n }\n }\n }\n }\n throw fail(\n `Could not resolve '${part}' in path '${\n joinJsonPath(pathParts.slice(0, i)) || \"/\"\n }' while resolving '${joinJsonPath(pathParts)}'`\n )\n }\n } catch (e) {\n if (!failIfResolveFails) {\n return undefined\n }\n throw e\n }\n return current!\n}\n\n/**\n * @internal\n * @hidden\n */\nexport function convertChildNodesToArray(\n childNodes: IChildNodesMap | null\n): AnyNode[] {\n if (!childNodes) {\n return EMPTY_ARRAY as AnyNode[]\n }\n\n const keys = Object.keys(childNodes)\n if (!keys.length) {\n return EMPTY_ARRAY as AnyNode[]\n }\n\n const result = new Array(keys.length) as AnyNode[]\n keys.forEach((key, index) => {\n result[index] = childNodes![key]\n })\n return result\n}\n"]}
@@ -1,101 +0,0 @@
1
- import { BaseNode } from "./BaseNode.ts";
2
- import { ComplexType } from "../type/type.ts";
3
- import { Hook, IdentifierCache } from "../../internal.ts";
4
- import type { AnyNode, IAnyType, IDisposer, IJsonPatch, IMiddleware, IMiddlewareEvent, IMiddlewareHandler, IReversibleJsonPatch, IStateTreeNode, IType, ReferenceIdentifier } from "../../internal.ts";
5
- /**
6
- * @internal
7
- * @hidden
8
- */
9
- export interface IChildNodesMap {
10
- [key: string]: AnyNode;
11
- }
12
- /**
13
- * @internal
14
- * @hidden
15
- */
16
- export declare class ObjectNode<C, S, T> extends BaseNode<C, S, T> {
17
- readonly type: ComplexType<C, S, T>;
18
- storedValue: T & IStateTreeNode<IType<C, S, T>>;
19
- readonly nodeId: number;
20
- readonly identifierAttribute?: string;
21
- readonly identifier: string | null;
22
- readonly unnormalizedIdentifier: ReferenceIdentifier | null;
23
- identifierCache?: IdentifierCache;
24
- isProtectionEnabled: boolean;
25
- middlewares?: IMiddleware[];
26
- hasSnapshotPostProcessor: boolean;
27
- private _applyPatches?;
28
- applyPatches(patches: IJsonPatch[]): void;
29
- private _applySnapshot?;
30
- applySnapshot(snapshot: C): void;
31
- private _autoUnbox;
32
- _isRunningAction: boolean;
33
- private _hasSnapshotReaction;
34
- private _observableInstanceState;
35
- private _childNodes;
36
- private _initialSnapshot;
37
- private _cachedInitialSnapshot?;
38
- private _cachedInitialSnapshotCreated;
39
- private _snapshotComputed;
40
- constructor(complexType: ComplexType<C, S, T>, parent: AnyObjectNode | null, subpath: string, environment: any, initialValue: C);
41
- createObservableInstanceIfNeeded(fireHooks?: boolean): void;
42
- createObservableInstance(fireHooks?: boolean): void;
43
- get root(): AnyObjectNode;
44
- clearParent(): void;
45
- setParent(newParent: AnyObjectNode, subpath: string): void;
46
- protected fireHook(name: Hook): void;
47
- private _snapshotUponDeath?;
48
- get snapshot(): S;
49
- getSnapshot(): S;
50
- private _getActualSnapshot;
51
- private _getCachedInitialSnapshot;
52
- private isRunningAction;
53
- assertAlive(context: AssertAliveContext): void;
54
- private _getAssertAliveError;
55
- getChildNode(subpath: string): AnyNode;
56
- getChildren(): ReadonlyArray<AnyNode>;
57
- getChildType(propertyName?: string): IAnyType;
58
- get isProtected(): boolean;
59
- assertWritable(context: AssertAliveContext): void;
60
- removeChild(subpath: string): void;
61
- unbox(childNode: AnyNode | undefined): AnyNode | undefined;
62
- toString(): string;
63
- finalizeCreation(): void;
64
- detach(): void;
65
- private preboot;
66
- die(): void;
67
- aboutToDie(): void;
68
- finalizeDeath(): void;
69
- onSnapshot(onChange: (snapshot: S) => void): IDisposer;
70
- protected emitSnapshot(snapshot: S): void;
71
- onPatch(handler: (patch: IJsonPatch, reversePatch: IJsonPatch) => void): IDisposer;
72
- emitPatch(basePatch: IReversibleJsonPatch, source: AnyNode): void;
73
- hasDisposer(disposer: () => void): boolean;
74
- addDisposer(disposer: () => void): void;
75
- removeDisposer(disposer: () => void): void;
76
- private removeMiddleware;
77
- addMiddleWare(handler: IMiddlewareHandler, includeHooks?: boolean): IDisposer;
78
- applyPatchLocally(subpath: string, patch: IJsonPatch): void;
79
- private _addSnapshotReaction;
80
- private _internalEvents?;
81
- private _internalEventsHasSubscribers;
82
- private _internalEventsRegister;
83
- private _internalEventsHas;
84
- private _internalEventsUnregister;
85
- private _internalEventsEmit;
86
- private _internalEventsClear;
87
- private _internalEventsClearAll;
88
- }
89
- /**
90
- * @internal
91
- * @hidden
92
- */
93
- export type AnyObjectNode = ObjectNode<any, any, any>;
94
- /**
95
- * @internal
96
- * @hidden
97
- */
98
- export interface AssertAliveContext {
99
- subpath?: string;
100
- actionContext?: IMiddlewareEvent;
101
- }