@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,317 +0,0 @@
1
- import { BaseNode } from "../../internal.ts";
2
- import type { AnyNode, AnyObjectNode, IChildNodesMap, IJsonPatch, IStateTreeNode, IValidationContext, IValidationResult, ModelPrimitive, ObjectNode, ScalarNode } from "../../internal.ts";
3
- /**
4
- * @internal
5
- * @hidden
6
- */
7
- export declare enum TypeFlags {
8
- String = 1,
9
- Number = 2,
10
- Boolean = 4,
11
- Date = 8,
12
- Literal = 16,
13
- Array = 32,
14
- Map = 64,
15
- Object = 128,
16
- Frozen = 256,
17
- Optional = 512,
18
- Reference = 1024,
19
- Identifier = 2048,
20
- Late = 4096,
21
- Refinement = 8192,
22
- Union = 16384,
23
- Null = 32768,
24
- Undefined = 65536,
25
- Integer = 131072,
26
- Custom = 262144,
27
- SnapshotProcessor = 524288,
28
- Lazy = 1048576,
29
- Finite = 2097152,
30
- Float = 4194304
31
- }
32
- /**
33
- * @internal
34
- * @hidden
35
- */
36
- export declare const cannotDetermineSubtype = "cannotDetermine";
37
- /**
38
- * A state tree node value.
39
- * @hidden
40
- */
41
- export type STNValue<T, IT extends IAnyType> = T extends object ? T & IStateTreeNode<IT> : T;
42
- /** @hidden */
43
- declare const $type: unique symbol;
44
- /**
45
- * A type, either complex or simple.
46
- */
47
- export interface IType<C, S, T> {
48
- /** @hidden */
49
- readonly [$type]: undefined;
50
- /**
51
- * Friendly type name.
52
- */
53
- name: string;
54
- /**
55
- * Name of the identifier attribute or null if none.
56
- */
57
- readonly identifierAttribute?: string;
58
- /**
59
- * Creates an instance for the type given an snapshot input.
60
- *
61
- * @returns An instance of that type.
62
- */
63
- create(snapshot?: C, env?: any): this["Type"];
64
- /**
65
- * Checks if a given snapshot / instance is of the given type.
66
- *
67
- * @param thing Snapshot or instance to be checked.
68
- * @returns true if the value is of the current type, false otherwise.
69
- */
70
- is(thing: any): thing is C | this["Type"];
71
- /**
72
- * Run's the type's typechecker on the given value with the given validation context.
73
- *
74
- * @param thing Value to be checked, either a snapshot or an instance.
75
- * @param context Validation context, an array of { subpaths, subtypes } that should be validated
76
- * @returns The validation result, an array with the list of validation errors.
77
- */
78
- validate(thing: C, context: IValidationContext): IValidationResult;
79
- /**
80
- * Gets the textual representation of the type as a string.
81
- */
82
- describe(): string;
83
- /**
84
- * @deprecated use `Instance<typeof MyType>` instead.
85
- * @hidden
86
- */
87
- readonly Type: STNValue<T, this>;
88
- /**
89
- * @deprecated do not use.
90
- * @hidden
91
- */
92
- readonly TypeWithoutSTN: T;
93
- /**
94
- * @deprecated use `SnapshotOut<typeof MyType>` instead.
95
- * @hidden
96
- */
97
- readonly SnapshotType: S;
98
- /**
99
- * @deprecated use `SnapshotIn<typeof MyType>` instead.
100
- * @hidden
101
- */
102
- readonly CreationType: C;
103
- /**
104
- * @internal
105
- * @hidden
106
- */
107
- flags: TypeFlags;
108
- /**
109
- * @internal
110
- * @hidden
111
- */
112
- isType: true;
113
- /**
114
- * @internal
115
- * @hidden
116
- */
117
- instantiate(parent: AnyObjectNode | null, subpath: string, environment: any, initialValue: C | T): BaseNode<C, S, T>;
118
- /**
119
- * @internal
120
- * @hidden
121
- */
122
- reconcile(current: BaseNode<C, S, T>, newValue: C | T, parent: AnyObjectNode, subpath: string): BaseNode<C, S, T>;
123
- /**
124
- * @internal
125
- * @hidden
126
- */
127
- getSnapshot(node: BaseNode<C, S, T>, applyPostProcess?: boolean): S;
128
- /**
129
- * @internal
130
- * @hidden
131
- */
132
- isAssignableFrom(type: IAnyType): boolean;
133
- /**
134
- * @internal
135
- * @hidden
136
- */
137
- getSubTypes(): IAnyType[] | IAnyType | null | typeof cannotDetermineSubtype;
138
- }
139
- /**
140
- * Any kind of type.
141
- */
142
- export interface IAnyType extends IType<any, any, any> {
143
- }
144
- /**
145
- * A simple type, this is, a type where the instance and the snapshot representation are the same.
146
- */
147
- export interface ISimpleType<T> extends IType<T, T, T> {
148
- }
149
- /** @hidden */
150
- export type Primitives = ModelPrimitive | null | undefined;
151
- /**
152
- * A complex type.
153
- * @deprecated just for compatibility with old versions, could be deprecated on the next major version
154
- * @hidden
155
- */
156
- export interface IComplexType<C, S, T> extends IType<C, S, T & object> {
157
- }
158
- /**
159
- * Any kind of complex type.
160
- */
161
- export interface IAnyComplexType extends IType<any, any, object> {
162
- }
163
- /** @hidden */
164
- export type ExtractCSTWithoutSTN<IT extends {
165
- [$type]: undefined;
166
- CreationType: any;
167
- SnapshotType: any;
168
- TypeWithoutSTN: any;
169
- }> = IT["CreationType"] | IT["SnapshotType"] | IT["TypeWithoutSTN"];
170
- /** @hidden */
171
- export type ExtractCSTWithSTN<IT extends {
172
- [$type]: undefined;
173
- CreationType: any;
174
- SnapshotType: any;
175
- Type: any;
176
- }> = IT["CreationType"] | IT["SnapshotType"] | IT["Type"];
177
- /**
178
- * The instance representation of a given type.
179
- */
180
- export type Instance<T> = T extends {
181
- [$type]: undefined;
182
- Type: any;
183
- } ? T["Type"] : T;
184
- /**
185
- * The input (creation) snapshot representation of a given type.
186
- */
187
- export type SnapshotIn<T> = T extends {
188
- [$type]: undefined;
189
- CreationType: any;
190
- } ? T["CreationType"] : T extends IStateTreeNode<infer IT> ? IT["CreationType"] : T;
191
- /**
192
- * The output snapshot representation of a given type.
193
- */
194
- export type SnapshotOut<T> = T extends {
195
- [$type]: undefined;
196
- SnapshotType: any;
197
- } ? T["SnapshotType"] : T extends IStateTreeNode<infer IT> ? IT["SnapshotType"] : T;
198
- /**
199
- * A type which is equivalent to the union of SnapshotIn and Instance types of a given typeof TYPE or typeof VARIABLE.
200
- * For primitives it defaults to the primitive itself.
201
- *
202
- * For example:
203
- * - `SnapshotOrInstance<typeof ModelA> = SnapshotIn<typeof ModelA> | Instance<typeof ModelA>`
204
- * - `SnapshotOrInstance<typeof self.a (where self.a is a ModelA)> = SnapshotIn<typeof ModelA> | Instance<typeof ModelA>`
205
- *
206
- * Usually you might want to use this when your model has a setter action that sets a property.
207
- *
208
- * Example:
209
- * ```ts
210
- * const ModelA = types.model({
211
- * n: types.number
212
- * })
213
- *
214
- * const ModelB = types.model({
215
- * innerModel: ModelA
216
- * }).actions(self => ({
217
- * // this will accept as property both the snapshot and the instance, whichever is preferred
218
- * setInnerModel(m: SnapshotOrInstance<typeof self.innerModel>) {
219
- * self.innerModel = cast(m)
220
- * }
221
- * }))
222
- * ```
223
- */
224
- export type SnapshotOrInstance<T> = SnapshotIn<T> | Instance<T>;
225
- /**
226
- * A base type produces a MST node (Node in the state tree)
227
- *
228
- * @internal
229
- * @hidden
230
- */
231
- export declare abstract class BaseType<C, S, T, N extends BaseNode<any, any, any> = BaseNode<C, S, T>> implements IType<C, S, T> {
232
- [$type]: undefined;
233
- readonly C: C;
234
- readonly S: S;
235
- readonly T: T;
236
- readonly N: N;
237
- readonly isType = true;
238
- readonly name: string;
239
- constructor(name: string);
240
- create(snapshot?: C, environment?: any): any;
241
- getSnapshot(_node: N, _applyPostProcess?: boolean): S;
242
- abstract reconcile(current: N, newValue: C | T, parent: AnyObjectNode, subpath: string): N;
243
- abstract instantiate(parent: AnyObjectNode | null, subpath: string, environment: any, initialValue: C | T): N;
244
- abstract flags: TypeFlags;
245
- abstract describe(): string;
246
- abstract isValidSnapshot(value: C, context: IValidationContext): IValidationResult;
247
- isAssignableFrom(type: IAnyType): boolean;
248
- validate(value: C | T, context: IValidationContext): IValidationResult;
249
- is(thing: any): thing is any;
250
- get Type(): any;
251
- get TypeWithoutSTN(): any;
252
- get SnapshotType(): any;
253
- get CreationType(): any;
254
- abstract getSubTypes(): IAnyType[] | IAnyType | null | typeof cannotDetermineSubtype;
255
- }
256
- /**
257
- * @internal
258
- * @hidden
259
- */
260
- export type AnyBaseType = BaseType<any, any, any, any>;
261
- /**
262
- * @internal
263
- * @hidden
264
- */
265
- export type ExtractNodeType<IT extends IAnyType> = IT extends BaseType<any, any, any, infer N> ? N : never;
266
- /**
267
- * A complex type produces a MST node (Node in the state tree)
268
- *
269
- * @internal
270
- * @hidden
271
- */
272
- export declare abstract class ComplexType<C, S, T> extends BaseType<C, S, T, ObjectNode<C, S, T>> {
273
- identifierAttribute?: string;
274
- constructor(name: string);
275
- create(snapshot?: C, environment?: any): any;
276
- getValue(node: this["N"]): T;
277
- abstract getDefaultSnapshot(): C;
278
- abstract createNewInstance(childNodes: IChildNodesMap): T;
279
- abstract finalizeNewInstance(node: this["N"], instance: any): void;
280
- abstract applySnapshot(node: this["N"], snapshot: C): void;
281
- abstract applyPatchLocally(node: this["N"], subpath: string, patch: IJsonPatch): void;
282
- abstract processInitialSnapshot(childNodes: IChildNodesMap, snapshot: C): S;
283
- abstract getChildren(node: this["N"]): ReadonlyArray<AnyNode>;
284
- abstract getChildNode(node: this["N"], key: string): AnyNode;
285
- abstract getChildType(propertyName?: string): IAnyType;
286
- abstract initializeChildNodes(node: this["N"], snapshot: any): IChildNodesMap;
287
- abstract removeChild(node: this["N"], subpath: string): void;
288
- isMatchingSnapshotId(current: this["N"], snapshot: C): boolean;
289
- private tryToReconcileNode;
290
- reconcile(current: this["N"], newValue: C | T, parent: AnyObjectNode, subpath: string): this["N"];
291
- getSubTypes(): null;
292
- }
293
- /**
294
- * @internal
295
- * @hidden
296
- */
297
- export declare abstract class SimpleType<C, S, T> extends BaseType<C, S, T, ScalarNode<C, S, T>> {
298
- abstract instantiate(parent: AnyObjectNode | null, subpath: string, environment: any, initialValue: C): this["N"];
299
- createNewInstance(snapshot: C): T;
300
- getValue(node: this["N"]): T;
301
- getSnapshot(node: this["N"]): S;
302
- reconcile(current: this["N"], newValue: C, parent: AnyObjectNode, subpath: string): this["N"];
303
- getSubTypes(): null;
304
- }
305
- /**
306
- * Returns if a given value represents a type.
307
- *
308
- * @param value Value to check.
309
- * @returns `true` if the value is a type.
310
- */
311
- export declare function isType(value: any): value is IAnyType;
312
- /**
313
- * @internal
314
- * @hidden
315
- */
316
- export declare function assertIsType(type: IAnyType, argNumber: number | number[]): void;
317
- export {};
@@ -1,251 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SimpleType = exports.ComplexType = exports.BaseType = exports.cannotDetermineSubtype = exports.TypeFlags = void 0;
4
- exports.isType = isType;
5
- exports.assertIsType = assertIsType;
6
- const mobx_1 = require("mobx");
7
- const internal_ts_1 = require("../../internal.js");
8
- // Cache for validation results to avoid re-validating the same object against the same type
9
- // Uses WeakMap so cached objects can be garbage collected
10
- const validationCache = new WeakMap();
11
- /**
12
- * @internal
13
- * @hidden
14
- */
15
- var TypeFlags;
16
- (function (TypeFlags) {
17
- TypeFlags[TypeFlags["String"] = 1] = "String";
18
- TypeFlags[TypeFlags["Number"] = 2] = "Number";
19
- TypeFlags[TypeFlags["Boolean"] = 4] = "Boolean";
20
- TypeFlags[TypeFlags["Date"] = 8] = "Date";
21
- TypeFlags[TypeFlags["Literal"] = 16] = "Literal";
22
- TypeFlags[TypeFlags["Array"] = 32] = "Array";
23
- TypeFlags[TypeFlags["Map"] = 64] = "Map";
24
- TypeFlags[TypeFlags["Object"] = 128] = "Object";
25
- TypeFlags[TypeFlags["Frozen"] = 256] = "Frozen";
26
- TypeFlags[TypeFlags["Optional"] = 512] = "Optional";
27
- TypeFlags[TypeFlags["Reference"] = 1024] = "Reference";
28
- TypeFlags[TypeFlags["Identifier"] = 2048] = "Identifier";
29
- TypeFlags[TypeFlags["Late"] = 4096] = "Late";
30
- TypeFlags[TypeFlags["Refinement"] = 8192] = "Refinement";
31
- TypeFlags[TypeFlags["Union"] = 16384] = "Union";
32
- TypeFlags[TypeFlags["Null"] = 32768] = "Null";
33
- TypeFlags[TypeFlags["Undefined"] = 65536] = "Undefined";
34
- TypeFlags[TypeFlags["Integer"] = 131072] = "Integer";
35
- TypeFlags[TypeFlags["Custom"] = 262144] = "Custom";
36
- TypeFlags[TypeFlags["SnapshotProcessor"] = 524288] = "SnapshotProcessor";
37
- TypeFlags[TypeFlags["Lazy"] = 1048576] = "Lazy";
38
- TypeFlags[TypeFlags["Finite"] = 2097152] = "Finite";
39
- TypeFlags[TypeFlags["Float"] = 4194304] = "Float";
40
- })(TypeFlags || (exports.TypeFlags = TypeFlags = {}));
41
- /**
42
- * @internal
43
- * @hidden
44
- */
45
- exports.cannotDetermineSubtype = "cannotDetermine";
46
- /** @hidden */
47
- const $type = Symbol("$type");
48
- /**
49
- * A base type produces a MST node (Node in the state tree)
50
- *
51
- * @internal
52
- * @hidden
53
- */
54
- class BaseType {
55
- [$type];
56
- // these are just to make inner types avaialable to inherited classes
57
- C;
58
- S;
59
- T;
60
- N;
61
- isType = true;
62
- name;
63
- constructor(name) {
64
- this.name = name;
65
- }
66
- create(snapshot, environment) {
67
- (0, internal_ts_1.typecheckInternal)(this, snapshot);
68
- return this.instantiate(null, "", environment, snapshot).value;
69
- }
70
- getSnapshot(_node, _applyPostProcess) {
71
- // istanbul ignore next
72
- throw (0, internal_ts_1.fail)("unimplemented method");
73
- }
74
- isAssignableFrom(type) {
75
- return type === this;
76
- }
77
- validate(value, context) {
78
- const node = (0, internal_ts_1.getStateTreeNodeSafe)(value);
79
- if (node) {
80
- const valueType = (0, internal_ts_1.getType)(value);
81
- return this.isAssignableFrom(valueType)
82
- ? (0, internal_ts_1.typeCheckSuccess)()
83
- : (0, internal_ts_1.typeCheckFailure)(context, value);
84
- // it is tempting to compare snapshots, but in that case we should always clone on assignments...
85
- }
86
- // check cache for object values (only at root level to avoid context mismatches)
87
- if (typeof value === "object" && value !== null && context.length === 1) {
88
- const typeCache = validationCache.get(value);
89
- if (typeCache) {
90
- const cached = typeCache.get(this);
91
- if (cached !== undefined) {
92
- return cached;
93
- }
94
- }
95
- }
96
- const result = this.isValidSnapshot(value, context);
97
- // cache result for object values (only at root level)
98
- if (typeof value === "object" && value !== null && context.length === 1) {
99
- let typeCache = validationCache.get(value);
100
- if (!typeCache) {
101
- typeCache = new WeakMap();
102
- validationCache.set(value, typeCache);
103
- }
104
- typeCache.set(this, result);
105
- }
106
- return result;
107
- }
108
- is(thing) {
109
- return this.validate(thing, [{ path: "", type: this }]).length === 0;
110
- }
111
- get Type() {
112
- // istanbul ignore next
113
- throw (0, internal_ts_1.fail)("Factory.Type should not be actually called. It is just a Type signature that can be used at compile time with Typescript, by using `typeof type.Type`");
114
- }
115
- get TypeWithoutSTN() {
116
- // istanbul ignore next
117
- throw (0, internal_ts_1.fail)("Factory.TypeWithoutSTN should not be actually called. It is just a Type signature that can be used at compile time with Typescript, by using `typeof type.TypeWithoutSTN`");
118
- }
119
- get SnapshotType() {
120
- // istanbul ignore next
121
- throw (0, internal_ts_1.fail)("Factory.SnapshotType should not be actually called. It is just a Type signature that can be used at compile time with Typescript, by using `typeof type.SnapshotType`");
122
- }
123
- get CreationType() {
124
- // istanbul ignore next
125
- throw (0, internal_ts_1.fail)("Factory.CreationType should not be actually called. It is just a Type signature that can be used at compile time with Typescript, by using `typeof type.CreationType`");
126
- }
127
- }
128
- exports.BaseType = BaseType;
129
- BaseType.prototype.create = (0, mobx_1.action)(BaseType.prototype.create);
130
- /**
131
- * A complex type produces a MST node (Node in the state tree)
132
- *
133
- * @internal
134
- * @hidden
135
- */
136
- class ComplexType extends BaseType {
137
- identifierAttribute;
138
- constructor(name) {
139
- super(name);
140
- }
141
- create(snapshot = this.getDefaultSnapshot(), environment) {
142
- return super.create(snapshot, environment);
143
- }
144
- getValue(node) {
145
- node.createObservableInstanceIfNeeded();
146
- return node.storedValue;
147
- }
148
- isMatchingSnapshotId(current, snapshot) {
149
- return (!current.identifierAttribute ||
150
- current.identifier ===
151
- (0, internal_ts_1.normalizeIdentifier)(snapshot[current.identifierAttribute]));
152
- }
153
- tryToReconcileNode(current, newValue) {
154
- if (current.isDetaching) {
155
- return false;
156
- }
157
- if (current.snapshot === newValue) {
158
- // newValue is the current snapshot of the node, noop
159
- return true;
160
- }
161
- if ((0, internal_ts_1.isStateTreeNode)(newValue) && (0, internal_ts_1.getStateTreeNode)(newValue) === current) {
162
- // the current node is the same as the new one
163
- return true;
164
- }
165
- if (current.type === this &&
166
- (0, internal_ts_1.isMutable)(newValue) &&
167
- !(0, internal_ts_1.isStateTreeNode)(newValue) &&
168
- this.isMatchingSnapshotId(current, newValue)) {
169
- // the newValue has no node, so can be treated like a snapshot
170
- // we can reconcile
171
- current.applySnapshot(newValue);
172
- return true;
173
- }
174
- return false;
175
- }
176
- reconcile(current, newValue, parent, subpath) {
177
- const nodeReconciled = this.tryToReconcileNode(current, newValue);
178
- if (nodeReconciled) {
179
- current.setParent(parent, subpath);
180
- return current;
181
- }
182
- // current node cannot be recycled in any way
183
- current.die(); // noop if detaching
184
- // attempt to reuse the new one
185
- if ((0, internal_ts_1.isStateTreeNode)(newValue) && this.isAssignableFrom((0, internal_ts_1.getType)(newValue))) {
186
- // newValue is a Node as well, move it here..
187
- const newNode = (0, internal_ts_1.getStateTreeNode)(newValue);
188
- newNode.setParent(parent, subpath);
189
- return newNode;
190
- }
191
- // nothing to do, we have to create a new node
192
- return this.instantiate(parent, subpath, undefined, newValue);
193
- }
194
- getSubTypes() {
195
- return null;
196
- }
197
- }
198
- exports.ComplexType = ComplexType;
199
- ComplexType.prototype.create = (0, mobx_1.action)(ComplexType.prototype.create);
200
- /**
201
- * @internal
202
- * @hidden
203
- */
204
- class SimpleType extends BaseType {
205
- createNewInstance(snapshot) {
206
- return snapshot;
207
- }
208
- getValue(node) {
209
- // if we ever find a case where scalar nodes can be accessed without iterating through its parent
210
- // uncomment this to make sure the parent chain is created when this is accessed
211
- // if (node.parent) {
212
- // node.parent.createObservableInstanceIfNeeded()
213
- // }
214
- return node.storedValue;
215
- }
216
- getSnapshot(node) {
217
- return node.storedValue;
218
- }
219
- reconcile(current, newValue, parent, subpath) {
220
- // reconcile only if type and value are still the same, and only if the node is not detaching
221
- if (!current.isDetaching &&
222
- current.type === this &&
223
- current.storedValue === newValue) {
224
- return current;
225
- }
226
- const res = this.instantiate(parent, subpath, undefined, newValue);
227
- current.die(); // noop if detaching
228
- return res;
229
- }
230
- getSubTypes() {
231
- return null;
232
- }
233
- }
234
- exports.SimpleType = SimpleType;
235
- /**
236
- * Returns if a given value represents a type.
237
- *
238
- * @param value Value to check.
239
- * @returns `true` if the value is a type.
240
- */
241
- function isType(value) {
242
- return typeof value === "object" && value && value.isType === true;
243
- }
244
- /**
245
- * @internal
246
- * @hidden
247
- */
248
- function assertIsType(type, argNumber) {
249
- (0, internal_ts_1.assertArg)(type, isType, "mobx-state-tree type", argNumber);
250
- }
251
- //# sourceMappingURL=type.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"type.js","sourceRoot":"","sources":["../../../src/core/type/type.ts"],"names":[],"mappings":";;;AAinBA,wBAEC;AAMD,oCAEC;AA3nBD,+BAA6B;AAE7B,mDAa0B;AAE1B,4FAA4F;AAC5F,0DAA0D;AAC1D,MAAM,eAAe,GAAG,IAAI,OAAO,EAGhC,CAAA;AAeH;;;GAGG;AACH,IAAY,SAwBX;AAxBD,WAAY,SAAS;IACnB,6CAAU,CAAA;IACV,6CAAe,CAAA;IACf,+CAAgB,CAAA;IAChB,yCAAa,CAAA;IACb,gDAAgB,CAAA;IAChB,4CAAc,CAAA;IACd,wCAAY,CAAA;IACZ,+CAAe,CAAA;IACf,+CAAe,CAAA;IACf,mDAAiB,CAAA;IACjB,sDAAmB,CAAA;IACnB,wDAAoB,CAAA;I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,KAAK,KAAK,QAAQ,IAAI,KAAK,IAAI,KAAK,CAAC,MAAM,KAAK,IAAI,CAAA;AACpE,CAAC;AAED;;;GAGG;AACH,SAAgB,YAAY,CAAC,IAAc,EAAE,SAA4B;IACvE,IAAA,uBAAS,EAAC,IAAI,EAAE,MAAM,EAAE,sBAAsB,EAAE,SAAS,CAAC,CAAA;AAC5D,CAAC","sourcesContent":["import { action } from \"mobx\"\n\nimport {\n BaseNode,\n assertArg,\n fail,\n getStateTreeNode,\n getStateTreeNodeSafe,\n getType,\n isMutable,\n isStateTreeNode,\n normalizeIdentifier,\n typeCheckFailure,\n typeCheckSuccess,\n typecheckInternal\n} from \"../../internal.ts\"\n\n// Cache for validation results to avoid re-validating the same object against the same type\n// Uses WeakMap so cached objects can be garbage collected\nconst validationCache = new WeakMap<\n object,\n WeakMap<BaseType<any, any, any, any>, IValidationResult>\n>()\n\nimport type {\n AnyNode,\n AnyObjectNode,\n IChildNodesMap,\n IJsonPatch,\n IStateTreeNode,\n IValidationContext,\n IValidationResult,\n ModelPrimitive,\n ObjectNode,\n ScalarNode\n} from \"../../internal.ts\"\n\n/**\n * @internal\n * @hidden\n */\nexport enum TypeFlags {\n String = 1,\n Number = 1 << 1,\n Boolean = 1 << 2,\n Date = 1 << 3,\n Literal = 1 << 4,\n Array = 1 << 5,\n Map = 1 << 6,\n Object = 1 << 7,\n Frozen = 1 << 8,\n Optional = 1 << 9,\n Reference = 1 << 10,\n Identifier = 1 << 11,\n Late = 1 << 12,\n Refinement = 1 << 13,\n Union = 1 << 14,\n Null = 1 << 15,\n Undefined = 1 << 16,\n Integer = 1 << 17,\n Custom = 1 << 18,\n SnapshotProcessor = 1 << 19,\n Lazy = 1 << 20,\n Finite = 1 << 21,\n Float = 1 << 22\n}\n\n/**\n * @internal\n * @hidden\n */\nexport const cannotDetermineSubtype = \"cannotDetermine\"\n\n/**\n * A state tree node value.\n * @hidden\n */\nexport type STNValue<T, IT extends IAnyType> = T extends object\n ? T & IStateTreeNode<IT>\n : T\n\n/** @hidden */\nconst $type: unique symbol = Symbol(\"$type\")\n\n/**\n * A type, either complex or simple.\n */\nexport interface IType<C, S, T> {\n // fake, will never be present, just for typing\n /** @hidden */\n readonly [$type]: undefined\n\n /**\n * Friendly type name.\n */\n name: string\n\n /**\n * Name of the identifier attribute or null if none.\n */\n readonly identifierAttribute?: string\n\n /**\n * Creates an instance for the type given an snapshot input.\n *\n * @returns An instance of that type.\n */\n create(snapshot?: C, env?: any): this[\"Type\"]\n\n /**\n * Checks if a given snapshot / instance is of the given type.\n *\n * @param thing Snapshot or instance to be checked.\n * @returns true if the value is of the current type, false otherwise.\n */\n is(thing: any): thing is C | this[\"Type\"]\n\n /**\n * Run's the type's typechecker on the given value with the given validation context.\n *\n * @param thing Value to be checked, either a snapshot or an instance.\n * @param context Validation context, an array of { subpaths, subtypes } that should be validated\n * @returns The validation result, an array with the list of validation errors.\n */\n validate(thing: C, context: IValidationContext): IValidationResult\n\n /**\n * Gets the textual representation of the type as a string.\n */\n describe(): string\n\n /**\n * @deprecated use `Instance<typeof MyType>` instead.\n * @hidden\n */\n readonly Type: STNValue<T, this>\n\n /**\n * @deprecated do not use.\n * @hidden\n */\n readonly TypeWithoutSTN: T\n\n /**\n * @deprecated use `SnapshotOut<typeof MyType>` instead.\n * @hidden\n */\n readonly SnapshotType: S\n\n /**\n * @deprecated use `SnapshotIn<typeof MyType>` instead.\n * @hidden\n */\n readonly CreationType: C\n\n // Internal api's\n\n /**\n * @internal\n * @hidden\n */\n flags: TypeFlags\n /**\n * @internal\n * @hidden\n */\n isType: true\n /**\n * @internal\n * @hidden\n */\n instantiate(\n parent: AnyObjectNode | null,\n subpath: string,\n environment: any,\n initialValue: C | T\n ): BaseNode<C, S, T>\n /**\n * @internal\n * @hidden\n */\n reconcile(\n current: BaseNode<C, S, T>,\n newValue: C | T,\n parent: AnyObjectNode,\n subpath: string\n ): BaseNode<C, S, T>\n /**\n * @internal\n * @hidden\n */\n getSnapshot(node: BaseNode<C, S, T>, applyPostProcess?: boolean): S\n /**\n * @internal\n * @hidden\n */\n isAssignableFrom(type: IAnyType): boolean\n /**\n * @internal\n * @hidden\n */\n getSubTypes(): IAnyType[] | IAnyType | null | typeof cannotDetermineSubtype\n}\n\n/**\n * Any kind of type.\n */\nexport interface IAnyType extends IType<any, any, any> {}\n\n/**\n * A simple type, this is, a type where the instance and the snapshot representation are the same.\n */\nexport interface ISimpleType<T> extends IType<T, T, T> {}\n\n/** @hidden */\nexport type Primitives = ModelPrimitive | null | undefined\n\n/**\n * A complex type.\n * @deprecated just for compatibility with old versions, could be deprecated on the next major version\n * @hidden\n */\nexport interface IComplexType<C, S, T> extends IType<C, S, T & object> {}\n\n/**\n * Any kind of complex type.\n */\nexport interface IAnyComplexType extends IType<any, any, object> {}\n\n/** @hidden */\nexport type ExtractCSTWithoutSTN<\n IT extends {\n [$type]: undefined\n CreationType: any\n SnapshotType: any\n TypeWithoutSTN: any\n }\n> = IT[\"CreationType\"] | IT[\"SnapshotType\"] | IT[\"TypeWithoutSTN\"]\n/** @hidden */\nexport type ExtractCSTWithSTN<\n IT extends {\n [$type]: undefined\n CreationType: any\n SnapshotType: any\n Type: any\n }\n> = IT[\"CreationType\"] | IT[\"SnapshotType\"] | IT[\"Type\"]\n\n/**\n * The instance representation of a given type.\n */\nexport type Instance<T> = T extends { [$type]: undefined; Type: any }\n ? T[\"Type\"]\n : T\n\n/**\n * The input (creation) snapshot representation of a given type.\n */\nexport type SnapshotIn<T> = T extends { [$type]: undefined; CreationType: any }\n ? T[\"CreationType\"]\n : T extends IStateTreeNode<infer IT>\n ? IT[\"CreationType\"]\n : T\n\n/**\n * The output snapshot representation of a given type.\n */\nexport type SnapshotOut<T> = T extends { [$type]: undefined; SnapshotType: any }\n ? T[\"SnapshotType\"]\n : T extends IStateTreeNode<infer IT>\n ? IT[\"SnapshotType\"]\n : T\n\n/**\n * A type which is equivalent to the union of SnapshotIn and Instance types of a given typeof TYPE or typeof VARIABLE.\n * For primitives it defaults to the primitive itself.\n *\n * For example:\n * - `SnapshotOrInstance<typeof ModelA> = SnapshotIn<typeof ModelA> | Instance<typeof ModelA>`\n * - `SnapshotOrInstance<typeof self.a (where self.a is a ModelA)> = SnapshotIn<typeof ModelA> | Instance<typeof ModelA>`\n *\n * Usually you might want to use this when your model has a setter action that sets a property.\n *\n * Example:\n * ```ts\n * const ModelA = types.model({\n * n: types.number\n * })\n *\n * const ModelB = types.model({\n * innerModel: ModelA\n * }).actions(self => ({\n * // this will accept as property both the snapshot and the instance, whichever is preferred\n * setInnerModel(m: SnapshotOrInstance<typeof self.innerModel>) {\n * self.innerModel = cast(m)\n * }\n * }))\n * ```\n */\nexport type SnapshotOrInstance<T> = SnapshotIn<T> | Instance<T>\n\n/**\n * A base type produces a MST node (Node in the state tree)\n *\n * @internal\n * @hidden\n */\nexport abstract class BaseType<\n C,\n S,\n T,\n N extends BaseNode<any, any, any> = BaseNode<C, S, T>\n> implements IType<C, S, T> {\n [$type]!: undefined\n\n // these are just to make inner types avaialable to inherited classes\n readonly C!: C\n readonly S!: S\n readonly T!: T\n readonly N!: N\n\n readonly isType = true\n readonly name: string\n\n constructor(name: string) {\n this.name = name\n }\n\n create(snapshot?: C, environment?: any) {\n typecheckInternal(this, snapshot)\n return this.instantiate(null, \"\", environment, snapshot!).value\n }\n\n getSnapshot(_node: N, _applyPostProcess?: boolean): S {\n // istanbul ignore next\n throw fail(\"unimplemented method\")\n }\n\n abstract reconcile(\n current: N,\n newValue: C | T,\n parent: AnyObjectNode,\n subpath: string\n ): N\n\n abstract instantiate(\n parent: AnyObjectNode | null,\n subpath: string,\n environment: any,\n initialValue: C | T\n ): N\n\n declare abstract flags: TypeFlags\n abstract describe(): string\n\n abstract isValidSnapshot(\n value: C,\n context: IValidationContext\n ): IValidationResult\n\n isAssignableFrom(type: IAnyType): boolean {\n return type === this\n }\n\n validate(value: C | T, context: IValidationContext): IValidationResult {\n const node = getStateTreeNodeSafe(value)\n if (node) {\n const valueType = getType(value)\n return this.isAssignableFrom(valueType)\n ? typeCheckSuccess()\n : typeCheckFailure(context, value)\n // it is tempting to compare snapshots, but in that case we should always clone on assignments...\n }\n\n // check cache for object values (only at root level to avoid context mismatches)\n if (typeof value === \"object\" && value !== null && context.length === 1) {\n const typeCache = validationCache.get(value)\n if (typeCache) {\n const cached = typeCache.get(this)\n if (cached !== undefined) {\n return cached\n }\n }\n }\n\n const result = this.isValidSnapshot(value as C, context)\n\n // cache result for object values (only at root level)\n if (typeof value === \"object\" && value !== null && context.length === 1) {\n let typeCache = validationCache.get(value)\n if (!typeCache) {\n typeCache = new WeakMap()\n validationCache.set(value, typeCache)\n }\n typeCache.set(this, result)\n }\n\n return result\n }\n\n is(thing: any): thing is any {\n return this.validate(thing, [{ path: \"\", type: this }]).length === 0\n }\n\n get Type(): any {\n // istanbul ignore next\n throw fail(\n \"Factory.Type should not be actually called. It is just a Type signature that can be used at compile time with Typescript, by using `typeof type.Type`\"\n )\n }\n get TypeWithoutSTN(): any {\n // istanbul ignore next\n throw fail(\n \"Factory.TypeWithoutSTN should not be actually called. It is just a Type signature that can be used at compile time with Typescript, by using `typeof type.TypeWithoutSTN`\"\n )\n }\n get SnapshotType(): any {\n // istanbul ignore next\n throw fail(\n \"Factory.SnapshotType should not be actually called. It is just a Type signature that can be used at compile time with Typescript, by using `typeof type.SnapshotType`\"\n )\n }\n get CreationType(): any {\n // istanbul ignore next\n throw fail(\n \"Factory.CreationType should not be actually called. It is just a Type signature that can be used at compile time with Typescript, by using `typeof type.CreationType`\"\n )\n }\n\n abstract getSubTypes():\n | IAnyType[]\n | IAnyType\n | null\n | typeof cannotDetermineSubtype\n}\nBaseType.prototype.create = action(BaseType.prototype.create)\n\n/**\n * @internal\n * @hidden\n */\nexport type AnyBaseType = BaseType<any, any, any, any>\n\n/**\n * @internal\n * @hidden\n */\nexport type ExtractNodeType<IT extends IAnyType> =\n IT extends BaseType<any, any, any, infer N> ? N : never\n\n/**\n * A complex type produces a MST node (Node in the state tree)\n *\n * @internal\n * @hidden\n */\nexport abstract class ComplexType<C, S, T> extends BaseType<\n C,\n S,\n T,\n ObjectNode<C, S, T>\n> {\n identifierAttribute?: string\n\n constructor(name: string) {\n super(name)\n }\n\n create(snapshot: C = this.getDefaultSnapshot(), environment?: any) {\n return super.create(snapshot, environment)\n }\n\n getValue(node: this[\"N\"]): T {\n node.createObservableInstanceIfNeeded()\n return node.storedValue\n }\n\n abstract getDefaultSnapshot(): C\n\n abstract createNewInstance(childNodes: IChildNodesMap): T\n abstract finalizeNewInstance(node: this[\"N\"], instance: any): void\n\n abstract applySnapshot(node: this[\"N\"], snapshot: C): void\n abstract applyPatchLocally(\n node: this[\"N\"],\n subpath: string,\n patch: IJsonPatch\n ): void\n abstract processInitialSnapshot(childNodes: IChildNodesMap, snapshot: C): S\n\n abstract getChildren(node: this[\"N\"]): ReadonlyArray<AnyNode>\n abstract getChildNode(node: this[\"N\"], key: string): AnyNode\n abstract getChildType(propertyName?: string): IAnyType\n abstract initializeChildNodes(node: this[\"N\"], snapshot: any): IChildNodesMap\n abstract removeChild(node: this[\"N\"], subpath: string): void\n\n isMatchingSnapshotId(current: this[\"N\"], snapshot: C): boolean {\n return (\n !current.identifierAttribute ||\n current.identifier ===\n normalizeIdentifier((snapshot as any)[current.identifierAttribute])\n )\n }\n\n private tryToReconcileNode(current: this[\"N\"], newValue: C | T) {\n if (current.isDetaching) {\n return false\n }\n if ((current.snapshot as any) === newValue) {\n // newValue is the current snapshot of the node, noop\n return true\n }\n if (isStateTreeNode(newValue) && getStateTreeNode(newValue) === current) {\n // the current node is the same as the new one\n return true\n }\n if (\n current.type === this &&\n isMutable(newValue) &&\n !isStateTreeNode(newValue) &&\n this.isMatchingSnapshotId(current, newValue as any)\n ) {\n // the newValue has no node, so can be treated like a snapshot\n // we can reconcile\n current.applySnapshot(newValue as C)\n return true\n }\n return false\n }\n\n reconcile(\n current: this[\"N\"],\n newValue: C | T,\n parent: AnyObjectNode,\n subpath: string\n ): this[\"N\"] {\n const nodeReconciled = this.tryToReconcileNode(current, newValue)\n if (nodeReconciled) {\n current.setParent(parent, subpath)\n return current\n }\n\n // current node cannot be recycled in any way\n current.die() // noop if detaching\n // attempt to reuse the new one\n if (isStateTreeNode(newValue) && this.isAssignableFrom(getType(newValue))) {\n // newValue is a Node as well, move it here..\n const newNode = getStateTreeNode(newValue)\n newNode.setParent(parent, subpath)\n return newNode\n }\n // nothing to do, we have to create a new node\n return this.instantiate(parent, subpath, undefined, newValue)\n }\n\n getSubTypes() {\n return null\n }\n}\nComplexType.prototype.create = action(ComplexType.prototype.create)\n\n/**\n * @internal\n * @hidden\n */\nexport abstract class SimpleType<C, S, T> extends BaseType<\n C,\n S,\n T,\n ScalarNode<C, S, T>\n> {\n abstract instantiate(\n parent: AnyObjectNode | null,\n subpath: string,\n environment: any,\n initialValue: C\n ): this[\"N\"]\n\n createNewInstance(snapshot: C): T {\n return snapshot as any\n }\n\n getValue(node: this[\"N\"]): T {\n // if we ever find a case where scalar nodes can be accessed without iterating through its parent\n // uncomment this to make sure the parent chain is created when this is accessed\n // if (node.parent) {\n // node.parent.createObservableInstanceIfNeeded()\n // }\n return node.storedValue\n }\n\n getSnapshot(node: this[\"N\"]): S {\n return node.storedValue\n }\n\n reconcile(\n current: this[\"N\"],\n newValue: C,\n parent: AnyObjectNode,\n subpath: string\n ): this[\"N\"] {\n // reconcile only if type and value are still the same, and only if the node is not detaching\n if (\n !current.isDetaching &&\n current.type === this &&\n current.storedValue === newValue\n ) {\n return current\n }\n const res = this.instantiate(parent, subpath, undefined, newValue)\n current.die() // noop if detaching\n return res\n }\n\n getSubTypes() {\n return null\n }\n}\n\n/**\n * Returns if a given value represents a type.\n *\n * @param value Value to check.\n * @returns `true` if the value is a type.\n */\nexport function isType(value: any): value is IAnyType {\n return typeof value === \"object\" && value && value.isType === true\n}\n\n/**\n * @internal\n * @hidden\n */\nexport function assertIsType(type: IAnyType, argNumber: number | number[]) {\n assertArg(type, isType, \"mobx-state-tree type\", argNumber)\n}\n"]}