@jbrowse/mobx-state-tree 5.4.4 → 5.4.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/core/action.d.ts +87 -0
- package/dist/core/action.js.map +1 -0
- package/dist/core/actionContext.d.ts +27 -0
- package/dist/core/actionContext.js.map +1 -0
- package/dist/core/flow.d.ts +69 -0
- package/dist/core/flow.js.map +1 -0
- package/dist/core/json-patch.d.ts +46 -0
- package/dist/core/json-patch.js.map +1 -0
- package/dist/core/mst-operations.d.ts +459 -0
- package/dist/core/mst-operations.js.map +1 -0
- package/dist/core/node/BaseNode.d.ts +62 -0
- package/dist/core/node/BaseNode.js.map +1 -0
- package/dist/core/node/Hook.d.ts +17 -0
- package/dist/core/node/Hook.js.map +1 -0
- package/dist/core/node/create-node.d.ts +16 -0
- package/dist/core/node/create-node.js.map +1 -0
- package/dist/core/node/identifier-cache.d.ts +19 -0
- package/dist/core/node/identifier-cache.js.map +1 -0
- package/dist/core/node/livelinessChecking.d.ts +37 -0
- package/dist/core/node/livelinessChecking.js.map +1 -0
- package/dist/core/node/node-utils.d.ts +83 -0
- package/dist/core/node/node-utils.js.map +1 -0
- package/dist/core/node/object-node.d.ts +99 -0
- package/dist/core/node/object-node.js.map +1 -0
- package/dist/core/node/scalar-node.d.ts +19 -0
- package/dist/core/node/scalar-node.js.map +1 -0
- package/dist/core/process.d.ts +50 -0
- package/dist/core/process.js.map +1 -0
- package/dist/core/type/type-checker.d.ts +60 -0
- package/dist/core/type/type-checker.js.map +1 -0
- package/dist/core/type/type.d.ts +317 -0
- package/dist/core/type/type.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js.map +1 -0
- package/dist/internal.d.ts +38 -0
- package/dist/internal.js.map +1 -0
- package/dist/middlewares/create-action-tracking-middleware.d.ts +24 -0
- package/dist/middlewares/create-action-tracking-middleware.js.map +1 -0
- package/dist/middlewares/createActionTrackingMiddleware2.d.ts +34 -0
- package/dist/middlewares/createActionTrackingMiddleware2.js.map +1 -0
- package/dist/middlewares/on-action.d.ts +87 -0
- package/dist/middlewares/on-action.js.map +1 -0
- package/dist/types/complex-types/array.d.ts +80 -0
- package/dist/types/complex-types/array.js.map +1 -0
- package/dist/types/complex-types/map.d.ts +110 -0
- package/dist/types/complex-types/map.js.map +1 -0
- package/dist/types/complex-types/model.d.ts +192 -0
- package/dist/types/complex-types/model.js.map +1 -0
- package/dist/types/index.d.ts +32 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/primitives.d.ts +124 -0
- package/dist/types/primitives.js.map +1 -0
- package/dist/types/utility-types/custom.d.ts +74 -0
- package/dist/types/utility-types/custom.js.map +1 -0
- package/dist/types/utility-types/enumeration.d.ts +5 -0
- package/dist/types/utility-types/enumeration.js.map +1 -0
- package/dist/types/utility-types/frozen.d.ts +23 -0
- package/dist/types/utility-types/frozen.js.map +1 -0
- package/dist/types/utility-types/identifier.d.ts +86 -0
- package/dist/types/utility-types/identifier.js.map +1 -0
- package/dist/types/utility-types/late.d.ts +10 -0
- package/dist/types/utility-types/late.js.map +1 -0
- package/dist/types/utility-types/lazy.d.ts +22 -0
- package/dist/types/utility-types/lazy.js.map +1 -0
- package/dist/types/utility-types/literal.d.ts +37 -0
- package/dist/types/utility-types/literal.js.map +1 -0
- package/dist/types/utility-types/maybe.d.ts +26 -0
- package/dist/types/utility-types/maybe.js.map +1 -0
- package/dist/types/utility-types/optional.d.ts +41 -0
- package/dist/types/utility-types/optional.js.map +1 -0
- package/dist/types/utility-types/reference.d.ts +89 -0
- package/dist/types/utility-types/reference.js.map +1 -0
- package/dist/types/utility-types/refinement.d.ts +10 -0
- package/dist/types/utility-types/refinement.js.map +1 -0
- package/dist/types/utility-types/snapshotProcessor.d.ts +63 -0
- package/dist/types/utility-types/snapshotProcessor.js.map +1 -0
- package/dist/types/utility-types/union.d.ts +73 -0
- package/dist/types/utility-types/union.js.map +1 -0
- package/dist/utils.d.ts +230 -0
- package/dist/utils.js.map +1 -0
- package/package.json +3 -2
|
@@ -0,0 +1,317 @@
|
|
|
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 {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type.js","sourceRoot":"","sources":["../../../src/core/type/type.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAE7B,OAAO,EAEL,SAAS,EACT,IAAI,EACJ,gBAAgB,EAChB,oBAAoB,EACpB,OAAO,EACP,SAAS,EACT,eAAe,EACf,mBAAmB,EACnB,gBAAgB,EAChB,gBAAgB,EAChB,iBAAiB,EAClB,MAAM,mBAAmB,CAAA;AAe1B;;;GAGG;AACH,MAAM,CAAN,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,CAAA;AACjB,CAAC,EAxBW,SAAS,KAAT,SAAS,QAwBpB;AAED;;;GAGG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,iBAAiB,CAAA;AAUvD,cAAc;AACd,MAAM,KAAK,GAAkB,MAAM,CAAC,OAAO,CAAC,CAAA;AA2N5C;;;;;GAKG;AACH,MAAM,OAAgB,QAA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AAE,sBAAsB,EAAE,SAAS,CAAC,CAAA;AAC5D,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
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";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AA8EA,OAAO,EACL,WAAW,EACX,aAAa,EACb,WAAW,EACX,UAAU,EACV,aAAa,EACb,IAAI,EACJ,cAAc,EACd,uBAAuB,EACvB,cAAc,EACd,KAAK,EACL,+BAA+B,EAC/B,8BAA8B,EAC9B,QAAQ,EACR,OAAO,EACP,MAAM,EACN,cAAc,EACd,IAAI,EACJ,YAAY,EACZ,MAAM,EACN,aAAa,EACb,qBAAqB,EACrB,UAAU,EACV,SAAS,EACT,SAAS,EACT,eAAe,EACf,OAAO,EACP,YAAY,EACZ,kBAAkB,EAClB,eAAe,EACf,OAAO,EACP,uBAAuB,EACvB,WAAW,EACX,OAAO,EACP,SAAS,EACT,eAAe,EACf,sBAAsB,EACtB,4BAA4B,EAC5B,OAAO,EACP,WAAW,EACX,YAAY,EACZ,gBAAgB,EAChB,UAAU,EACV,aAAa,EACb,SAAS,EACT,WAAW,EACX,cAAc,EACd,eAAe,EACf,WAAW,EACX,eAAe,EACf,gBAAgB,EAChB,MAAM,EACN,eAAe,EACf,MAAM,EACN,WAAW,EACX,gBAAgB,EAChB,YAAY,EACZ,QAAQ,EACR,OAAO,EACP,UAAU,EACV,OAAO,EACP,OAAO,EACP,aAAa,EACb,aAAa,EACb,iBAAiB,EACjB,WAAW,EACX,qBAAqB,EACrB,qBAAqB,EACrB,aAAa,EACb,WAAW,EACX,mBAAmB,EACnB,YAAY,EACZ,UAAU,EACV,SAAS,EACT,KAAK,EACL,KAAK,IAAI,CAAC,EACV,gBAAgB,EAChB,SAAS,EACT,IAAI,EACJ,UAAU,EACX,MAAM,eAAe,CAAA"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export * from "./core/node/livelinessChecking.ts";
|
|
2
|
+
export * from "./core/node/Hook.ts";
|
|
3
|
+
export * from "./core/mst-operations.ts";
|
|
4
|
+
export * from "./core/node/BaseNode.ts";
|
|
5
|
+
export * from "./core/node/scalar-node.ts";
|
|
6
|
+
export * from "./core/node/object-node.ts";
|
|
7
|
+
export * from "./core/type/type.ts";
|
|
8
|
+
export * from "./middlewares/create-action-tracking-middleware.ts";
|
|
9
|
+
export * from "./middlewares/createActionTrackingMiddleware2.ts";
|
|
10
|
+
export * from "./middlewares/on-action.ts";
|
|
11
|
+
export * from "./core/action.ts";
|
|
12
|
+
export * from "./core/actionContext.ts";
|
|
13
|
+
export * from "./core/type/type-checker.ts";
|
|
14
|
+
export * from "./core/node/identifier-cache.ts";
|
|
15
|
+
export * from "./core/node/create-node.ts";
|
|
16
|
+
export * from "./core/node/node-utils.ts";
|
|
17
|
+
export * from "./core/process.ts";
|
|
18
|
+
export * from "./core/flow.ts";
|
|
19
|
+
export * from "./core/json-patch.ts";
|
|
20
|
+
export * from "./utils.ts";
|
|
21
|
+
export * from "./types/utility-types/snapshotProcessor.ts";
|
|
22
|
+
export * from "./types/complex-types/map.ts";
|
|
23
|
+
export * from "./types/complex-types/array.ts";
|
|
24
|
+
export * from "./types/complex-types/model.ts";
|
|
25
|
+
export * from "./types/primitives.ts";
|
|
26
|
+
export * from "./types/utility-types/literal.ts";
|
|
27
|
+
export * from "./types/utility-types/refinement.ts";
|
|
28
|
+
export * from "./types/utility-types/enumeration.ts";
|
|
29
|
+
export * from "./types/utility-types/union.ts";
|
|
30
|
+
export * from "./types/utility-types/optional.ts";
|
|
31
|
+
export * from "./types/utility-types/maybe.ts";
|
|
32
|
+
export * from "./types/utility-types/late.ts";
|
|
33
|
+
export * from "./types/utility-types/lazy.ts";
|
|
34
|
+
export * from "./types/utility-types/frozen.ts";
|
|
35
|
+
export * from "./types/utility-types/reference.ts";
|
|
36
|
+
export * from "./types/utility-types/identifier.ts";
|
|
37
|
+
export * from "./types/utility-types/custom.ts";
|
|
38
|
+
export * from "./types/index.ts";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"internal.js","sourceRoot":"","sources":["../src/internal.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,cAAc,mCAAmC,CAAA;AACjD,cAAc,qBAAqB,CAAA;AACnC,cAAc,0BAA0B,CAAA;AACxC,cAAc,yBAAyB,CAAA;AACvC,cAAc,4BAA4B,CAAA;AAC1C,cAAc,4BAA4B,CAAA;AAC1C,cAAc,qBAAqB,CAAA;AACnC,cAAc,oDAAoD,CAAA;AAClE,cAAc,kDAAkD,CAAA;AAChE,cAAc,4BAA4B,CAAA;AAC1C,cAAc,kBAAkB,CAAA;AAChC,cAAc,yBAAyB,CAAA;AACvC,cAAc,6BAA6B,CAAA;AAC3C,cAAc,iCAAiC,CAAA;AAC/C,cAAc,4BAA4B,CAAA;AAC1C,cAAc,2BAA2B,CAAA;AACzC,cAAc,mBAAmB,CAAA;AACjC,cAAc,gBAAgB,CAAA;AAC9B,cAAc,sBAAsB,CAAA;AACpC,cAAc,YAAY,CAAA;AAC1B,cAAc,4CAA4C,CAAA;AAC1D,cAAc,8BAA8B,CAAA;AAC5C,cAAc,gCAAgC,CAAA;AAC9C,cAAc,gCAAgC,CAAA;AAC9C,cAAc,uBAAuB,CAAA;AACrC,cAAc,kCAAkC,CAAA;AAChD,cAAc,qCAAqC,CAAA;AACnD,cAAc,sCAAsC,CAAA;AACpD,cAAc,gCAAgC,CAAA;AAC9C,cAAc,mCAAmC,CAAA;AACjD,cAAc,gCAAgC,CAAA;AAC9C,cAAc,+BAA+B,CAAA;AAC7C,cAAc,+BAA+B,CAAA;AAC7C,cAAc,iCAAiC,CAAA;AAC/C,cAAc,oCAAoC,CAAA;AAClD,cAAc,qCAAqC,CAAA;AACnD,cAAc,iCAAiC,CAAA;AAC/C,cAAc,kBAAkB,CAAA"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { type IMiddlewareEvent, type IMiddlewareHandler } from "../internal.ts";
|
|
2
|
+
export interface IActionTrackingMiddlewareHooks<T> {
|
|
3
|
+
filter?: (call: IMiddlewareEvent) => boolean;
|
|
4
|
+
onStart: (call: IMiddlewareEvent) => T;
|
|
5
|
+
onResume: (call: IMiddlewareEvent, context: T) => void;
|
|
6
|
+
onSuspend: (call: IMiddlewareEvent, context: T) => void;
|
|
7
|
+
onSuccess: (call: IMiddlewareEvent, context: T, result: any) => void;
|
|
8
|
+
onFail: (call: IMiddlewareEvent, context: T, error: any) => void;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Note: Consider migrating to `createActionTrackingMiddleware2`, it is easier to use.
|
|
12
|
+
*
|
|
13
|
+
* Convenience utility to create action based middleware that supports async processes more easily.
|
|
14
|
+
* All hooks are called for both synchronous and asynchronous actions. Except that either `onSuccess` or `onFail` is called
|
|
15
|
+
*
|
|
16
|
+
* The create middleware tracks the process of an action (assuming it passes the `filter`).
|
|
17
|
+
* `onResume` can return any value, which will be passed as second argument to any other hook. This makes it possible to keep state during a process.
|
|
18
|
+
*
|
|
19
|
+
* See the `atomic` middleware for an example
|
|
20
|
+
*
|
|
21
|
+
* @param hooks
|
|
22
|
+
* @returns
|
|
23
|
+
*/
|
|
24
|
+
export declare function createActionTrackingMiddleware<T = any>(hooks: IActionTrackingMiddlewareHooks<T>): IMiddlewareHandler;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-action-tracking-middleware.js","sourceRoot":"","sources":["../../src/middlewares/create-action-tracking-middleware.ts"],"names":[],"mappings":"AAK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AAC,CAAA;gBAClC,KAAK,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAA;gBACjD,OAAO,IAAI,CAAC,IAAI,CAAC,CAAA;YACnB,CAAC;QACH,CAAC;IACH,CAAC,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { type IActionContext, type IMiddlewareHandler } from "../internal.ts";
|
|
2
|
+
export interface IActionTrackingMiddleware2Call<TEnv> extends Readonly<IActionContext> {
|
|
3
|
+
env: TEnv | undefined;
|
|
4
|
+
readonly parentCall?: IActionTrackingMiddleware2Call<TEnv>;
|
|
5
|
+
}
|
|
6
|
+
export interface IActionTrackingMiddleware2Hooks<TEnv> {
|
|
7
|
+
filter?: (call: IActionTrackingMiddleware2Call<TEnv>) => boolean;
|
|
8
|
+
onStart: (call: IActionTrackingMiddleware2Call<TEnv>) => void;
|
|
9
|
+
onFinish: (call: IActionTrackingMiddleware2Call<TEnv>, error?: any) => void;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Convenience utility to create action based middleware that supports async processes more easily.
|
|
13
|
+
* The flow is like this:
|
|
14
|
+
* - for each action: if filter passes -> `onStart` -> (inner actions recursively) -> `onFinish`
|
|
15
|
+
*
|
|
16
|
+
* Example: if we had an action `a` that called inside an action `b1`, then `b2` the flow would be:
|
|
17
|
+
* - `filter(a)`
|
|
18
|
+
* - `onStart(a)`
|
|
19
|
+
* - `filter(b1)`
|
|
20
|
+
* - `onStart(b1)`
|
|
21
|
+
* - `onFinish(b1)`
|
|
22
|
+
* - `filter(b2)`
|
|
23
|
+
* - `onStart(b2)`
|
|
24
|
+
* - `onFinish(b2)`
|
|
25
|
+
* - `onFinish(a)`
|
|
26
|
+
*
|
|
27
|
+
* The flow is the same no matter if the actions are sync or async.
|
|
28
|
+
*
|
|
29
|
+
* See the `atomic` middleware for an example
|
|
30
|
+
*
|
|
31
|
+
* @param hooks
|
|
32
|
+
* @returns
|
|
33
|
+
*/
|
|
34
|
+
export declare function createActionTrackingMiddleware2<TEnv = any>(middlewareHooks: IActionTrackingMiddleware2Hooks<TEnv>): IMiddlewareHandler;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createActionTrackingMiddleware2.js","sourceRoot":"","sources":["../../src/middlewares/createActionTrackingMiddleware2.ts"],"names":[],"mappings":"AAqBA,MAAM,aAAa;IAKC;IACP;IALH,YAAY,GAAG,CAAC,CAAA;IAChB,OAAO,GAAG,IAAI,CAAA;IAEtB,YACkB,KAAuD,EAC9D,IAAyC;QADlC,UAAK,GAAL,KAAK,CAAkD;QAC9D,SAAI,GAAJ,IAAI,CAAqC;QAElD,IAAI,KAAK,EAAE,CAAC;YACV,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;QACrB,CAAC;IACH,CAAC;IAED,MAAM,CAAC,KAAW;QAChB,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YACjB,IAAI,CAAC,OAAO,GAAG,KAAK,CAAA;YACpB,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;gBACf,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,CAAC,CAAA;YACvC,CAAC;QACH,CAAC;IACH,CAAC;IAED,eAAe;QACb,IAAI,CAAC,YAAY,EAAE,CAAA;IACrB,CAAC;IAED,eAAe;QACb,IAAI,CAAC,YAAY,EAAE,CAAA;IACrB,CAAC;IAED,IAAI,eAAe;QACjB,OAAO,IAAI,CAAC,YAAY,GAAG,CAAC,CAAA;IAC9B,CAAC;CACF;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,UAAU,+BAA+B,CAC7C,eAAsD;IAEtD,MAAM,cAAc,GAAG,IAAI,GAAG,EAAyB,CAAA;IAEvD,OAAO,SAAS,wBAAwB,CACtC,IAAsB,EACtB,IAA2C;QAE3C,2BAA2B;QAC3B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,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { type IActionContext, type IAnyStateTreeNode, type IDisposer } from "../internal.ts";
|
|
2
|
+
export interface ISerializedActionCall {
|
|
3
|
+
name: string;
|
|
4
|
+
path?: string;
|
|
5
|
+
args?: any[];
|
|
6
|
+
}
|
|
7
|
+
export interface IActionRecorder {
|
|
8
|
+
actions: ReadonlyArray<ISerializedActionCall>;
|
|
9
|
+
readonly recording: boolean;
|
|
10
|
+
stop(): void;
|
|
11
|
+
resume(): void;
|
|
12
|
+
replay(target: IAnyStateTreeNode): void;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Applies an action or a series of actions in a single MobX transaction.
|
|
16
|
+
* Does not return any value
|
|
17
|
+
* Takes an action description as produced by the `onAction` middleware.
|
|
18
|
+
*
|
|
19
|
+
* @param target
|
|
20
|
+
* @param actions
|
|
21
|
+
*/
|
|
22
|
+
export declare function applyAction(target: IAnyStateTreeNode, actions: ISerializedActionCall | ISerializedActionCall[]): void;
|
|
23
|
+
/**
|
|
24
|
+
* Small abstraction around `onAction` and `applyAction`, attaches an action listener to a tree and records all the actions emitted.
|
|
25
|
+
* Returns an recorder object with the following signature:
|
|
26
|
+
*
|
|
27
|
+
* Example:
|
|
28
|
+
* ```ts
|
|
29
|
+
* export interface IActionRecorder {
|
|
30
|
+
* // the recorded actions
|
|
31
|
+
* actions: ISerializedActionCall[]
|
|
32
|
+
* // true if currently recording
|
|
33
|
+
* recording: boolean
|
|
34
|
+
* // stop recording actions
|
|
35
|
+
* stop(): void
|
|
36
|
+
* // resume recording actions
|
|
37
|
+
* resume(): void
|
|
38
|
+
* // apply all the recorded actions on the given object
|
|
39
|
+
* replay(target: IAnyStateTreeNode): void
|
|
40
|
+
* }
|
|
41
|
+
* ```
|
|
42
|
+
*
|
|
43
|
+
* The optional filter function allows to skip recording certain actions.
|
|
44
|
+
*
|
|
45
|
+
* @param subject
|
|
46
|
+
* @returns
|
|
47
|
+
*/
|
|
48
|
+
export declare function recordActions(subject: IAnyStateTreeNode, filter?: (action: ISerializedActionCall, actionContext: IActionContext | undefined) => boolean): IActionRecorder;
|
|
49
|
+
/**
|
|
50
|
+
* Registers a function that will be invoked for each action that is called on the provided model instance, or to any of its children.
|
|
51
|
+
* See [actions](https://github.com/mobxjs/mobx-state-tree#actions) for more details. onAction events are emitted only for the outermost called action in the stack.
|
|
52
|
+
* Action can also be intercepted by middleware using addMiddleware to change the function call before it will be run.
|
|
53
|
+
*
|
|
54
|
+
* Not all action arguments might be serializable. For unserializable arguments, a struct like `{ $MST_UNSERIALIZABLE: true, type: "someType" }` will be generated.
|
|
55
|
+
* MST Nodes are considered non-serializable as well (they could be serialized as there snapshot, but it is uncertain whether an replaying party will be able to handle such a non-instantiated snapshot).
|
|
56
|
+
* Rather, when using `onAction` middleware, one should consider in passing arguments which are 1: an id, 2: a (relative) path, or 3: a snapshot. Instead of a real MST node.
|
|
57
|
+
*
|
|
58
|
+
* Example:
|
|
59
|
+
* ```ts
|
|
60
|
+
* const Todo = types.model({
|
|
61
|
+
* task: types.string
|
|
62
|
+
* })
|
|
63
|
+
*
|
|
64
|
+
* const TodoStore = types.model({
|
|
65
|
+
* todos: types.array(Todo)
|
|
66
|
+
* }).actions(self => ({
|
|
67
|
+
* add(todo) {
|
|
68
|
+
* self.todos.push(todo);
|
|
69
|
+
* }
|
|
70
|
+
* }))
|
|
71
|
+
*
|
|
72
|
+
* const s = TodoStore.create({ todos: [] })
|
|
73
|
+
*
|
|
74
|
+
* let disposer = onAction(s, (call) => {
|
|
75
|
+
* console.log(call);
|
|
76
|
+
* })
|
|
77
|
+
*
|
|
78
|
+
* s.add({ task: "Grab a coffee" })
|
|
79
|
+
* // Logs: { name: "add", path: "", args: [{ task: "Grab a coffee" }] }
|
|
80
|
+
* ```
|
|
81
|
+
*
|
|
82
|
+
* @param target
|
|
83
|
+
* @param listener
|
|
84
|
+
* @param attachAfter (default false) fires the listener *after* the action has executed instead of before.
|
|
85
|
+
* @returns
|
|
86
|
+
*/
|
|
87
|
+
export declare function onAction(target: IAnyStateTreeNode, listener: (call: ISerializedActionCall) => void, attachAfter?: boolean): IDisposer;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"on-action.js","sourceRoot":"","sources":["../../src/middlewares/on-action.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,MAAM,CAAA;AAElC,OAAO,EAKL,aAAa,EACb,UAAU,EACV,aAAa,EACb,OAAO,EACP,SAAS,EACT,qBAAqB,EACrB,OAAO,EACP,IAAI,EACJ,2BAA2B,EAC3B,uBAAuB,EACvB,gBAAgB,EAChB,OAAO,EACP,OAAO,EACP,aAAa,EACb,WAAW,EACX,WAAW,EACX,MAAM,EACN,eAAe,EACf,UAAU,EACV,SAAS,EACV,MAAM,gBAAgB,CAAA;AAgBvB,SAAS,iBAAiB,CACxB,IAAa,EACb,UAAkB,EAClB,KAAa,EACb,GAAQ;IAER,IAAI,GAAG,YAAY,IAAI,EAAE,CAAC;QACxB,OAAO,EAAE,SAAS,EAAE,GAAG,CAAC,OAAO,EAAE,EAAE,CAAA;IACrC,CAAC;IACD,IAAI,WAAW,CAAC,GAAG,CAAC,EAAE,CAAC;QACrB,OAAO,GAAG,CAAA;IACZ,CAAC;IACD,0IAA0I;IAC1I,mJAAmJ;IACnJ,IAAI,eAAe,CAAC,GAAG,CAAC,EAAE,CAAC;QACzB,OAAO,0BAA0B,CAAC,aAAa,OAAO,CAAC,GAAG,CAAC,CAAC,IAAI,GAAG,CAAC,CAAA;IACtE,CAAC;IACD,IAAI,OAAO,GAAG,KAAK,UAAU,EAAE,CAAC;QAC9B,OAAO,0BAA0B,CAAC,YAAY,CAAC,CAAA;IACjD,CAAC;IACD,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;QACpE,OAAO,0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ACH,CAAC;QACD,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,EAAE,CAAC;YACzB,SAAS,CACP,+IAA+I,CAChJ,CAAA;QACH,CAAC;IACH,CAAC;IAED,OAAO,aAAa,CAAC,MAAM,EAAE,SAAS,OAAO,CAAC,OAAO,EAAE,IAAI;QACzD,IAAI,OAAO,CAAC,IAAI,KAAK,QAAQ,IAAI,OAAO,CAAC,EAAE,KAAK,OAAO,CAAC,MAAM,EAAE,CAAC;YAC/D,MAAM,UAAU,GAAG,gBAAgB,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;YACpD,MAAM,IAAI,GAAG;gBACX,IAAI,EAAE,OAAO,CAAC,IAAI;gBAClB,IAAI,EAAE,2BAA2B,CAAC,gBAAgB,CAAC,MAAM,CAAC,EAAE,UAAU,CAAC;gBACvE,IAAI,EAAE,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,GAAQ,EAAE,KAAa,EAAE,EAAE,CACjD,iBAAiB,CAAC,UAAU,EAAE,OAAO,CAAC,IAAI,EAAE,KAAK,EAAE,GAAG,CAAC,CACxD;aACF,CAAA;YACD,IAAI,WAAW,EAAE,CAAC;gBAChB,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,CAAA;gBACzB,QAAQ,CAAC,IAAI,CAAC,CAAA;gBACd,OAAO,GAAG,CAAA;YACZ,CAAC;iBAAM,CAAC;gBACN,QAAQ,CAAC,IAAI,CAAC,CAAA;gBACd,OAAO,IAAI,CAAC,OAAO,CAAC,CAAA;YACtB,CAAC;QACH,CAAC;aAAM,CAAC;YACN,OAAO,IAAI,CAAC,OAAO,CAAC,CAAA;QACtB,CAAC;IACH,CAAC,CAAC,CAAA;AACJ,CAAC"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { IArrayDidChange, IArraySplice, IArrayWillChange, IArrayWillSplice, IObservableArray } from "mobx";
|
|
2
|
+
import { type AnyNode, type AnyObjectNode, ComplexType, type ExtractCSTWithSTN, type IAnyType, type IChildNodesMap, type IHooksGetter, type IJsonPatch, type IType, type IValidationContext, type IValidationResult, TypeFlags } from "../../internal.ts";
|
|
3
|
+
/** @hidden */
|
|
4
|
+
export interface IMSTArray<IT extends IAnyType> extends IObservableArray<IT["Type"]> {
|
|
5
|
+
push(...items: IT["Type"][]): number;
|
|
6
|
+
push(...items: ExtractCSTWithSTN<IT>[]): number;
|
|
7
|
+
concat(...items: ConcatArray<IT["Type"]>[]): IT["Type"][];
|
|
8
|
+
concat(...items: ConcatArray<ExtractCSTWithSTN<IT>>[]): IT["Type"][];
|
|
9
|
+
concat(...items: (IT["Type"] | ConcatArray<IT["Type"]>)[]): IT["Type"][];
|
|
10
|
+
concat(...items: (ExtractCSTWithSTN<IT> | ConcatArray<ExtractCSTWithSTN<IT>>)[]): IT["Type"][];
|
|
11
|
+
splice(start: number, deleteCount?: number): IT["Type"][];
|
|
12
|
+
splice(start: number, deleteCount: number, ...items: IT["Type"][]): IT["Type"][];
|
|
13
|
+
splice(start: number, deleteCount: number, ...items: ExtractCSTWithSTN<IT>[]): IT["Type"][];
|
|
14
|
+
unshift(...items: IT["Type"][]): number;
|
|
15
|
+
unshift(...items: ExtractCSTWithSTN<IT>[]): number;
|
|
16
|
+
}
|
|
17
|
+
/** @hidden */
|
|
18
|
+
export interface IArrayType<IT extends IAnyType> extends IType<readonly IT["CreationType"][] | undefined, IT["SnapshotType"][], IMSTArray<IT>> {
|
|
19
|
+
hooks(hooks: IHooksGetter<IMSTArray<IAnyType>>): IArrayType<IT>;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* @internal
|
|
23
|
+
* @hidden
|
|
24
|
+
*/
|
|
25
|
+
export declare class ArrayType<IT extends IAnyType> extends ComplexType<readonly IT["CreationType"][] | undefined, IT["SnapshotType"][], IMSTArray<IT>> {
|
|
26
|
+
private readonly _subType;
|
|
27
|
+
readonly flags = TypeFlags.Array;
|
|
28
|
+
private readonly hookInitializers;
|
|
29
|
+
constructor(name: string, _subType: IT, hookInitializers?: Array<IHooksGetter<IMSTArray<IT>>>);
|
|
30
|
+
hooks(hooks: IHooksGetter<IMSTArray<IT>>): ArrayType<IT>;
|
|
31
|
+
instantiate(parent: AnyObjectNode | null, subpath: string, environment: any, initialValue: this["C"] | this["T"]): this["N"];
|
|
32
|
+
initializeChildNodes(objNode: this["N"], snapshot?: this["C"]): IChildNodesMap;
|
|
33
|
+
createNewInstance(childNodes: IChildNodesMap): this["T"];
|
|
34
|
+
finalizeNewInstance(node: this["N"], instance: this["T"]): void;
|
|
35
|
+
describe(): string;
|
|
36
|
+
getChildren(node: this["N"]): AnyNode[];
|
|
37
|
+
getChildNode(node: this["N"], key: string): AnyNode;
|
|
38
|
+
willChange(change: IArrayWillChange<AnyNode> | IArrayWillSplice<AnyNode>): IArrayWillChange<AnyNode> | IArrayWillSplice<AnyNode> | null;
|
|
39
|
+
getSnapshot(node: this["N"]): this["S"];
|
|
40
|
+
processInitialSnapshot(childNodes: IChildNodesMap): this["S"];
|
|
41
|
+
didChange(change: IArrayDidChange<AnyNode> | IArraySplice<AnyNode>): void;
|
|
42
|
+
applyPatchLocally(node: this["N"], subpath: string, patch: IJsonPatch): void;
|
|
43
|
+
applySnapshot(node: this["N"], snapshot: this["C"]): void;
|
|
44
|
+
getChildType(): IAnyType;
|
|
45
|
+
isValidSnapshot(value: this["C"], context: IValidationContext): IValidationResult;
|
|
46
|
+
getDefaultSnapshot(): this["C"];
|
|
47
|
+
removeChild(node: this["N"], subpath: string): void;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* `types.array` - Creates an index based collection type who's children are all of a uniform declared type.
|
|
51
|
+
*
|
|
52
|
+
* This type will always produce [observable arrays](https://mobx.js.org/api.html#observablearray)
|
|
53
|
+
*
|
|
54
|
+
* Example:
|
|
55
|
+
* ```ts
|
|
56
|
+
* const Todo = types.model({
|
|
57
|
+
* task: types.string
|
|
58
|
+
* })
|
|
59
|
+
*
|
|
60
|
+
* const TodoStore = types.model({
|
|
61
|
+
* todos: types.array(Todo)
|
|
62
|
+
* })
|
|
63
|
+
*
|
|
64
|
+
* const s = TodoStore.create({ todos: [] })
|
|
65
|
+
* unprotect(s) // needed to allow modifying outside of an action
|
|
66
|
+
* s.todos.push({ task: "Grab coffee" })
|
|
67
|
+
* console.log(s.todos[0]) // prints: "Grab coffee"
|
|
68
|
+
* ```
|
|
69
|
+
*
|
|
70
|
+
* @param subtype
|
|
71
|
+
* @returns
|
|
72
|
+
*/
|
|
73
|
+
export declare function array<IT extends IAnyType>(subtype: IT): IArrayType<IT>;
|
|
74
|
+
/**
|
|
75
|
+
* Returns if a given value represents an array type.
|
|
76
|
+
*
|
|
77
|
+
* @param type
|
|
78
|
+
* @returns `true` if the type is an array type.
|
|
79
|
+
*/
|
|
80
|
+
export declare function isArrayType<Items extends IAnyType = IAnyType>(type: IAnyType): type is IArrayType<Items>;
|