@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.
- package/package.json +2 -2
- package/dist/core/action.d.ts +0 -87
- package/dist/core/action.js +0 -228
- package/dist/core/action.js.map +0 -1
- package/dist/core/actionContext.d.ts +0 -27
- package/dist/core/actionContext.js +0 -42
- package/dist/core/actionContext.js.map +0 -1
- package/dist/core/flow.d.ts +0 -69
- package/dist/core/flow.js +0 -180
- package/dist/core/flow.js.map +0 -1
- package/dist/core/json-patch.d.ts +0 -46
- package/dist/core/json-patch.js +0 -133
- package/dist/core/json-patch.js.map +0 -1
- package/dist/core/mst-operations.d.ts +0 -459
- package/dist/core/mst-operations.js +0 -885
- package/dist/core/mst-operations.js.map +0 -1
- package/dist/core/node/BaseNode.d.ts +0 -62
- package/dist/core/node/BaseNode.js +0 -152
- package/dist/core/node/BaseNode.js.map +0 -1
- package/dist/core/node/Hook.d.ts +0 -17
- package/dist/core/node/Hook.js +0 -15
- package/dist/core/node/Hook.js.map +0 -1
- package/dist/core/node/create-node.d.ts +0 -16
- package/dist/core/node/create-node.js +0 -41
- package/dist/core/node/create-node.js.map +0 -1
- package/dist/core/node/identifier-cache.d.ts +0 -19
- package/dist/core/node/identifier-cache.js +0 -115
- package/dist/core/node/identifier-cache.js.map +0 -1
- package/dist/core/node/livelinessChecking.d.ts +0 -37
- package/dist/core/node/livelinessChecking.js +0 -38
- package/dist/core/node/livelinessChecking.js.map +0 -1
- package/dist/core/node/node-utils.d.ts +0 -83
- package/dist/core/node/node-utils.js +0 -165
- package/dist/core/node/node-utils.js.map +0 -1
- package/dist/core/node/object-node.d.ts +0 -99
- package/dist/core/node/object-node.js +0 -545
- package/dist/core/node/object-node.js.map +0 -1
- package/dist/core/node/scalar-node.d.ts +0 -19
- package/dist/core/node/scalar-node.js +0 -89
- package/dist/core/node/scalar-node.js.map +0 -1
- package/dist/core/process.d.ts +0 -50
- package/dist/core/process.js +0 -39
- package/dist/core/process.js.map +0 -1
- package/dist/core/type/type-checker.d.ts +0 -69
- package/dist/core/type/type-checker.js +0 -154
- package/dist/core/type/type-checker.js.map +0 -1
- package/dist/core/type/type.d.ts +0 -317
- package/dist/core/type/type.js +0 -251
- package/dist/core/type/type.js.map +0 -1
- package/dist/index.d.ts +0 -2
- package/dist/index.js +0 -85
- package/dist/index.js.map +0 -1
- package/dist/internal.d.ts +0 -39
- package/dist/internal.js +0 -60
- package/dist/internal.js.map +0 -1
- package/dist/middlewares/create-action-tracking-middleware.d.ts +0 -24
- package/dist/middlewares/create-action-tracking-middleware.js +0 -81
- package/dist/middlewares/create-action-tracking-middleware.js.map +0 -1
- package/dist/middlewares/createActionTrackingMiddleware2.d.ts +0 -34
- package/dist/middlewares/createActionTrackingMiddleware2.js +0 -133
- package/dist/middlewares/createActionTrackingMiddleware2.js.map +0 -1
- package/dist/middlewares/on-action.d.ts +0 -87
- package/dist/middlewares/on-action.js +0 -215
- package/dist/middlewares/on-action.js.map +0 -1
- package/dist/mobx-state-tree.js +0 -85
- package/dist/mobx-state-tree.module.js +0 -83
- package/dist/types/complex-types/array.d.ts +0 -80
- package/dist/types/complex-types/array.js +0 -352
- package/dist/types/complex-types/array.js.map +0 -1
- package/dist/types/complex-types/map.d.ts +0 -110
- package/dist/types/complex-types/map.js +0 -361
- package/dist/types/complex-types/map.js.map +0 -1
- package/dist/types/complex-types/model.d.ts +0 -192
- package/dist/types/complex-types/model.js +0 -477
- package/dist/types/complex-types/model.js.map +0 -1
- package/dist/types/index.d.ts +0 -33
- package/dist/types/index.js +0 -38
- package/dist/types/index.js.map +0 -1
- package/dist/types/primitives.d.ts +0 -124
- package/dist/types/primitives.js +0 -182
- package/dist/types/primitives.js.map +0 -1
- package/dist/types/utility-types/custom.d.ts +0 -74
- package/dist/types/utility-types/custom.js +0 -110
- package/dist/types/utility-types/custom.js.map +0 -1
- package/dist/types/utility-types/enumeration.d.ts +0 -5
- package/dist/types/utility-types/enumeration.js +0 -34
- package/dist/types/utility-types/enumeration.js.map +0 -1
- package/dist/types/utility-types/frozen.d.ts +0 -23
- package/dist/types/utility-types/frozen.js +0 -97
- package/dist/types/utility-types/frozen.js.map +0 -1
- package/dist/types/utility-types/identifier.d.ts +0 -86
- package/dist/types/utility-types/identifier.js +0 -129
- package/dist/types/utility-types/identifier.js.map +0 -1
- package/dist/types/utility-types/late.d.ts +0 -10
- package/dist/types/utility-types/late.js +0 -109
- package/dist/types/utility-types/late.js.map +0 -1
- package/dist/types/utility-types/lazy.d.ts +0 -22
- package/dist/types/utility-types/lazy.js +0 -76
- package/dist/types/utility-types/lazy.js.map +0 -1
- package/dist/types/utility-types/literal.d.ts +0 -37
- package/dist/types/utility-types/literal.js +0 -63
- package/dist/types/utility-types/literal.js.map +0 -1
- package/dist/types/utility-types/maybe.d.ts +0 -26
- package/dist/types/utility-types/maybe.js +0 -30
- package/dist/types/utility-types/maybe.js.map +0 -1
- package/dist/types/utility-types/optional.d.ts +0 -41
- package/dist/types/utility-types/optional.js +0 -140
- package/dist/types/utility-types/optional.js.map +0 -1
- package/dist/types/utility-types/reference.d.ts +0 -89
- package/dist/types/utility-types/reference.js +0 -392
- package/dist/types/utility-types/reference.js.map +0 -1
- package/dist/types/utility-types/refinement.d.ts +0 -10
- package/dist/types/utility-types/refinement.js +0 -85
- package/dist/types/utility-types/refinement.js.map +0 -1
- package/dist/types/utility-types/resilient.d.ts +0 -18
- package/dist/types/utility-types/resilient.js +0 -120
- package/dist/types/utility-types/resilient.js.map +0 -1
- package/dist/types/utility-types/snapshotProcessor.d.ts +0 -63
- package/dist/types/utility-types/snapshotProcessor.js +0 -161
- package/dist/types/utility-types/snapshotProcessor.js.map +0 -1
- package/dist/types/utility-types/union.d.ts +0 -77
- package/dist/types/utility-types/union.js +0 -245
- package/dist/types/utility-types/union.js.map +0 -1
- package/dist/utils.d.ts +0 -230
- package/dist/utils.js +0 -483
- package/dist/utils.js.map +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jbrowse/mobx-state-tree",
|
|
3
|
-
"version": "5.6.
|
|
3
|
+
"version": "5.6.3",
|
|
4
4
|
"description": "Fork of mobx-state-tree starting from v5.4.2 for use in jbrowse 2",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"main": "dist/mobx-state-tree.js",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
},
|
|
30
30
|
"repository": {
|
|
31
31
|
"type": "git",
|
|
32
|
-
"url": "https://github.com/GMOD/mobx-state-tree.git"
|
|
32
|
+
"url": "git+https://github.com/GMOD/mobx-state-tree.git"
|
|
33
33
|
},
|
|
34
34
|
"author": "Michel Weststrate",
|
|
35
35
|
"license": "MIT",
|
package/dist/core/action.d.ts
DELETED
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
import type { IActionContext, IAnyStateTreeNode, IDisposer } from "../internal.ts";
|
|
2
|
-
export 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 interface FunctionWithFlag extends Function {
|
|
16
|
-
_isMSTAction?: boolean;
|
|
17
|
-
_isFlowAction?: boolean;
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* @internal
|
|
21
|
-
* @hidden
|
|
22
|
-
*/
|
|
23
|
-
export type IMiddleware = {
|
|
24
|
-
handler: IMiddlewareHandler;
|
|
25
|
-
includeHooks: boolean;
|
|
26
|
-
};
|
|
27
|
-
export type IMiddlewareHandler = (actionCall: IMiddlewareEvent, next: (actionCall: IMiddlewareEvent, callback?: (value: any) => any) => void, abort: (value: any) => void) => any;
|
|
28
|
-
/**
|
|
29
|
-
* @internal
|
|
30
|
-
* @hidden
|
|
31
|
-
*/
|
|
32
|
-
export declare function getCurrentActionContext(): IMiddlewareEvent | undefined;
|
|
33
|
-
/**
|
|
34
|
-
* @internal
|
|
35
|
-
* @hidden
|
|
36
|
-
*/
|
|
37
|
-
export declare function getNextActionId(): number;
|
|
38
|
-
/**
|
|
39
|
-
* @internal
|
|
40
|
-
* @hidden
|
|
41
|
-
*/
|
|
42
|
-
export declare function runWithActionContext(context: IMiddlewareEvent, fn: Function): any;
|
|
43
|
-
/**
|
|
44
|
-
* @internal
|
|
45
|
-
* @hidden
|
|
46
|
-
*/
|
|
47
|
-
export declare function getParentActionContext(parentContext: IMiddlewareEvent | undefined): IMiddlewareEvent | undefined;
|
|
48
|
-
/**
|
|
49
|
-
* @internal
|
|
50
|
-
* @hidden
|
|
51
|
-
*/
|
|
52
|
-
export declare function createActionInvoker<T extends FunctionWithFlag>(target: IAnyStateTreeNode, name: string, fn: T): (...args: any[]) => any;
|
|
53
|
-
/**
|
|
54
|
-
* Middleware can be used to intercept any action is invoked on the subtree where it is attached.
|
|
55
|
-
* If a tree is protected (by default), this means that any mutation of the tree will pass through your middleware.
|
|
56
|
-
*
|
|
57
|
-
* For more details, see the [middleware docs](concepts/middleware.md)
|
|
58
|
-
*
|
|
59
|
-
* @param target Node to apply the middleware to.
|
|
60
|
-
* @param middleware Middleware to apply.
|
|
61
|
-
* @returns A callable function to dispose the middleware.
|
|
62
|
-
*/
|
|
63
|
-
export declare function addMiddleware(target: IAnyStateTreeNode, handler: IMiddlewareHandler, includeHooks?: boolean): IDisposer;
|
|
64
|
-
/**
|
|
65
|
-
* Binds middleware to a specific action.
|
|
66
|
-
*
|
|
67
|
-
* Example:
|
|
68
|
-
* ```ts
|
|
69
|
-
* type.actions(self => {
|
|
70
|
-
* function takeA____() {
|
|
71
|
-
* self.toilet.donate()
|
|
72
|
-
* self.wipe()
|
|
73
|
-
* self.wipe()
|
|
74
|
-
* self.toilet.flush()
|
|
75
|
-
* }
|
|
76
|
-
* return {
|
|
77
|
-
* takeA____: decorate(atomic, takeA____)
|
|
78
|
-
* }
|
|
79
|
-
* })
|
|
80
|
-
* ```
|
|
81
|
-
*
|
|
82
|
-
* @param handler
|
|
83
|
-
* @param fn
|
|
84
|
-
* @param includeHooks
|
|
85
|
-
* @returns The original function
|
|
86
|
-
*/
|
|
87
|
-
export declare function decorate<T extends Function>(handler: IMiddlewareHandler, fn: T, includeHooks?: boolean): T;
|
package/dist/core/action.js
DELETED
|
@@ -1,228 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getCurrentActionContext = getCurrentActionContext;
|
|
4
|
-
exports.getNextActionId = getNextActionId;
|
|
5
|
-
exports.runWithActionContext = runWithActionContext;
|
|
6
|
-
exports.getParentActionContext = getParentActionContext;
|
|
7
|
-
exports.createActionInvoker = createActionInvoker;
|
|
8
|
-
exports.addMiddleware = addMiddleware;
|
|
9
|
-
exports.decorate = decorate;
|
|
10
|
-
const mobx_1 = require("mobx");
|
|
11
|
-
const internal_ts_1 = require("../internal.js");
|
|
12
|
-
let nextActionId = 1;
|
|
13
|
-
let currentActionContext;
|
|
14
|
-
/**
|
|
15
|
-
* @internal
|
|
16
|
-
* @hidden
|
|
17
|
-
*/
|
|
18
|
-
function getCurrentActionContext() {
|
|
19
|
-
return currentActionContext;
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* @internal
|
|
23
|
-
* @hidden
|
|
24
|
-
*/
|
|
25
|
-
function getNextActionId() {
|
|
26
|
-
return nextActionId++;
|
|
27
|
-
}
|
|
28
|
-
// TODO: optimize away entire action context if there is no middleware in tree?
|
|
29
|
-
/**
|
|
30
|
-
* @internal
|
|
31
|
-
* @hidden
|
|
32
|
-
*/
|
|
33
|
-
function runWithActionContext(context, fn) {
|
|
34
|
-
const node = (0, internal_ts_1.getStateTreeNode)(context.context);
|
|
35
|
-
if (context.type === "action") {
|
|
36
|
-
node.assertAlive({
|
|
37
|
-
actionContext: context
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
const baseIsRunningAction = node._isRunningAction;
|
|
41
|
-
node._isRunningAction = true;
|
|
42
|
-
const previousContext = currentActionContext;
|
|
43
|
-
currentActionContext = context;
|
|
44
|
-
try {
|
|
45
|
-
return runMiddleWares(node, context, fn);
|
|
46
|
-
}
|
|
47
|
-
finally {
|
|
48
|
-
currentActionContext = previousContext;
|
|
49
|
-
node._isRunningAction = baseIsRunningAction;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* @internal
|
|
54
|
-
* @hidden
|
|
55
|
-
*/
|
|
56
|
-
function getParentActionContext(parentContext) {
|
|
57
|
-
if (!parentContext) {
|
|
58
|
-
return undefined;
|
|
59
|
-
}
|
|
60
|
-
if (parentContext.type === "action") {
|
|
61
|
-
return parentContext;
|
|
62
|
-
}
|
|
63
|
-
return parentContext.parentActionEvent;
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* @internal
|
|
67
|
-
* @hidden
|
|
68
|
-
*/
|
|
69
|
-
function createActionInvoker(target, name, fn) {
|
|
70
|
-
const res = function (...args) {
|
|
71
|
-
const id = getNextActionId();
|
|
72
|
-
const parentContext = currentActionContext;
|
|
73
|
-
const parentActionContext = getParentActionContext(parentContext);
|
|
74
|
-
return runWithActionContext({
|
|
75
|
-
type: "action",
|
|
76
|
-
name,
|
|
77
|
-
id,
|
|
78
|
-
args,
|
|
79
|
-
context: target,
|
|
80
|
-
tree: (0, internal_ts_1.getRoot)(target),
|
|
81
|
-
rootId: parentContext ? parentContext.rootId : id,
|
|
82
|
-
parentId: parentContext ? parentContext.id : 0,
|
|
83
|
-
allParentIds: parentContext
|
|
84
|
-
? [...parentContext.allParentIds, parentContext.id]
|
|
85
|
-
: [],
|
|
86
|
-
parentEvent: parentContext,
|
|
87
|
-
parentActionEvent: parentActionContext
|
|
88
|
-
}, fn);
|
|
89
|
-
};
|
|
90
|
-
res._isMSTAction = true;
|
|
91
|
-
res._isFlowAction = fn._isFlowAction;
|
|
92
|
-
return res;
|
|
93
|
-
}
|
|
94
|
-
/**
|
|
95
|
-
* Middleware can be used to intercept any action is invoked on the subtree where it is attached.
|
|
96
|
-
* If a tree is protected (by default), this means that any mutation of the tree will pass through your middleware.
|
|
97
|
-
*
|
|
98
|
-
* For more details, see the [middleware docs](concepts/middleware.md)
|
|
99
|
-
*
|
|
100
|
-
* @param target Node to apply the middleware to.
|
|
101
|
-
* @param middleware Middleware to apply.
|
|
102
|
-
* @returns A callable function to dispose the middleware.
|
|
103
|
-
*/
|
|
104
|
-
function addMiddleware(target, handler, includeHooks = true) {
|
|
105
|
-
const node = (0, internal_ts_1.getStateTreeNode)(target);
|
|
106
|
-
if ((0, internal_ts_1.devMode)()) {
|
|
107
|
-
if (!node.isProtectionEnabled) {
|
|
108
|
-
(0, internal_ts_1.warnError)("It is recommended to protect the state tree before attaching action middleware, as otherwise it cannot be guaranteed that all changes are passed through middleware. See `protect`");
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
return node.addMiddleWare(handler, includeHooks);
|
|
112
|
-
}
|
|
113
|
-
/**
|
|
114
|
-
* Binds middleware to a specific action.
|
|
115
|
-
*
|
|
116
|
-
* Example:
|
|
117
|
-
* ```ts
|
|
118
|
-
* type.actions(self => {
|
|
119
|
-
* function takeA____() {
|
|
120
|
-
* self.toilet.donate()
|
|
121
|
-
* self.wipe()
|
|
122
|
-
* self.wipe()
|
|
123
|
-
* self.toilet.flush()
|
|
124
|
-
* }
|
|
125
|
-
* return {
|
|
126
|
-
* takeA____: decorate(atomic, takeA____)
|
|
127
|
-
* }
|
|
128
|
-
* })
|
|
129
|
-
* ```
|
|
130
|
-
*
|
|
131
|
-
* @param handler
|
|
132
|
-
* @param fn
|
|
133
|
-
* @param includeHooks
|
|
134
|
-
* @returns The original function
|
|
135
|
-
*/
|
|
136
|
-
function decorate(handler, fn, includeHooks = true) {
|
|
137
|
-
const middleware = { handler, includeHooks };
|
|
138
|
-
fn.$mst_middleware = fn.$mst_middleware || [];
|
|
139
|
-
fn.$mst_middleware.push(middleware);
|
|
140
|
-
return fn;
|
|
141
|
-
}
|
|
142
|
-
class CollectedMiddlewares {
|
|
143
|
-
arrayIndex = 0;
|
|
144
|
-
inArrayIndex = 0;
|
|
145
|
-
middlewares = [];
|
|
146
|
-
constructor(node, fn) {
|
|
147
|
-
// we just push middleware arrays into an array of arrays to avoid making copies
|
|
148
|
-
if (fn.$mst_middleware) {
|
|
149
|
-
this.middlewares.push(fn.$mst_middleware);
|
|
150
|
-
}
|
|
151
|
-
let n = node;
|
|
152
|
-
// Find all middlewares. Optimization: cache this?
|
|
153
|
-
while (n) {
|
|
154
|
-
if (n.middlewares) {
|
|
155
|
-
this.middlewares.push(n.middlewares);
|
|
156
|
-
}
|
|
157
|
-
n = n.parent;
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
get isEmpty() {
|
|
161
|
-
return this.middlewares.length <= 0;
|
|
162
|
-
}
|
|
163
|
-
getNextMiddleware() {
|
|
164
|
-
const array = this.middlewares[this.arrayIndex];
|
|
165
|
-
if (!array) {
|
|
166
|
-
return undefined;
|
|
167
|
-
}
|
|
168
|
-
const item = array[this.inArrayIndex++];
|
|
169
|
-
if (!item) {
|
|
170
|
-
this.arrayIndex++;
|
|
171
|
-
this.inArrayIndex = 0;
|
|
172
|
-
return this.getNextMiddleware();
|
|
173
|
-
}
|
|
174
|
-
return item;
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
function runMiddleWares(node, baseCall, originalFn) {
|
|
178
|
-
const middlewares = new CollectedMiddlewares(node, originalFn);
|
|
179
|
-
// Short circuit
|
|
180
|
-
if (middlewares.isEmpty) {
|
|
181
|
-
return (0, mobx_1.action)(originalFn)(...baseCall.args);
|
|
182
|
-
}
|
|
183
|
-
let result = null;
|
|
184
|
-
function runNextMiddleware(call) {
|
|
185
|
-
const middleware = middlewares.getNextMiddleware();
|
|
186
|
-
const handler = middleware && middleware.handler;
|
|
187
|
-
if (!handler) {
|
|
188
|
-
return (0, mobx_1.action)(originalFn)(...call.args);
|
|
189
|
-
}
|
|
190
|
-
// skip hooks if asked to
|
|
191
|
-
if (!middleware.includeHooks && internal_ts_1.Hook[call.name]) {
|
|
192
|
-
return runNextMiddleware(call);
|
|
193
|
-
}
|
|
194
|
-
let nextInvoked = false;
|
|
195
|
-
function next(call2, callback) {
|
|
196
|
-
nextInvoked = true;
|
|
197
|
-
// the result can contain
|
|
198
|
-
// - the non manipulated return value from an action
|
|
199
|
-
// - the non manipulated abort value
|
|
200
|
-
// - one of the above but manipulated through the callback function
|
|
201
|
-
result = runNextMiddleware(call2);
|
|
202
|
-
if (callback) {
|
|
203
|
-
result = callback(result);
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
let abortInvoked = false;
|
|
207
|
-
function abort(value) {
|
|
208
|
-
abortInvoked = true;
|
|
209
|
-
// overwrite the result
|
|
210
|
-
// can be manipulated through middlewares earlier in the queue using the callback fn
|
|
211
|
-
result = value;
|
|
212
|
-
}
|
|
213
|
-
handler(call, next, abort);
|
|
214
|
-
if ((0, internal_ts_1.devMode)()) {
|
|
215
|
-
if (!nextInvoked && !abortInvoked) {
|
|
216
|
-
const node2 = (0, internal_ts_1.getStateTreeNode)(call.tree);
|
|
217
|
-
throw (0, internal_ts_1.fail)(`Neither the next() nor the abort() callback within the middleware ${handler.name} for the action: "${call.name}" on the node: ${node2.type.name} was invoked.`);
|
|
218
|
-
}
|
|
219
|
-
else if (nextInvoked && abortInvoked) {
|
|
220
|
-
const node2 = (0, internal_ts_1.getStateTreeNode)(call.tree);
|
|
221
|
-
throw (0, internal_ts_1.fail)(`The next() and abort() callback within the middleware ${handler.name} for the action: "${call.name}" on the node: ${node2.type.name} were invoked.`);
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
return result;
|
|
225
|
-
}
|
|
226
|
-
return runNextMiddleware(baseCall);
|
|
227
|
-
}
|
|
228
|
-
//# sourceMappingURL=action.js.map
|
package/dist/core/action.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"action.js","sourceRoot":"","sources":["../../src/core/action.ts"],"names":[],"mappings":";;AAqEA,0DAEC;AAMD,0CAEC;AAOD,oDAmBC;AAMD,wDAUC;AAMD,kDAgCC;AAYD,sCAcC;AAyBD,4BASC;AA3ND,+BAA2C;AAE3C,gDAOuB;AAqDvB,IAAI,YAAY,GAAG,CAAC,CAAA;AACpB,IAAI,oBAAkD,CAAA;AAEtD;;;GAGG;AACH,SAAgB,uBAAuB;IACrC,OAAO,oBAAoB,CAAA;AAC7B,CAAC;AAED;;;GAGG;AACH,SAAgB,eAAe;IAC7B,OAAO,YAAY,EAAE,CAAA;AACvB,CAAC;AAED,+EAA+E;AAC/E;;;GAGG;AACH,SAAgB,oBAAoB,CAAC,OAAyB,EAAE,EAAY;IAC1E,MAAM,IAAI,GAAG,IAAA,8BAAgB,EAAC,OAAO,CAAC,OAAO,CAAC,CAAA;IAE9C,IAAI,OAAO,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;QAC9B,IAAI,CAAC,WAAW,CAAC;YACf,aAAa,EAAE,OAAO;SACvB,CAAC,CAAA;IACJ,CAAC;IAED,MAAM,mBAAmB,GAAG,IAAI,CAAC,gBAAgB,CAAA;IACjD,IAAI,CAAC,gBAAgB,GAAG,IAAI,CAAA;IAC5B,MAAM,eAAe,GAAG,oBAAoB,CAAA;IAC5C,oBAAoB,GAAG,OAAO,CAAA;IAC9B,IAAI,CAAC;QACH,OAAO,cAAc,CAAC,IAAI,EAAE,OAAO,EAAE,EAAE,CAAC,CAAA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ACR,yDAAyD,OAAO,CAAC,IAAI,qBAAqB,IAAI,CAAC,IAAI,kBAAkB,KAAK,CAAC,IAAI,CAAC,IAAI,gBAAgB,CACrJ,CAAA;YACH,CAAC;QACH,CAAC;QACD,OAAO,MAAM,CAAA;IACf,CAAC;IACD,OAAO,iBAAiB,CAAC,QAAQ,CAAC,CAAA;AACpC,CAAC"}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { type IAnyStateTreeNode, type IMiddlewareEvent } from "../internal.ts";
|
|
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,42 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getRunningActionContext = getRunningActionContext;
|
|
4
|
-
exports.isActionContextChildOf = isActionContextChildOf;
|
|
5
|
-
exports.isActionContextThisOrChildOf = isActionContextThisOrChildOf;
|
|
6
|
-
const action_ts_1 = require("./action.js");
|
|
7
|
-
/**
|
|
8
|
-
* Returns the currently executing MST action context, or undefined if none.
|
|
9
|
-
*/
|
|
10
|
-
function getRunningActionContext() {
|
|
11
|
-
let current = (0, action_ts_1.getCurrentActionContext)();
|
|
12
|
-
while (current && current.type !== "action") {
|
|
13
|
-
current = current.parentActionEvent;
|
|
14
|
-
}
|
|
15
|
-
return current;
|
|
16
|
-
}
|
|
17
|
-
function _isActionContextThisOrChildOf(actionContext, sameOrParent, includeSame) {
|
|
18
|
-
const parentId = typeof sameOrParent === "number" ? sameOrParent : sameOrParent.id;
|
|
19
|
-
let current = includeSame
|
|
20
|
-
? actionContext
|
|
21
|
-
: actionContext.parentActionEvent;
|
|
22
|
-
while (current) {
|
|
23
|
-
if (current.id === parentId) {
|
|
24
|
-
return true;
|
|
25
|
-
}
|
|
26
|
-
current = current.parentActionEvent;
|
|
27
|
-
}
|
|
28
|
-
return false;
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Returns if the given action context is a parent of this action context.
|
|
32
|
-
*/
|
|
33
|
-
function isActionContextChildOf(actionContext, parent) {
|
|
34
|
-
return _isActionContextThisOrChildOf(actionContext, parent, false);
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Returns if the given action context is this or a parent of this action context.
|
|
38
|
-
*/
|
|
39
|
-
function isActionContextThisOrChildOf(actionContext, parentOrThis) {
|
|
40
|
-
return _isActionContextThisOrChildOf(actionContext, parentOrThis, true);
|
|
41
|
-
}
|
|
42
|
-
//# sourceMappingURL=actionContext.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"actionContext.js","sourceRoot":"","sources":["../../src/core/actionContext.ts"],"names":[],"mappings":";;AAyBA,0DAMC;AAyBD,wDAKC;AAKD,oEAKC;AAtED,2CAAqD;AAqBrD;;GAEG;AACH,SAAgB,uBAAuB;IACrC,IAAI,OAAO,GAAG,IAAA,mCAAuB,GAAE,CAAA;IACvC,OAAO,OAAO,IAAI,OAAO,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;QAC5C,OAAO,GAAG,OAAO,CAAC,iBAAiB,CAAA;IACrC,CAAC;IACD,OAAO,OAAO,CAAA;AAChB,CAAC;AAED,SAAS,6BAA6B,CACpC,aAA6B,EAC7B,YAAwD,EACxD,WAAoB;IAEpB,MAAM,QAAQ,GACZ,OAAO,YAAY,KAAK,QAAQ,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,YAAY,CAAC,EAAE,CAAA;IAEnE,IAAI,OAAO,GAAkD,WAAW;QACtE,CAAC,CAAC,aAAa;QACf,CAAC,CAAC,aAAa,CAAC,iBAAiB,CAAA;IACnC,OAAO,OAAO,EAAE,CAAC;QACf,IAAI,OAAO,CAAC,EAAE,KAAK,QAAQ,EAAE,CAAC;YAC5B,OAAO,IAAI,CAAA;QACb,CAAC;QACD,OAAO,GAAG,OAAO,CAAC,iBAAiB,CAAA;IACrC,CAAC;IACD,OAAO,KAAK,CAAA;AACd,CAAC;AAED;;GAEG;AACH,SAAgB,sBAAsB,CACpC,aAA6B,EAC7B,MAAkD;IAElD,OAAO,6BAA6B,CAAC,aAAa,EAAE,MAAM,EAAE,KAAK,CAAC,CAAA;AACpE,CAAC;AAED;;GAEG;AACH,SAAgB,4BAA4B,CAC1C,aAA6B,EAC7B,YAAwD;IAExD,OAAO,6BAA6B,CAAC,aAAa,EAAE,YAAY,EAAE,IAAI,CAAC,CAAA;AACzE,CAAC"}
|
package/dist/core/flow.d.ts
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import type { FunctionWithFlag } from "./action.ts";
|
|
2
|
-
/**
|
|
3
|
-
* @hidden
|
|
4
|
-
*/
|
|
5
|
-
export type FlowReturn<R> = R extends Promise<infer T> ? T : R;
|
|
6
|
-
/**
|
|
7
|
-
* See [asynchronous actions](concepts/async-actions.md).
|
|
8
|
-
*
|
|
9
|
-
* @returns The flow as a promise.
|
|
10
|
-
*/
|
|
11
|
-
export declare function flow<R, Args extends any[]>(generator: (...args: Args) => Generator<PromiseLike<any>, R, any>): (...args: Args) => Promise<FlowReturn<R>>;
|
|
12
|
-
/**
|
|
13
|
-
* @deprecated Not needed since TS3.6.
|
|
14
|
-
* Used for TypeScript to make flows that return a promise return the actual promise result.
|
|
15
|
-
*
|
|
16
|
-
* @param val
|
|
17
|
-
* @returns
|
|
18
|
-
*/
|
|
19
|
-
export declare function castFlowReturn<T>(val: T): T;
|
|
20
|
-
/**
|
|
21
|
-
* @experimental
|
|
22
|
-
* experimental api - might change on minor/patch releases
|
|
23
|
-
*
|
|
24
|
-
* Convert a promise-returning function to a generator-returning one.
|
|
25
|
-
* This is intended to allow for usage of `yield*` in async actions to
|
|
26
|
-
* retain the promise return type.
|
|
27
|
-
*
|
|
28
|
-
* Example:
|
|
29
|
-
* ```ts
|
|
30
|
-
* function getDataAsync(input: string): Promise<number> { ... }
|
|
31
|
-
* const getDataGen = toGeneratorFunction(getDataAsync);
|
|
32
|
-
*
|
|
33
|
-
* const someModel.actions(self => ({
|
|
34
|
-
* someAction: flow(function*() {
|
|
35
|
-
* // value is typed as number
|
|
36
|
-
* const value = yield* getDataGen("input value");
|
|
37
|
-
* ...
|
|
38
|
-
* })
|
|
39
|
-
* }))
|
|
40
|
-
* ```
|
|
41
|
-
*/
|
|
42
|
-
export declare function toGeneratorFunction<R, Args extends any[]>(p: (...args: Args) => Promise<R>): (...args: Args) => Generator<Promise<R>, R, R>;
|
|
43
|
-
/**
|
|
44
|
-
* @experimental
|
|
45
|
-
* experimental api - might change on minor/patch releases
|
|
46
|
-
*
|
|
47
|
-
* Convert a promise to a generator yielding that promise
|
|
48
|
-
* This is intended to allow for usage of `yield*` in async actions to
|
|
49
|
-
* retain the promise return type.
|
|
50
|
-
*
|
|
51
|
-
* Example:
|
|
52
|
-
* ```ts
|
|
53
|
-
* function getDataAsync(input: string): Promise<number> { ... }
|
|
54
|
-
*
|
|
55
|
-
* const someModel.actions(self => ({
|
|
56
|
-
* someAction: flow(function*() {
|
|
57
|
-
* // value is typed as number
|
|
58
|
-
* const value = yield* toGenerator(getDataAsync("input value"));
|
|
59
|
-
* ...
|
|
60
|
-
* })
|
|
61
|
-
* }))
|
|
62
|
-
* ```
|
|
63
|
-
*/
|
|
64
|
-
export declare function toGenerator<R>(p: Promise<R>): Generator<Promise<R>, R, R>;
|
|
65
|
-
/**
|
|
66
|
-
* @internal
|
|
67
|
-
* @hidden
|
|
68
|
-
*/
|
|
69
|
-
export declare function createFlowSpawner(name: string, generator: FunctionWithFlag): (this: any, ...flowArgs: any[]) => Promise<unknown>;
|
package/dist/core/flow.js
DELETED
|
@@ -1,180 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.flow = flow;
|
|
4
|
-
exports.castFlowReturn = castFlowReturn;
|
|
5
|
-
exports.toGeneratorFunction = toGeneratorFunction;
|
|
6
|
-
exports.toGenerator = toGenerator;
|
|
7
|
-
exports.createFlowSpawner = createFlowSpawner;
|
|
8
|
-
const utils_ts_1 = require("../utils.js");
|
|
9
|
-
const action_ts_1 = require("./action.js");
|
|
10
|
-
/**
|
|
11
|
-
* See [asynchronous actions](concepts/async-actions.md).
|
|
12
|
-
*
|
|
13
|
-
* @returns The flow as a promise.
|
|
14
|
-
*/
|
|
15
|
-
function flow(generator) {
|
|
16
|
-
return createFlowSpawner(generator.name, generator);
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* @deprecated Not needed since TS3.6.
|
|
20
|
-
* Used for TypeScript to make flows that return a promise return the actual promise result.
|
|
21
|
-
*
|
|
22
|
-
* @param val
|
|
23
|
-
* @returns
|
|
24
|
-
*/
|
|
25
|
-
function castFlowReturn(val) {
|
|
26
|
-
return val;
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* @experimental
|
|
30
|
-
* experimental api - might change on minor/patch releases
|
|
31
|
-
*
|
|
32
|
-
* Convert a promise-returning function to a generator-returning one.
|
|
33
|
-
* This is intended to allow for usage of `yield*` in async actions to
|
|
34
|
-
* retain the promise return type.
|
|
35
|
-
*
|
|
36
|
-
* Example:
|
|
37
|
-
* ```ts
|
|
38
|
-
* function getDataAsync(input: string): Promise<number> { ... }
|
|
39
|
-
* const getDataGen = toGeneratorFunction(getDataAsync);
|
|
40
|
-
*
|
|
41
|
-
* const someModel.actions(self => ({
|
|
42
|
-
* someAction: flow(function*() {
|
|
43
|
-
* // value is typed as number
|
|
44
|
-
* const value = yield* getDataGen("input value");
|
|
45
|
-
* ...
|
|
46
|
-
* })
|
|
47
|
-
* }))
|
|
48
|
-
* ```
|
|
49
|
-
*/
|
|
50
|
-
function toGeneratorFunction(p) {
|
|
51
|
-
return function* (...args) {
|
|
52
|
-
return (yield p(...args));
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* @experimental
|
|
57
|
-
* experimental api - might change on minor/patch releases
|
|
58
|
-
*
|
|
59
|
-
* Convert a promise to a generator yielding that promise
|
|
60
|
-
* This is intended to allow for usage of `yield*` in async actions to
|
|
61
|
-
* retain the promise return type.
|
|
62
|
-
*
|
|
63
|
-
* Example:
|
|
64
|
-
* ```ts
|
|
65
|
-
* function getDataAsync(input: string): Promise<number> { ... }
|
|
66
|
-
*
|
|
67
|
-
* const someModel.actions(self => ({
|
|
68
|
-
* someAction: flow(function*() {
|
|
69
|
-
* // value is typed as number
|
|
70
|
-
* const value = yield* toGenerator(getDataAsync("input value"));
|
|
71
|
-
* ...
|
|
72
|
-
* })
|
|
73
|
-
* }))
|
|
74
|
-
* ```
|
|
75
|
-
*/
|
|
76
|
-
function* toGenerator(p) {
|
|
77
|
-
return (yield p);
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* @internal
|
|
81
|
-
* @hidden
|
|
82
|
-
*/
|
|
83
|
-
function createFlowSpawner(name, generator) {
|
|
84
|
-
const spawner = function flowSpawner(...flowArgs) {
|
|
85
|
-
// Implementation based on https://github.com/tj/co/blob/master/index.js
|
|
86
|
-
const runId = (0, action_ts_1.getNextActionId)();
|
|
87
|
-
const parentContext = (0, action_ts_1.getCurrentActionContext)();
|
|
88
|
-
if (!parentContext) {
|
|
89
|
-
throw (0, utils_ts_1.fail)("a mst flow must always have a parent context");
|
|
90
|
-
}
|
|
91
|
-
const parentActionContext = (0, action_ts_1.getParentActionContext)(parentContext);
|
|
92
|
-
if (!parentActionContext) {
|
|
93
|
-
throw (0, utils_ts_1.fail)("a mst flow must always have a parent action context");
|
|
94
|
-
}
|
|
95
|
-
const contextBase = {
|
|
96
|
-
name,
|
|
97
|
-
id: runId,
|
|
98
|
-
tree: parentContext.tree,
|
|
99
|
-
context: parentContext.context,
|
|
100
|
-
parentId: parentContext.id,
|
|
101
|
-
allParentIds: [...parentContext.allParentIds, parentContext.id],
|
|
102
|
-
rootId: parentContext.rootId,
|
|
103
|
-
parentEvent: parentContext,
|
|
104
|
-
parentActionEvent: parentActionContext
|
|
105
|
-
};
|
|
106
|
-
function wrap(fn, type, arg) {
|
|
107
|
-
fn.$mst_middleware = spawner.$mst_middleware; // pick up any middleware attached to the flow
|
|
108
|
-
return (0, action_ts_1.runWithActionContext)({
|
|
109
|
-
...contextBase,
|
|
110
|
-
type,
|
|
111
|
-
args: [arg]
|
|
112
|
-
}, fn);
|
|
113
|
-
}
|
|
114
|
-
return new Promise(function (resolve, reject) {
|
|
115
|
-
let gen;
|
|
116
|
-
const init = function asyncActionInit(...initArgs) {
|
|
117
|
-
gen = generator(...initArgs);
|
|
118
|
-
onFulfilled(undefined); // kick off the flow
|
|
119
|
-
};
|
|
120
|
-
init.$mst_middleware = spawner.$mst_middleware;
|
|
121
|
-
(0, action_ts_1.runWithActionContext)({
|
|
122
|
-
...contextBase,
|
|
123
|
-
type: "flow_spawn",
|
|
124
|
-
args: flowArgs
|
|
125
|
-
}, init);
|
|
126
|
-
function onFulfilled(res) {
|
|
127
|
-
let ret;
|
|
128
|
-
try {
|
|
129
|
-
// prettier-ignore
|
|
130
|
-
const cancelError = wrap((_r) => { ret = gen.next(_r); }, "flow_resume", res);
|
|
131
|
-
if (cancelError instanceof Error) {
|
|
132
|
-
ret = gen.throw(cancelError);
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
catch (e) {
|
|
136
|
-
// prettier-ignore
|
|
137
|
-
(0, utils_ts_1.setImmediateWithFallback)(() => {
|
|
138
|
-
wrap((_r) => { reject(e); }, "flow_throw", e);
|
|
139
|
-
});
|
|
140
|
-
return;
|
|
141
|
-
}
|
|
142
|
-
next(ret);
|
|
143
|
-
return;
|
|
144
|
-
}
|
|
145
|
-
function onRejected(err) {
|
|
146
|
-
let ret;
|
|
147
|
-
try {
|
|
148
|
-
// prettier-ignore
|
|
149
|
-
wrap((_r) => { ret = gen.throw(_r); }, "flow_resume_error", err); // or yieldError?
|
|
150
|
-
}
|
|
151
|
-
catch (e) {
|
|
152
|
-
// prettier-ignore
|
|
153
|
-
(0, utils_ts_1.setImmediateWithFallback)(() => {
|
|
154
|
-
wrap((_r) => { reject(e); }, "flow_throw", e);
|
|
155
|
-
});
|
|
156
|
-
return;
|
|
157
|
-
}
|
|
158
|
-
next(ret);
|
|
159
|
-
}
|
|
160
|
-
function next(ret) {
|
|
161
|
-
if (ret.done) {
|
|
162
|
-
// prettier-ignore
|
|
163
|
-
(0, utils_ts_1.setImmediateWithFallback)(() => {
|
|
164
|
-
wrap((r) => { resolve(r); }, "flow_return", ret.value);
|
|
165
|
-
});
|
|
166
|
-
return;
|
|
167
|
-
}
|
|
168
|
-
// TODO: support more type of values? See https://github.com/tj/co/blob/249bbdc72da24ae44076afd716349d2089b31c4c/index.js#L100
|
|
169
|
-
if (!ret.value || typeof ret.value.then !== "function") {
|
|
170
|
-
// istanbul ignore next
|
|
171
|
-
throw (0, utils_ts_1.fail)("Only promises can be yielded to `async`, got: " + ret);
|
|
172
|
-
}
|
|
173
|
-
return ret.value.then(onFulfilled, onRejected);
|
|
174
|
-
}
|
|
175
|
-
});
|
|
176
|
-
};
|
|
177
|
-
spawner._isFlowAction = true;
|
|
178
|
-
return spawner;
|
|
179
|
-
}
|
|
180
|
-
//# sourceMappingURL=flow.js.map
|
package/dist/core/flow.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"flow.js","sourceRoot":"","sources":["../../src/core/flow.ts"],"names":[],"mappings":";;AAoBA,oBAIC;AASD,wCAEC;AAwBD,kDAMC;AAuBD,kCAEC;AAMD,8CA2GC;AA3MD,0CAA4D;AAC5D,2CAKoB;AASpB;;;;GAIG;AACH,SAAgB,IAAI,CAClB,SAAiE;IAEjE,OAAO,iBAAiB,CAAC,SAAS,CAAC,IAAI,EAAE,SAAS,CAAQ,CAAA;AAC5D,CAAC;AAED;;;;;;GAMG;AACH,SAAgB,cAAc,CAAI,GAAM;IACtC,OAAO,GAAU,CAAA;AACnB,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,SAAgB,mBAAmB,CACjC,CAAgC;IAEhC,OAAO,QAAQ,CAAC,EAAE,GAAG,IAAU;QAC7B,OAAO,CAAC,MAAM,CAAC,CAAC,GAAG,IAAI,CAAC,CAAM,CAAA;IAChC,CAAC,CAAA;AACH,CAAC;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,QAAe,CAAC,CAAC,WAAW,CAAI,CAAa;IAC3C,OAAO,CAAC,MAAM,CAAC,CAAM,CAAA;AACvB,CAAC;AAED;;;GAGG;AACH,SAAgB,iBAAiB,CAAC,IAAY,EAAE,SAA2B;IACzE,MAAM,OAAO,GAAG,SAAS,WAAW,CAAY,GAAG,QAAe;QAChE,wEAAwE;QACxE,MAAM,KAAK,GAAG,IAAA,2BAAe,GAAE,CAAA;QAC/B,MAAM,aAAa,GAAG,IAAA,mCAAuB,G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