@jbrowse/mobx-state-tree 5.6.2 → 5.6.3

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 (126) hide show
  1. package/package.json +2 -2
  2. package/dist/core/action.d.ts +0 -87
  3. package/dist/core/action.js +0 -228
  4. package/dist/core/action.js.map +0 -1
  5. package/dist/core/actionContext.d.ts +0 -27
  6. package/dist/core/actionContext.js +0 -42
  7. package/dist/core/actionContext.js.map +0 -1
  8. package/dist/core/flow.d.ts +0 -69
  9. package/dist/core/flow.js +0 -180
  10. package/dist/core/flow.js.map +0 -1
  11. package/dist/core/json-patch.d.ts +0 -46
  12. package/dist/core/json-patch.js +0 -133
  13. package/dist/core/json-patch.js.map +0 -1
  14. package/dist/core/mst-operations.d.ts +0 -459
  15. package/dist/core/mst-operations.js +0 -885
  16. package/dist/core/mst-operations.js.map +0 -1
  17. package/dist/core/node/BaseNode.d.ts +0 -62
  18. package/dist/core/node/BaseNode.js +0 -152
  19. package/dist/core/node/BaseNode.js.map +0 -1
  20. package/dist/core/node/Hook.d.ts +0 -17
  21. package/dist/core/node/Hook.js +0 -15
  22. package/dist/core/node/Hook.js.map +0 -1
  23. package/dist/core/node/create-node.d.ts +0 -16
  24. package/dist/core/node/create-node.js +0 -41
  25. package/dist/core/node/create-node.js.map +0 -1
  26. package/dist/core/node/identifier-cache.d.ts +0 -19
  27. package/dist/core/node/identifier-cache.js +0 -115
  28. package/dist/core/node/identifier-cache.js.map +0 -1
  29. package/dist/core/node/livelinessChecking.d.ts +0 -37
  30. package/dist/core/node/livelinessChecking.js +0 -38
  31. package/dist/core/node/livelinessChecking.js.map +0 -1
  32. package/dist/core/node/node-utils.d.ts +0 -83
  33. package/dist/core/node/node-utils.js +0 -165
  34. package/dist/core/node/node-utils.js.map +0 -1
  35. package/dist/core/node/object-node.d.ts +0 -99
  36. package/dist/core/node/object-node.js +0 -545
  37. package/dist/core/node/object-node.js.map +0 -1
  38. package/dist/core/node/scalar-node.d.ts +0 -19
  39. package/dist/core/node/scalar-node.js +0 -89
  40. package/dist/core/node/scalar-node.js.map +0 -1
  41. package/dist/core/process.d.ts +0 -50
  42. package/dist/core/process.js +0 -39
  43. package/dist/core/process.js.map +0 -1
  44. package/dist/core/type/type-checker.d.ts +0 -69
  45. package/dist/core/type/type-checker.js +0 -154
  46. package/dist/core/type/type-checker.js.map +0 -1
  47. package/dist/core/type/type.d.ts +0 -317
  48. package/dist/core/type/type.js +0 -251
  49. package/dist/core/type/type.js.map +0 -1
  50. package/dist/index.d.ts +0 -2
  51. package/dist/index.js +0 -85
  52. package/dist/index.js.map +0 -1
  53. package/dist/internal.d.ts +0 -39
  54. package/dist/internal.js +0 -60
  55. package/dist/internal.js.map +0 -1
  56. package/dist/middlewares/create-action-tracking-middleware.d.ts +0 -24
  57. package/dist/middlewares/create-action-tracking-middleware.js +0 -81
  58. package/dist/middlewares/create-action-tracking-middleware.js.map +0 -1
  59. package/dist/middlewares/createActionTrackingMiddleware2.d.ts +0 -34
  60. package/dist/middlewares/createActionTrackingMiddleware2.js +0 -133
  61. package/dist/middlewares/createActionTrackingMiddleware2.js.map +0 -1
  62. package/dist/middlewares/on-action.d.ts +0 -87
  63. package/dist/middlewares/on-action.js +0 -215
  64. package/dist/middlewares/on-action.js.map +0 -1
  65. package/dist/mobx-state-tree.js +0 -85
  66. package/dist/mobx-state-tree.module.js +0 -83
  67. package/dist/types/complex-types/array.d.ts +0 -80
  68. package/dist/types/complex-types/array.js +0 -352
  69. package/dist/types/complex-types/array.js.map +0 -1
  70. package/dist/types/complex-types/map.d.ts +0 -110
  71. package/dist/types/complex-types/map.js +0 -361
  72. package/dist/types/complex-types/map.js.map +0 -1
  73. package/dist/types/complex-types/model.d.ts +0 -192
  74. package/dist/types/complex-types/model.js +0 -477
  75. package/dist/types/complex-types/model.js.map +0 -1
  76. package/dist/types/index.d.ts +0 -33
  77. package/dist/types/index.js +0 -38
  78. package/dist/types/index.js.map +0 -1
  79. package/dist/types/primitives.d.ts +0 -124
  80. package/dist/types/primitives.js +0 -182
  81. package/dist/types/primitives.js.map +0 -1
  82. package/dist/types/utility-types/custom.d.ts +0 -74
  83. package/dist/types/utility-types/custom.js +0 -110
  84. package/dist/types/utility-types/custom.js.map +0 -1
  85. package/dist/types/utility-types/enumeration.d.ts +0 -5
  86. package/dist/types/utility-types/enumeration.js +0 -34
  87. package/dist/types/utility-types/enumeration.js.map +0 -1
  88. package/dist/types/utility-types/frozen.d.ts +0 -23
  89. package/dist/types/utility-types/frozen.js +0 -97
  90. package/dist/types/utility-types/frozen.js.map +0 -1
  91. package/dist/types/utility-types/identifier.d.ts +0 -86
  92. package/dist/types/utility-types/identifier.js +0 -129
  93. package/dist/types/utility-types/identifier.js.map +0 -1
  94. package/dist/types/utility-types/late.d.ts +0 -10
  95. package/dist/types/utility-types/late.js +0 -109
  96. package/dist/types/utility-types/late.js.map +0 -1
  97. package/dist/types/utility-types/lazy.d.ts +0 -22
  98. package/dist/types/utility-types/lazy.js +0 -76
  99. package/dist/types/utility-types/lazy.js.map +0 -1
  100. package/dist/types/utility-types/literal.d.ts +0 -37
  101. package/dist/types/utility-types/literal.js +0 -63
  102. package/dist/types/utility-types/literal.js.map +0 -1
  103. package/dist/types/utility-types/maybe.d.ts +0 -26
  104. package/dist/types/utility-types/maybe.js +0 -30
  105. package/dist/types/utility-types/maybe.js.map +0 -1
  106. package/dist/types/utility-types/optional.d.ts +0 -41
  107. package/dist/types/utility-types/optional.js +0 -140
  108. package/dist/types/utility-types/optional.js.map +0 -1
  109. package/dist/types/utility-types/reference.d.ts +0 -89
  110. package/dist/types/utility-types/reference.js +0 -392
  111. package/dist/types/utility-types/reference.js.map +0 -1
  112. package/dist/types/utility-types/refinement.d.ts +0 -10
  113. package/dist/types/utility-types/refinement.js +0 -85
  114. package/dist/types/utility-types/refinement.js.map +0 -1
  115. package/dist/types/utility-types/resilient.d.ts +0 -18
  116. package/dist/types/utility-types/resilient.js +0 -120
  117. package/dist/types/utility-types/resilient.js.map +0 -1
  118. package/dist/types/utility-types/snapshotProcessor.d.ts +0 -63
  119. package/dist/types/utility-types/snapshotProcessor.js +0 -161
  120. package/dist/types/utility-types/snapshotProcessor.js.map +0 -1
  121. package/dist/types/utility-types/union.d.ts +0 -77
  122. package/dist/types/utility-types/union.js +0 -245
  123. package/dist/types/utility-types/union.js.map +0 -1
  124. package/dist/utils.d.ts +0 -230
  125. package/dist/utils.js +0 -483
  126. package/dist/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;IACpB,4CAAc,CAAA;IACd,wDAAoB,CAAA;IACpB,+CAAe,CAAA;IACf,6CAAc,CAAA;IACd,uDAAmB,CAAA;IACnB,oDAAiB,CAAA;IACjB,kDAAgB,CAAA;IAChB,wEAA2B,CAAA;IAC3B,+CAAc,CAAA;IACd,mDAAgB,CAAA;IAChB,iDAAe,C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AS,CAAC,CAAA;AAC5D,CAAC"}
package/dist/index.d.ts DELETED
@@ -1,2 +0,0 @@
1
- export type { CustomTypeOptions, IActionContext, IActionRecorder, IActionTrackingMiddleware2Call, IActionTrackingMiddleware2Hooks, IActionTrackingMiddlewareHooks, IAnyComplexType, IAnyModelType, IAnyStateTreeNode, IAnyType, IArrayType, IComplexType, IDisposer, IJsonPatch, IMSTArray, IMSTMap, IMapType, IMaybe, IMaybeIType, IMaybeNull, IMiddlewareEvent, IMiddlewareEventType, IMiddlewareHandler, IModelReflectionData, IModelReflectionPropertiesData, IModelType, IOptionalIType, IPatchRecorder, IReferenceType, IReversibleJsonPatch, ISerializedActionCall, ISimpleType, ISnapshotProcessor, ISnapshotProcessors, IStateTreeNode, IType, ITypeUnion, Instance, LivelinessMode, LivelynessMode, ModelActions, ModelCreationType2, ModelCreationType, ModelInstanceType, ModelInstanceTypeProps, ModelPrimitive, ModelProperties, ModelPropertiesDeclaration, ModelPropertiesDeclarationToProperties, ModelSnapshotType2, ModelSnapshotType, OnReferenceInvalidated, OnReferenceInvalidatedEvent, OptionalDefaultValueOrFunction, ReferenceIdentifier, ReferenceOptions, ReferenceOptionsGetSet, ReferenceOptionsOnInvalidated, SnapshotIn, SnapshotOrInstance, SnapshotOut, TypeOfValue, TypeOrStateTreeNodeToStateTreeNode, UnionOptions, UnionStringArray, ValidOptionalValue, ValidOptionalValues, _CustomCSProcessor, _CustomJoin, _CustomOrOther, _NotCustomized } from "./internal.ts";
2
- export { addDisposer, addMiddleware, applyAction, applyPatch, applySnapshot, cast, castFlowReturn, castToReferenceSnapshot, castToSnapshot, clone, createActionTrackingMiddleware2, createActionTrackingMiddleware, decorate, destroy, detach, escapeJsonPath, flow, getChildType, getEnv, getIdentifier, getLivelinessChecking, getMembers, getNodeId, getParent, getParentOfType, getPath, getPathParts, getPropertyMembers, getRelativePath, getRoot, getRunningActionContext, getSnapshot, getType, hasParent, hasParentOfType, isActionContextChildOf, isActionContextThisOrChildOf, isAlive, isArrayType, isFrozenType, isIdentifierType, isLateType, isLiteralType, isMapType, isModelType, isOptionalType, isPrimitiveType, isProtected, isReferenceType, isRefinementType, isRoot, isStateTreeNode, isType, isUnionType, isValidReference, joinJsonPath, onAction, onPatch, onSnapshot, process, protect, recordActions, recordPatches, resolveIdentifier, resolvePath, setLivelinessChecking, setLivelynessChecking, splitJsonPath, toGenerator, toGeneratorFunction, tryReference, tryResolve, typecheck, types, types as t, unescapeJsonPath, unprotect, walk, setDevMode } from "./internal.ts";