mobx-state-tree 3.15.0 → 3.17.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 (47) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +3 -1757
  3. package/dist/core/action.d.ts +50 -50
  4. package/dist/core/actionContext.d.ts +27 -27
  5. package/dist/core/flow.d.ts +63 -14
  6. package/dist/core/json-patch.d.ts +36 -36
  7. package/dist/core/mst-operations.d.ts +451 -451
  8. package/dist/core/node/BaseNode.d.ts +1 -1
  9. package/dist/core/node/Hook.d.ts +17 -17
  10. package/dist/core/node/create-node.d.ts +1 -1
  11. package/dist/core/node/identifier-cache.d.ts +1 -1
  12. package/dist/core/node/livelinessChecking.d.ts +37 -37
  13. package/dist/core/node/node-utils.d.ts +28 -28
  14. package/dist/core/node/object-node.d.ts +1 -1
  15. package/dist/core/node/scalar-node.d.ts +1 -1
  16. package/dist/core/process.d.ts +45 -45
  17. package/dist/core/type/type-checker.d.ts +30 -30
  18. package/dist/core/type/type.d.ts +162 -162
  19. package/dist/index.d.ts +3 -3
  20. package/dist/internal.d.ts +37 -37
  21. package/dist/middlewares/create-action-tracking-middleware.d.ts +24 -24
  22. package/dist/middlewares/createActionTrackingMiddleware2.d.ts +34 -34
  23. package/dist/middlewares/on-action.d.ts +87 -87
  24. package/dist/mobx-state-tree.js +6362 -6237
  25. package/dist/mobx-state-tree.min.js +12 -12
  26. package/dist/mobx-state-tree.module.js +6362 -6239
  27. package/dist/mobx-state-tree.umd.js +6342 -6217
  28. package/dist/mobx-state-tree.umd.min.js +11 -11
  29. package/dist/types/complex-types/array.d.ts +52 -52
  30. package/dist/types/complex-types/map.d.ts +80 -80
  31. package/dist/types/complex-types/model.d.ts +133 -133
  32. package/dist/types/index.d.ts +29 -29
  33. package/dist/types/primitives.d.ts +81 -81
  34. package/dist/types/utility-types/custom.d.ts +60 -60
  35. package/dist/types/utility-types/enumeration.d.ts +5 -5
  36. package/dist/types/utility-types/frozen.d.ts +11 -11
  37. package/dist/types/utility-types/identifier.d.ts +44 -44
  38. package/dist/types/utility-types/late.d.ts +10 -10
  39. package/dist/types/utility-types/literal.d.ts +25 -25
  40. package/dist/types/utility-types/maybe.d.ts +26 -26
  41. package/dist/types/utility-types/optional.d.ts +20 -20
  42. package/dist/types/utility-types/reference.d.ts +41 -41
  43. package/dist/types/utility-types/refinement.d.ts +10 -10
  44. package/dist/types/utility-types/snapshotProcessor.d.ts +61 -61
  45. package/dist/types/utility-types/union.d.ts +55 -55
  46. package/dist/utils.d.ts +4 -4
  47. package/package.json +22 -17
@@ -1,50 +1,50 @@
1
- import { IDisposer, IAnyStateTreeNode, IActionContext } from "../internal";
2
- export declare type IMiddlewareEventType = "action" | "flow_spawn" | "flow_resume" | "flow_resume_error" | "flow_return" | "flow_throw";
3
- export interface IMiddlewareEvent extends IActionContext {
4
- /** Event type */
5
- readonly type: IMiddlewareEventType;
6
- /** Parent event unique id */
7
- readonly parentId: number;
8
- /** Parent event object */
9
- readonly parentEvent: IMiddlewareEvent | undefined;
10
- /** Root event unique id */
11
- readonly rootId: number;
12
- /** Id of all events, from root until current (excluding current) */
13
- readonly allParentIds: number[];
14
- }
15
- export declare type IMiddlewareHandler = (actionCall: IMiddlewareEvent, next: (actionCall: IMiddlewareEvent, callback?: (value: any) => any) => void, abort: (value: any) => void) => any;
16
- /**
17
- * Middleware can be used to intercept any action is invoked on the subtree where it is attached.
18
- * If a tree is protected (by default), this means that any mutation of the tree will pass through your middleware.
19
- *
20
- * For more details, see the [middleware docs](../middleware.md)
21
- *
22
- * @param target Node to apply the middleware to.
23
- * @param middleware Middleware to apply.
24
- * @returns A callable function to dispose the middleware.
25
- */
26
- export declare function addMiddleware(target: IAnyStateTreeNode, handler: IMiddlewareHandler, includeHooks?: boolean): IDisposer;
27
- /**
28
- * Binds middleware to a specific action.
29
- *
30
- * Example:
31
- * ```ts
32
- * type.actions(self => {
33
- * function takeA____() {
34
- * self.toilet.donate()
35
- * self.wipe()
36
- * self.wipe()
37
- * self.toilet.flush()
38
- * }
39
- * return {
40
- * takeA____: decorate(atomic, takeA____)
41
- * }
42
- * })
43
- * ```
44
- *
45
- * @param handler
46
- * @param fn
47
- * @param includeHooks
48
- * @returns The original function
49
- */
50
- export declare function decorate<T extends Function>(handler: IMiddlewareHandler, fn: T, includeHooks?: boolean): T;
1
+ import { IDisposer, IAnyStateTreeNode, IActionContext } from "../internal";
2
+ export declare type IMiddlewareEventType = "action" | "flow_spawn" | "flow_resume" | "flow_resume_error" | "flow_return" | "flow_throw";
3
+ export interface IMiddlewareEvent extends IActionContext {
4
+ /** Event type */
5
+ readonly type: IMiddlewareEventType;
6
+ /** Parent event unique id */
7
+ readonly parentId: number;
8
+ /** Parent event object */
9
+ readonly parentEvent: IMiddlewareEvent | undefined;
10
+ /** Root event unique id */
11
+ readonly rootId: number;
12
+ /** Id of all events, from root until current (excluding current) */
13
+ readonly allParentIds: number[];
14
+ }
15
+ export declare type IMiddlewareHandler = (actionCall: IMiddlewareEvent, next: (actionCall: IMiddlewareEvent, callback?: (value: any) => any) => void, abort: (value: any) => void) => any;
16
+ /**
17
+ * Middleware can be used to intercept any action is invoked on the subtree where it is attached.
18
+ * If a tree is protected (by default), this means that any mutation of the tree will pass through your middleware.
19
+ *
20
+ * For more details, see the [middleware docs](concepts/middleware.md)
21
+ *
22
+ * @param target Node to apply the middleware to.
23
+ * @param middleware Middleware to apply.
24
+ * @returns A callable function to dispose the middleware.
25
+ */
26
+ export declare function addMiddleware(target: IAnyStateTreeNode, handler: IMiddlewareHandler, includeHooks?: boolean): IDisposer;
27
+ /**
28
+ * Binds middleware to a specific action.
29
+ *
30
+ * Example:
31
+ * ```ts
32
+ * type.actions(self => {
33
+ * function takeA____() {
34
+ * self.toilet.donate()
35
+ * self.wipe()
36
+ * self.wipe()
37
+ * self.toilet.flush()
38
+ * }
39
+ * return {
40
+ * takeA____: decorate(atomic, takeA____)
41
+ * }
42
+ * })
43
+ * ```
44
+ *
45
+ * @param handler
46
+ * @param fn
47
+ * @param includeHooks
48
+ * @returns The original function
49
+ */
50
+ export declare function decorate<T extends Function>(handler: IMiddlewareHandler, fn: T, includeHooks?: boolean): T;
@@ -1,27 +1,27 @@
1
- import { IAnyStateTreeNode, IMiddlewareEvent } from "../internal";
2
- export interface IActionContext {
3
- /** Event name (action name for actions) */
4
- readonly name: string;
5
- /** Event unique id */
6
- readonly id: number;
7
- /** Parent action event object */
8
- readonly parentActionEvent: IMiddlewareEvent | undefined;
9
- /** Event context (node where the action was invoked) */
10
- readonly context: IAnyStateTreeNode;
11
- /** Event tree (root node of the node where the action was invoked) */
12
- readonly tree: IAnyStateTreeNode;
13
- /** Event arguments in an array (action arguments for actions) */
14
- readonly args: any[];
15
- }
16
- /**
17
- * Returns the currently executing MST action context, or undefined if none.
18
- */
19
- export declare function getRunningActionContext(): IActionContext | undefined;
20
- /**
21
- * Returns if the given action context is a parent of this action context.
22
- */
23
- export declare function isActionContextChildOf(actionContext: IActionContext, parent: number | IActionContext | IMiddlewareEvent): boolean;
24
- /**
25
- * Returns if the given action context is this or a parent of this action context.
26
- */
27
- export declare function isActionContextThisOrChildOf(actionContext: IActionContext, parentOrThis: number | IActionContext | IMiddlewareEvent): boolean;
1
+ import { IAnyStateTreeNode, IMiddlewareEvent } from "../internal";
2
+ export interface IActionContext {
3
+ /** Event name (action name for actions) */
4
+ readonly name: string;
5
+ /** Event unique id */
6
+ readonly id: number;
7
+ /** Parent action event object */
8
+ readonly parentActionEvent: IMiddlewareEvent | undefined;
9
+ /** Event context (node where the action was invoked) */
10
+ readonly context: IAnyStateTreeNode;
11
+ /** Event tree (root node of the node where the action was invoked) */
12
+ readonly tree: IAnyStateTreeNode;
13
+ /** Event arguments in an array (action arguments for actions) */
14
+ readonly args: any[];
15
+ }
16
+ /**
17
+ * Returns the currently executing MST action context, or undefined if none.
18
+ */
19
+ export declare function getRunningActionContext(): IActionContext | undefined;
20
+ /**
21
+ * Returns if the given action context is a parent of this action context.
22
+ */
23
+ export declare function isActionContextChildOf(actionContext: IActionContext, parent: number | IActionContext | IMiddlewareEvent): boolean;
24
+ /**
25
+ * Returns if the given action context is this or a parent of this action context.
26
+ */
27
+ export declare function isActionContextThisOrChildOf(actionContext: IActionContext, parentOrThis: number | IActionContext | IMiddlewareEvent): boolean;
@@ -1,14 +1,63 @@
1
- /**
2
- * See [asynchronous actions](https://github.com/mobxjs/mobx-state-tree/blob/master/docs/async-actions.md).
3
- *
4
- * @returns The flow as a promise.
5
- */
6
- export declare function flow<R, Args extends any[]>(generator: (...args: Args) => Generator<any, R, any>): (...args: Args) => Promise<R>;
7
- /**
8
- * @deprecated Not needed since TS3.6.
9
- * Used for TypeScript to make flows that return a promise return the actual promise result.
10
- *
11
- * @param val
12
- * @returns
13
- */
14
- export declare function castFlowReturn<T>(val: T): T;
1
+ /**
2
+ * @hidden
3
+ */
4
+ export declare type FlowReturn<R> = R extends Promise<infer T> ? T : R;
5
+ /**
6
+ * See [asynchronous actions](concepts/async-actions.md).
7
+ *
8
+ * @returns The flow as a promise.
9
+ */
10
+ export declare function flow<R, Args extends any[]>(generator: (...args: Args) => Generator<Promise<any>, R, any>): (...args: Args) => Promise<FlowReturn<R>>;
11
+ /**
12
+ * @deprecated Not needed since TS3.6.
13
+ * Used for TypeScript to make flows that return a promise return the actual promise result.
14
+ *
15
+ * @param val
16
+ * @returns
17
+ */
18
+ export declare function castFlowReturn<T>(val: T): T;
19
+ /**
20
+ * @experimental
21
+ * experimental api - might change on minor/patch releases
22
+ *
23
+ * Convert a promise-returning function to a generator-returning one.
24
+ * This is intended to allow for usage of `yield*` in async actions to
25
+ * retain the promise return type.
26
+ *
27
+ * Example:
28
+ * ```ts
29
+ * function getDataAsync(input: string): Promise<number> { ... }
30
+ * const getDataGen = toGeneratorFunction(getDataAsync);
31
+ *
32
+ * const someModel.actions(self => ({
33
+ * someAction: flow(function*() {
34
+ * // value is typed as number
35
+ * const value = yield* getDataGen("input value");
36
+ * ...
37
+ * })
38
+ * }))
39
+ * ```
40
+ */
41
+ export declare function toGeneratorFunction<R, Args extends any[]>(p: (...args: Args) => Promise<R>): (...args: Args) => Generator<Promise<R>, R, R>;
42
+ /**
43
+ * @experimental
44
+ * experimental api - might change on minor/patch releases
45
+ *
46
+ * Convert a promise to a generator yielding that promise
47
+ * This is intended to allow for usage of `yield*` in async actions to
48
+ * retain the promise return type.
49
+ *
50
+ * Example:
51
+ * ```ts
52
+ * function getDataAsync(input: string): Promise<number> { ... }
53
+ *
54
+ * const someModel.actions(self => ({
55
+ * someAction: flow(function*() {
56
+ * // value is typed as number
57
+ * const value = yield* toGenerator(getDataAsync("input value"));
58
+ * ...
59
+ * })
60
+ * }))
61
+ * ```
62
+ */
63
+ export declare function toGenerator<R>(p: Promise<R>): Generator<Promise<R>, R, R>;
@@ -1,36 +1,36 @@
1
- /**
2
- * https://tools.ietf.org/html/rfc6902
3
- * http://jsonpatch.com/
4
- */
5
- export interface IJsonPatch {
6
- readonly op: "replace" | "add" | "remove";
7
- readonly path: string;
8
- readonly value?: any;
9
- }
10
- export interface IReversibleJsonPatch extends IJsonPatch {
11
- readonly oldValue: any;
12
- }
13
- /**
14
- * Escape slashes and backslashes.
15
- *
16
- * http://tools.ietf.org/html/rfc6901
17
- */
18
- export declare function escapeJsonPath(path: string): string;
19
- /**
20
- * Unescape slashes and backslashes.
21
- */
22
- export declare function unescapeJsonPath(path: string): string;
23
- /**
24
- * Generates a json-path compliant json path from path parts.
25
- *
26
- * @param path
27
- * @returns
28
- */
29
- export declare function joinJsonPath(path: string[]): string;
30
- /**
31
- * Splits and decodes a json path into several parts.
32
- *
33
- * @param path
34
- * @returns
35
- */
36
- export declare function splitJsonPath(path: string): string[];
1
+ /**
2
+ * https://tools.ietf.org/html/rfc6902
3
+ * http://jsonpatch.com/
4
+ */
5
+ export interface IJsonPatch {
6
+ readonly op: "replace" | "add" | "remove";
7
+ readonly path: string;
8
+ readonly value?: any;
9
+ }
10
+ export interface IReversibleJsonPatch extends IJsonPatch {
11
+ readonly oldValue: any;
12
+ }
13
+ /**
14
+ * Escape slashes and backslashes.
15
+ *
16
+ * http://tools.ietf.org/html/rfc6901
17
+ */
18
+ export declare function escapeJsonPath(path: string): string;
19
+ /**
20
+ * Unescape slashes and backslashes.
21
+ */
22
+ export declare function unescapeJsonPath(path: string): string;
23
+ /**
24
+ * Generates a json-path compliant json path from path parts.
25
+ *
26
+ * @param path
27
+ * @returns
28
+ */
29
+ export declare function joinJsonPath(path: string[]): string;
30
+ /**
31
+ * Splits and decodes a json path into several parts.
32
+ *
33
+ * @param path
34
+ * @returns
35
+ */
36
+ export declare function splitJsonPath(path: string): string[];