@jbrowse/mobx-state-tree 5.7.1 → 5.8.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (253) hide show
  1. package/README.md +0 -10
  2. package/dist/index.d.ts +2135 -2
  3. package/dist/mobx-state-tree.cjs +6894 -0
  4. package/dist/mobx-state-tree.cjs.map +1 -0
  5. package/dist/mobx-state-tree.mjs +6814 -0
  6. package/dist/mobx-state-tree.mjs.map +1 -0
  7. package/package.json +30 -26
  8. package/dist/core/action.d.ts +0 -87
  9. package/dist/core/action.js +0 -228
  10. package/dist/core/action.js.map +0 -1
  11. package/dist/core/actionContext.d.ts +0 -27
  12. package/dist/core/actionContext.js +0 -42
  13. package/dist/core/actionContext.js.map +0 -1
  14. package/dist/core/flow.d.ts +0 -69
  15. package/dist/core/flow.js +0 -180
  16. package/dist/core/flow.js.map +0 -1
  17. package/dist/core/json-patch.d.ts +0 -46
  18. package/dist/core/json-patch.js +0 -133
  19. package/dist/core/json-patch.js.map +0 -1
  20. package/dist/core/mst-operations.d.ts +0 -459
  21. package/dist/core/mst-operations.js +0 -885
  22. package/dist/core/mst-operations.js.map +0 -1
  23. package/dist/core/node/BaseNode.d.ts +0 -62
  24. package/dist/core/node/BaseNode.js +0 -152
  25. package/dist/core/node/BaseNode.js.map +0 -1
  26. package/dist/core/node/Hook.d.ts +0 -17
  27. package/dist/core/node/Hook.js +0 -15
  28. package/dist/core/node/Hook.js.map +0 -1
  29. package/dist/core/node/create-node.d.ts +0 -16
  30. package/dist/core/node/create-node.js +0 -41
  31. package/dist/core/node/create-node.js.map +0 -1
  32. package/dist/core/node/identifier-cache.d.ts +0 -19
  33. package/dist/core/node/identifier-cache.js +0 -115
  34. package/dist/core/node/identifier-cache.js.map +0 -1
  35. package/dist/core/node/livelinessChecking.d.ts +0 -37
  36. package/dist/core/node/livelinessChecking.js +0 -38
  37. package/dist/core/node/livelinessChecking.js.map +0 -1
  38. package/dist/core/node/node-utils.d.ts +0 -83
  39. package/dist/core/node/node-utils.js +0 -165
  40. package/dist/core/node/node-utils.js.map +0 -1
  41. package/dist/core/node/object-node.d.ts +0 -101
  42. package/dist/core/node/object-node.js +0 -546
  43. package/dist/core/node/object-node.js.map +0 -1
  44. package/dist/core/node/scalar-node.d.ts +0 -21
  45. package/dist/core/node/scalar-node.js +0 -90
  46. package/dist/core/node/scalar-node.js.map +0 -1
  47. package/dist/core/process.d.ts +0 -50
  48. package/dist/core/process.js +0 -39
  49. package/dist/core/process.js.map +0 -1
  50. package/dist/core/type/type-checker.d.ts +0 -69
  51. package/dist/core/type/type-checker.js +0 -154
  52. package/dist/core/type/type-checker.js.map +0 -1
  53. package/dist/core/type/type.d.ts +0 -317
  54. package/dist/core/type/type.js +0 -251
  55. package/dist/core/type/type.js.map +0 -1
  56. package/dist/index.js +0 -85
  57. package/dist/index.js.map +0 -1
  58. package/dist/internal.d.ts +0 -39
  59. package/dist/internal.js +0 -60
  60. package/dist/internal.js.map +0 -1
  61. package/dist/middlewares/create-action-tracking-middleware.d.ts +0 -24
  62. package/dist/middlewares/create-action-tracking-middleware.js +0 -81
  63. package/dist/middlewares/create-action-tracking-middleware.js.map +0 -1
  64. package/dist/middlewares/createActionTrackingMiddleware2.d.ts +0 -34
  65. package/dist/middlewares/createActionTrackingMiddleware2.js +0 -133
  66. package/dist/middlewares/createActionTrackingMiddleware2.js.map +0 -1
  67. package/dist/middlewares/on-action.d.ts +0 -87
  68. package/dist/middlewares/on-action.js +0 -215
  69. package/dist/middlewares/on-action.js.map +0 -1
  70. package/dist/package.json +0 -1
  71. package/dist/types/complex-types/array.d.ts +0 -81
  72. package/dist/types/complex-types/array.js +0 -353
  73. package/dist/types/complex-types/array.js.map +0 -1
  74. package/dist/types/complex-types/map.d.ts +0 -111
  75. package/dist/types/complex-types/map.js +0 -362
  76. package/dist/types/complex-types/map.js.map +0 -1
  77. package/dist/types/complex-types/model.d.ts +0 -193
  78. package/dist/types/complex-types/model.js +0 -478
  79. package/dist/types/complex-types/model.js.map +0 -1
  80. package/dist/types/index.d.ts +0 -33
  81. package/dist/types/index.js +0 -38
  82. package/dist/types/index.js.map +0 -1
  83. package/dist/types/primitives.d.ts +0 -125
  84. package/dist/types/primitives.js +0 -183
  85. package/dist/types/primitives.js.map +0 -1
  86. package/dist/types/utility-types/custom.d.ts +0 -75
  87. package/dist/types/utility-types/custom.js +0 -111
  88. package/dist/types/utility-types/custom.js.map +0 -1
  89. package/dist/types/utility-types/enumeration.d.ts +0 -5
  90. package/dist/types/utility-types/enumeration.js +0 -34
  91. package/dist/types/utility-types/enumeration.js.map +0 -1
  92. package/dist/types/utility-types/frozen.d.ts +0 -24
  93. package/dist/types/utility-types/frozen.js +0 -98
  94. package/dist/types/utility-types/frozen.js.map +0 -1
  95. package/dist/types/utility-types/identifier.d.ts +0 -87
  96. package/dist/types/utility-types/identifier.js +0 -130
  97. package/dist/types/utility-types/identifier.js.map +0 -1
  98. package/dist/types/utility-types/late.d.ts +0 -10
  99. package/dist/types/utility-types/late.js +0 -110
  100. package/dist/types/utility-types/late.js.map +0 -1
  101. package/dist/types/utility-types/lazy.d.ts +0 -23
  102. package/dist/types/utility-types/lazy.js +0 -77
  103. package/dist/types/utility-types/lazy.js.map +0 -1
  104. package/dist/types/utility-types/literal.d.ts +0 -38
  105. package/dist/types/utility-types/literal.js +0 -64
  106. package/dist/types/utility-types/literal.js.map +0 -1
  107. package/dist/types/utility-types/maybe.d.ts +0 -26
  108. package/dist/types/utility-types/maybe.js +0 -30
  109. package/dist/types/utility-types/maybe.js.map +0 -1
  110. package/dist/types/utility-types/optional.d.ts +0 -42
  111. package/dist/types/utility-types/optional.js +0 -141
  112. package/dist/types/utility-types/optional.js.map +0 -1
  113. package/dist/types/utility-types/reference.d.ts +0 -90
  114. package/dist/types/utility-types/reference.js +0 -393
  115. package/dist/types/utility-types/reference.js.map +0 -1
  116. package/dist/types/utility-types/refinement.d.ts +0 -10
  117. package/dist/types/utility-types/refinement.js +0 -86
  118. package/dist/types/utility-types/refinement.js.map +0 -1
  119. package/dist/types/utility-types/resilient.d.ts +0 -18
  120. package/dist/types/utility-types/resilient.js +0 -121
  121. package/dist/types/utility-types/resilient.js.map +0 -1
  122. package/dist/types/utility-types/snapshotProcessor.d.ts +0 -63
  123. package/dist/types/utility-types/snapshotProcessor.js +0 -162
  124. package/dist/types/utility-types/snapshotProcessor.js.map +0 -1
  125. package/dist/types/utility-types/union.d.ts +0 -78
  126. package/dist/types/utility-types/union.js +0 -246
  127. package/dist/types/utility-types/union.js.map +0 -1
  128. package/dist/utils.d.ts +0 -230
  129. package/dist/utils.js +0 -483
  130. package/dist/utils.js.map +0 -1
  131. package/esm/core/action.d.ts +0 -87
  132. package/esm/core/action.js +0 -219
  133. package/esm/core/action.js.map +0 -1
  134. package/esm/core/actionContext.d.ts +0 -27
  135. package/esm/core/actionContext.js +0 -37
  136. package/esm/core/actionContext.js.map +0 -1
  137. package/esm/core/flow.d.ts +0 -69
  138. package/esm/core/flow.js +0 -173
  139. package/esm/core/flow.js.map +0 -1
  140. package/esm/core/json-patch.d.ts +0 -46
  141. package/esm/core/json-patch.js +0 -125
  142. package/esm/core/json-patch.js.map +0 -1
  143. package/esm/core/mst-operations.d.ts +0 -459
  144. package/esm/core/mst-operations.js +0 -844
  145. package/esm/core/mst-operations.js.map +0 -1
  146. package/esm/core/node/BaseNode.d.ts +0 -62
  147. package/esm/core/node/BaseNode.js +0 -148
  148. package/esm/core/node/BaseNode.js.map +0 -1
  149. package/esm/core/node/Hook.d.ts +0 -17
  150. package/esm/core/node/Hook.js +0 -12
  151. package/esm/core/node/Hook.js.map +0 -1
  152. package/esm/core/node/create-node.d.ts +0 -16
  153. package/esm/core/node/create-node.js +0 -36
  154. package/esm/core/node/create-node.js.map +0 -1
  155. package/esm/core/node/identifier-cache.d.ts +0 -19
  156. package/esm/core/node/identifier-cache.js +0 -111
  157. package/esm/core/node/identifier-cache.js.map +0 -1
  158. package/esm/core/node/livelinessChecking.d.ts +0 -37
  159. package/esm/core/node/livelinessChecking.js +0 -33
  160. package/esm/core/node/livelinessChecking.js.map +0 -1
  161. package/esm/core/node/node-utils.d.ts +0 -83
  162. package/esm/core/node/node-utils.js +0 -153
  163. package/esm/core/node/node-utils.js.map +0 -1
  164. package/esm/core/node/object-node.d.ts +0 -101
  165. package/esm/core/node/object-node.js +0 -542
  166. package/esm/core/node/object-node.js.map +0 -1
  167. package/esm/core/node/scalar-node.d.ts +0 -21
  168. package/esm/core/node/scalar-node.js +0 -86
  169. package/esm/core/node/scalar-node.js.map +0 -1
  170. package/esm/core/process.d.ts +0 -50
  171. package/esm/core/process.js +0 -35
  172. package/esm/core/process.js.map +0 -1
  173. package/esm/core/type/type-checker.d.ts +0 -69
  174. package/esm/core/type/type-checker.js +0 -144
  175. package/esm/core/type/type-checker.js.map +0 -1
  176. package/esm/core/type/type.d.ts +0 -317
  177. package/esm/core/type/type.js +0 -243
  178. package/esm/core/type/type.js.map +0 -1
  179. package/esm/index.d.ts +0 -2
  180. package/esm/index.js +0 -2
  181. package/esm/index.js.map +0 -1
  182. package/esm/internal.d.ts +0 -39
  183. package/esm/internal.js +0 -44
  184. package/esm/internal.js.map +0 -1
  185. package/esm/middlewares/create-action-tracking-middleware.d.ts +0 -24
  186. package/esm/middlewares/create-action-tracking-middleware.js +0 -78
  187. package/esm/middlewares/create-action-tracking-middleware.js.map +0 -1
  188. package/esm/middlewares/createActionTrackingMiddleware2.d.ts +0 -34
  189. package/esm/middlewares/createActionTrackingMiddleware2.js +0 -130
  190. package/esm/middlewares/createActionTrackingMiddleware2.js.map +0 -1
  191. package/esm/middlewares/on-action.d.ts +0 -87
  192. package/esm/middlewares/on-action.js +0 -210
  193. package/esm/middlewares/on-action.js.map +0 -1
  194. package/esm/types/complex-types/array.d.ts +0 -81
  195. package/esm/types/complex-types/array.js +0 -347
  196. package/esm/types/complex-types/array.js.map +0 -1
  197. package/esm/types/complex-types/map.d.ts +0 -111
  198. package/esm/types/complex-types/map.js +0 -356
  199. package/esm/types/complex-types/map.js.map +0 -1
  200. package/esm/types/complex-types/model.d.ts +0 -193
  201. package/esm/types/complex-types/model.js +0 -471
  202. package/esm/types/complex-types/model.js.map +0 -1
  203. package/esm/types/index.d.ts +0 -33
  204. package/esm/types/index.js +0 -35
  205. package/esm/types/index.js.map +0 -1
  206. package/esm/types/primitives.d.ts +0 -125
  207. package/esm/types/primitives.js +0 -177
  208. package/esm/types/primitives.js.map +0 -1
  209. package/esm/types/utility-types/custom.d.ts +0 -75
  210. package/esm/types/utility-types/custom.js +0 -106
  211. package/esm/types/utility-types/custom.js.map +0 -1
  212. package/esm/types/utility-types/enumeration.d.ts +0 -5
  213. package/esm/types/utility-types/enumeration.js +0 -31
  214. package/esm/types/utility-types/enumeration.js.map +0 -1
  215. package/esm/types/utility-types/frozen.d.ts +0 -24
  216. package/esm/types/utility-types/frozen.js +0 -92
  217. package/esm/types/utility-types/frozen.js.map +0 -1
  218. package/esm/types/utility-types/identifier.d.ts +0 -87
  219. package/esm/types/utility-types/identifier.js +0 -121
  220. package/esm/types/utility-types/identifier.js.map +0 -1
  221. package/esm/types/utility-types/late.d.ts +0 -10
  222. package/esm/types/utility-types/late.js +0 -106
  223. package/esm/types/utility-types/late.js.map +0 -1
  224. package/esm/types/utility-types/lazy.d.ts +0 -23
  225. package/esm/types/utility-types/lazy.js +0 -72
  226. package/esm/types/utility-types/lazy.js.map +0 -1
  227. package/esm/types/utility-types/literal.d.ts +0 -38
  228. package/esm/types/utility-types/literal.js +0 -58
  229. package/esm/types/utility-types/literal.js.map +0 -1
  230. package/esm/types/utility-types/maybe.d.ts +0 -26
  231. package/esm/types/utility-types/maybe.js +0 -26
  232. package/esm/types/utility-types/maybe.js.map +0 -1
  233. package/esm/types/utility-types/optional.d.ts +0 -42
  234. package/esm/types/utility-types/optional.js +0 -135
  235. package/esm/types/utility-types/optional.js.map +0 -1
  236. package/esm/types/utility-types/reference.d.ts +0 -90
  237. package/esm/types/utility-types/reference.js +0 -383
  238. package/esm/types/utility-types/reference.js.map +0 -1
  239. package/esm/types/utility-types/refinement.d.ts +0 -10
  240. package/esm/types/utility-types/refinement.js +0 -82
  241. package/esm/types/utility-types/refinement.js.map +0 -1
  242. package/esm/types/utility-types/resilient.d.ts +0 -18
  243. package/esm/types/utility-types/resilient.js +0 -118
  244. package/esm/types/utility-types/resilient.js.map +0 -1
  245. package/esm/types/utility-types/snapshotProcessor.d.ts +0 -63
  246. package/esm/types/utility-types/snapshotProcessor.js +0 -159
  247. package/esm/types/utility-types/snapshotProcessor.js.map +0 -1
  248. package/esm/types/utility-types/union.d.ts +0 -78
  249. package/esm/types/utility-types/union.js +0 -240
  250. package/esm/types/utility-types/union.js.map +0 -1
  251. package/esm/utils.d.ts +0 -230
  252. package/esm/utils.js +0 -449
  253. package/esm/utils.js.map +0 -1
@@ -1,219 +0,0 @@
1
- import { action as mobxAction } from "mobx";
2
- import { Hook, devMode, fail, getRoot, getStateTreeNode, warnError } from "../internal.js";
3
- let nextActionId = 1;
4
- let currentActionContext;
5
- /**
6
- * @internal
7
- * @hidden
8
- */
9
- export function getCurrentActionContext() {
10
- return currentActionContext;
11
- }
12
- /**
13
- * @internal
14
- * @hidden
15
- */
16
- export function getNextActionId() {
17
- return nextActionId++;
18
- }
19
- // TODO: optimize away entire action context if there is no middleware in tree?
20
- /**
21
- * @internal
22
- * @hidden
23
- */
24
- export function runWithActionContext(context, fn) {
25
- const node = getStateTreeNode(context.context);
26
- if (context.type === "action") {
27
- node.assertAlive({
28
- actionContext: context
29
- });
30
- }
31
- const baseIsRunningAction = node._isRunningAction;
32
- node._isRunningAction = true;
33
- const previousContext = currentActionContext;
34
- currentActionContext = context;
35
- try {
36
- return runMiddleWares(node, context, fn);
37
- }
38
- finally {
39
- currentActionContext = previousContext;
40
- node._isRunningAction = baseIsRunningAction;
41
- }
42
- }
43
- /**
44
- * @internal
45
- * @hidden
46
- */
47
- export function getParentActionContext(parentContext) {
48
- if (!parentContext) {
49
- return undefined;
50
- }
51
- if (parentContext.type === "action") {
52
- return parentContext;
53
- }
54
- return parentContext.parentActionEvent;
55
- }
56
- /**
57
- * @internal
58
- * @hidden
59
- */
60
- export function createActionInvoker(target, name, fn) {
61
- const res = function (...args) {
62
- const id = getNextActionId();
63
- const parentContext = currentActionContext;
64
- const parentActionContext = getParentActionContext(parentContext);
65
- return runWithActionContext({
66
- type: "action",
67
- name,
68
- id,
69
- args,
70
- context: target,
71
- tree: getRoot(target),
72
- rootId: parentContext ? parentContext.rootId : id,
73
- parentId: parentContext ? parentContext.id : 0,
74
- allParentIds: parentContext
75
- ? [...parentContext.allParentIds, parentContext.id]
76
- : [],
77
- parentEvent: parentContext,
78
- parentActionEvent: parentActionContext
79
- }, fn);
80
- };
81
- res._isMSTAction = true;
82
- res._isFlowAction = fn._isFlowAction;
83
- return res;
84
- }
85
- /**
86
- * Middleware can be used to intercept any action is invoked on the subtree where it is attached.
87
- * If a tree is protected (by default), this means that any mutation of the tree will pass through your middleware.
88
- *
89
- * For more details, see the [middleware docs](concepts/middleware.md)
90
- *
91
- * @param target Node to apply the middleware to.
92
- * @param middleware Middleware to apply.
93
- * @returns A callable function to dispose the middleware.
94
- */
95
- export function addMiddleware(target, handler, includeHooks = true) {
96
- const node = getStateTreeNode(target);
97
- if (devMode()) {
98
- if (!node.isProtectionEnabled) {
99
- 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`");
100
- }
101
- }
102
- return node.addMiddleWare(handler, includeHooks);
103
- }
104
- /**
105
- * Binds middleware to a specific action.
106
- *
107
- * Example:
108
- * ```ts
109
- * type.actions(self => {
110
- * function takeA____() {
111
- * self.toilet.donate()
112
- * self.wipe()
113
- * self.wipe()
114
- * self.toilet.flush()
115
- * }
116
- * return {
117
- * takeA____: decorate(atomic, takeA____)
118
- * }
119
- * })
120
- * ```
121
- *
122
- * @param handler
123
- * @param fn
124
- * @param includeHooks
125
- * @returns The original function
126
- */
127
- export function decorate(handler, fn, includeHooks = true) {
128
- const middleware = { handler, includeHooks };
129
- fn.$mst_middleware = fn.$mst_middleware || [];
130
- fn.$mst_middleware.push(middleware);
131
- return fn;
132
- }
133
- class CollectedMiddlewares {
134
- arrayIndex = 0;
135
- inArrayIndex = 0;
136
- middlewares = [];
137
- constructor(node, fn) {
138
- // we just push middleware arrays into an array of arrays to avoid making copies
139
- if (fn.$mst_middleware) {
140
- this.middlewares.push(fn.$mst_middleware);
141
- }
142
- let n = node;
143
- // Find all middlewares. Optimization: cache this?
144
- while (n) {
145
- if (n.middlewares) {
146
- this.middlewares.push(n.middlewares);
147
- }
148
- n = n.parent;
149
- }
150
- }
151
- get isEmpty() {
152
- return this.middlewares.length <= 0;
153
- }
154
- getNextMiddleware() {
155
- const array = this.middlewares[this.arrayIndex];
156
- if (!array) {
157
- return undefined;
158
- }
159
- const item = array[this.inArrayIndex++];
160
- if (!item) {
161
- this.arrayIndex++;
162
- this.inArrayIndex = 0;
163
- return this.getNextMiddleware();
164
- }
165
- return item;
166
- }
167
- }
168
- function runMiddleWares(node, baseCall, originalFn) {
169
- const middlewares = new CollectedMiddlewares(node, originalFn);
170
- // Short circuit
171
- if (middlewares.isEmpty) {
172
- return mobxAction(originalFn)(...baseCall.args);
173
- }
174
- let result = null;
175
- function runNextMiddleware(call) {
176
- const middleware = middlewares.getNextMiddleware();
177
- const handler = middleware && middleware.handler;
178
- if (!handler) {
179
- return mobxAction(originalFn)(...call.args);
180
- }
181
- // skip hooks if asked to
182
- if (!middleware.includeHooks && Hook[call.name]) {
183
- return runNextMiddleware(call);
184
- }
185
- let nextInvoked = false;
186
- function next(call2, callback) {
187
- nextInvoked = true;
188
- // the result can contain
189
- // - the non manipulated return value from an action
190
- // - the non manipulated abort value
191
- // - one of the above but manipulated through the callback function
192
- result = runNextMiddleware(call2);
193
- if (callback) {
194
- result = callback(result);
195
- }
196
- }
197
- let abortInvoked = false;
198
- function abort(value) {
199
- abortInvoked = true;
200
- // overwrite the result
201
- // can be manipulated through middlewares earlier in the queue using the callback fn
202
- result = value;
203
- }
204
- handler(call, next, abort);
205
- if (devMode()) {
206
- if (!nextInvoked && !abortInvoked) {
207
- const node2 = getStateTreeNode(call.tree);
208
- throw 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.`);
209
- }
210
- else if (nextInvoked && abortInvoked) {
211
- const node2 = getStateTreeNode(call.tree);
212
- throw fail(`The next() and abort() callback within the middleware ${handler.name} for the action: "${call.name}" on the node: ${node2.type.name} were invoked.`);
213
- }
214
- }
215
- return result;
216
- }
217
- return runNextMiddleware(baseCall);
218
- }
219
- //# sourceMappingURL=action.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"action.js","sourceRoot":"","sources":["../../src/core/action.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,UAAU,EAAE,MAAM,MAAM,CAAA;AAE3C,OAAO,EACL,IAAI,EACJ,OAAO,EACP,IAAI,EACJ,OAAO,EACP,gBAAgB,EAChB,SAAS,EACV,MAAM,gBAAgB,CAAA;AAqDvB,IAAI,YAAY,GAAG,CAAC,CAAA;AACpB,IAAI,oBAAkD,CAAA;AAEtD;;;GAGG;AACH,MAAM,UAAU,uBAAuB;IACrC,OAAO,oBAAoB,CAAA;AAC7B,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,eAAe;IAC7B,OAAO,YAAY,EAAE,CAAA;AACvB,CAAC;AAED,+EAA+E;AAC/E;;;GAGG;AACH,MAAM,UAAU,oBAAoB,CAAC,OAAyB,EAAE,EAAY;IAC1E,MAAM,IAAI,GAAG,gBAAgB,CAAC,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,gBAA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AChK,CAAA;YACH,CAAC;iBAAM,IAAI,WAAW,IAAI,YAAY,EAAE,CAAC;gBACvC,MAAM,KAAK,GAAG,gBAAgB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;gBACzC,MAAM,IAAI,CACR,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","sourcesContent":["import { action as mobxAction } from \"mobx\"\n\nimport {\n Hook,\n devMode,\n fail,\n getRoot,\n getStateTreeNode,\n warnError\n} from \"../internal.ts\"\n\nimport type {\n AnyObjectNode,\n IActionContext,\n IAnyStateTreeNode,\n IDisposer\n} from \"../internal.ts\"\n\nexport type IMiddlewareEventType =\n | \"action\"\n | \"flow_spawn\"\n | \"flow_resume\"\n | \"flow_resume_error\"\n | \"flow_return\"\n | \"flow_throw\"\n// | \"task_spawn TODO, see #273\"\n\nexport interface IMiddlewareEvent extends IActionContext {\n /** Event type */\n readonly type: IMiddlewareEventType\n\n /** Parent event unique id */\n readonly parentId: number\n /** Parent event object */\n readonly parentEvent: IMiddlewareEvent | undefined\n\n /** Root event unique id */\n readonly rootId: number\n /** Id of all events, from root until current (excluding current) */\n readonly allParentIds: number[]\n}\n\nexport interface FunctionWithFlag extends Function {\n _isMSTAction?: boolean\n _isFlowAction?: boolean\n}\n\n/**\n * @internal\n * @hidden\n */\nexport type IMiddleware = {\n handler: IMiddlewareHandler\n includeHooks: boolean\n}\n\nexport type IMiddlewareHandler = (\n actionCall: IMiddlewareEvent,\n next: (actionCall: IMiddlewareEvent, callback?: (value: any) => any) => void,\n abort: (value: any) => void\n) => any\n\nlet nextActionId = 1\nlet currentActionContext: IMiddlewareEvent | undefined\n\n/**\n * @internal\n * @hidden\n */\nexport function getCurrentActionContext() {\n return currentActionContext\n}\n\n/**\n * @internal\n * @hidden\n */\nexport function getNextActionId() {\n return nextActionId++\n}\n\n// TODO: optimize away entire action context if there is no middleware in tree?\n/**\n * @internal\n * @hidden\n */\nexport function runWithActionContext(context: IMiddlewareEvent, fn: Function) {\n const node = getStateTreeNode(context.context)\n\n if (context.type === \"action\") {\n node.assertAlive({\n actionContext: context\n })\n }\n\n const baseIsRunningAction = node._isRunningAction\n node._isRunningAction = true\n const previousContext = currentActionContext\n currentActionContext = context\n try {\n return runMiddleWares(node, context, fn)\n } finally {\n currentActionContext = previousContext\n node._isRunningAction = baseIsRunningAction\n }\n}\n\n/**\n * @internal\n * @hidden\n */\nexport function getParentActionContext(\n parentContext: IMiddlewareEvent | undefined\n) {\n if (!parentContext) {\n return undefined\n }\n if (parentContext.type === \"action\") {\n return parentContext\n }\n return parentContext.parentActionEvent\n}\n\n/**\n * @internal\n * @hidden\n */\nexport function createActionInvoker<T extends FunctionWithFlag>(\n target: IAnyStateTreeNode,\n name: string,\n fn: T\n) {\n const res = function (...args: any[]) {\n const id = getNextActionId()\n const parentContext = currentActionContext\n const parentActionContext = getParentActionContext(parentContext)\n\n return runWithActionContext(\n {\n type: \"action\",\n name,\n id,\n args,\n context: target,\n tree: getRoot(target),\n rootId: parentContext ? parentContext.rootId : id,\n parentId: parentContext ? parentContext.id : 0,\n allParentIds: parentContext\n ? [...parentContext.allParentIds, parentContext.id]\n : [],\n parentEvent: parentContext,\n parentActionEvent: parentActionContext\n },\n fn\n )\n }\n ;(res as FunctionWithFlag)._isMSTAction = true\n ;(res as FunctionWithFlag)._isFlowAction = fn._isFlowAction\n return res\n}\n\n/**\n * Middleware can be used to intercept any action is invoked on the subtree where it is attached.\n * If a tree is protected (by default), this means that any mutation of the tree will pass through your middleware.\n *\n * For more details, see the [middleware docs](concepts/middleware.md)\n *\n * @param target Node to apply the middleware to.\n * @param middleware Middleware to apply.\n * @returns A callable function to dispose the middleware.\n */\nexport function addMiddleware(\n target: IAnyStateTreeNode,\n handler: IMiddlewareHandler,\n includeHooks: boolean = true\n): IDisposer {\n const node = getStateTreeNode(target)\n if (devMode()) {\n if (!node.isProtectionEnabled) {\n warnError(\n \"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`\"\n )\n }\n }\n return node.addMiddleWare(handler, includeHooks)\n}\n\n/**\n * Binds middleware to a specific action.\n *\n * Example:\n * ```ts\n * type.actions(self => {\n * function takeA____() {\n * self.toilet.donate()\n * self.wipe()\n * self.wipe()\n * self.toilet.flush()\n * }\n * return {\n * takeA____: decorate(atomic, takeA____)\n * }\n * })\n * ```\n *\n * @param handler\n * @param fn\n * @param includeHooks\n * @returns The original function\n */\nexport function decorate<T extends Function>(\n handler: IMiddlewareHandler,\n fn: T,\n includeHooks = true\n): T {\n const middleware: IMiddleware = { handler, includeHooks }\n ;(fn as any).$mst_middleware = (fn as any).$mst_middleware || []\n ;(fn as any).$mst_middleware.push(middleware)\n return fn\n}\n\nclass CollectedMiddlewares {\n private arrayIndex = 0\n private inArrayIndex = 0\n private middlewares: IMiddleware[][] = []\n\n constructor(node: AnyObjectNode, fn: Function) {\n // we just push middleware arrays into an array of arrays to avoid making copies\n if ((fn as any).$mst_middleware) {\n this.middlewares.push((fn as any).$mst_middleware)\n }\n let n: AnyObjectNode | null = node\n // Find all middlewares. Optimization: cache this?\n while (n) {\n if (n.middlewares) {\n this.middlewares.push(n.middlewares)\n }\n n = n.parent\n }\n }\n\n get isEmpty() {\n return this.middlewares.length <= 0\n }\n\n getNextMiddleware(): IMiddleware | undefined {\n const array = this.middlewares[this.arrayIndex]\n if (!array) {\n return undefined\n }\n const item = array[this.inArrayIndex++]\n if (!item) {\n this.arrayIndex++\n this.inArrayIndex = 0\n return this.getNextMiddleware()\n }\n return item\n }\n}\n\nfunction runMiddleWares(\n node: AnyObjectNode,\n baseCall: IMiddlewareEvent,\n originalFn: Function\n): any {\n const middlewares = new CollectedMiddlewares(node, originalFn)\n // Short circuit\n if (middlewares.isEmpty) {\n return mobxAction(originalFn)(...baseCall.args)\n }\n\n let result: any = null\n\n function runNextMiddleware(call: IMiddlewareEvent): any {\n const middleware = middlewares.getNextMiddleware()\n const handler = middleware && middleware.handler\n\n if (!handler) {\n return mobxAction(originalFn)(...call.args)\n }\n\n // skip hooks if asked to\n if (!middleware!.includeHooks && (Hook as any)[call.name]) {\n return runNextMiddleware(call)\n }\n\n let nextInvoked = false\n function next(\n call2: IMiddlewareEvent,\n callback?: (value: any) => any\n ): void {\n nextInvoked = true\n // the result can contain\n // - the non manipulated return value from an action\n // - the non manipulated abort value\n // - one of the above but manipulated through the callback function\n result = runNextMiddleware(call2)\n if (callback) {\n result = callback(result)\n }\n }\n\n let abortInvoked = false\n function abort(value: any) {\n abortInvoked = true\n // overwrite the result\n // can be manipulated through middlewares earlier in the queue using the callback fn\n result = value\n }\n\n handler(call, next, abort)\n if (devMode()) {\n if (!nextInvoked && !abortInvoked) {\n const node2 = getStateTreeNode(call.tree)\n throw fail(\n `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.`\n )\n } else if (nextInvoked && abortInvoked) {\n const node2 = getStateTreeNode(call.tree)\n throw fail(\n `The next() and abort() callback within the middleware ${handler.name} for the action: \"${call.name}\" on the node: ${node2.type.name} were invoked.`\n )\n }\n }\n return result\n }\n return runNextMiddleware(baseCall)\n}\n"]}
@@ -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,37 +0,0 @@
1
- import { getCurrentActionContext } from "./action.js";
2
- /**
3
- * Returns the currently executing MST action context, or undefined if none.
4
- */
5
- export function getRunningActionContext() {
6
- let current = getCurrentActionContext();
7
- while (current && current.type !== "action") {
8
- current = current.parentActionEvent;
9
- }
10
- return current;
11
- }
12
- function _isActionContextThisOrChildOf(actionContext, sameOrParent, includeSame) {
13
- const parentId = typeof sameOrParent === "number" ? sameOrParent : sameOrParent.id;
14
- let current = includeSame
15
- ? actionContext
16
- : actionContext.parentActionEvent;
17
- while (current) {
18
- if (current.id === parentId) {
19
- return true;
20
- }
21
- current = current.parentActionEvent;
22
- }
23
- return false;
24
- }
25
- /**
26
- * Returns if the given action context is a parent of this action context.
27
- */
28
- export function isActionContextChildOf(actionContext, parent) {
29
- return _isActionContextThisOrChildOf(actionContext, parent, false);
30
- }
31
- /**
32
- * Returns if the given action context is this or a parent of this action context.
33
- */
34
- export function isActionContextThisOrChildOf(actionContext, parentOrThis) {
35
- return _isActionContextThisOrChildOf(actionContext, parentOrThis, true);
36
- }
37
- //# sourceMappingURL=actionContext.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"actionContext.js","sourceRoot":"","sources":["../../src/core/actionContext.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAA;AAqBrD;;GAEG;AACH,MAAM,UAAU,uBAAuB;IACrC,IAAI,OAAO,GAAG,uBAAuB,EAAE,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,MAAM,UAAU,sBAAsB,CACpC,aAA6B,EAC7B,MAAkD;IAElD,OAAO,6BAA6B,CAAC,aAAa,EAAE,MAAM,EAAE,KAAK,CAAC,CAAA;AACpE,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,4BAA4B,CAC1C,aAA6B,EAC7B,YAAwD;IAExD,OAAO,6BAA6B,CAAC,aAAa,EAAE,YAAY,EAAE,IAAI,CAAC,CAAA;AACzE,CAAC","sourcesContent":["import { type IAnyStateTreeNode, type IMiddlewareEvent } from \"../internal.ts\"\nimport { getCurrentActionContext } from \"./action.ts\"\n\nexport interface IActionContext {\n /** Event name (action name for actions) */\n readonly name: string\n\n /** Event unique id */\n readonly id: number\n\n /** Parent action event object */\n readonly parentActionEvent: IMiddlewareEvent | undefined\n\n /** Event context (node where the action was invoked) */\n readonly context: IAnyStateTreeNode\n /** Event tree (root node of the node where the action was invoked) */\n readonly tree: IAnyStateTreeNode\n\n /** Event arguments in an array (action arguments for actions) */\n readonly args: any[]\n}\n\n/**\n * Returns the currently executing MST action context, or undefined if none.\n */\nexport function getRunningActionContext(): IActionContext | undefined {\n let current = getCurrentActionContext()\n while (current && current.type !== \"action\") {\n current = current.parentActionEvent\n }\n return current\n}\n\nfunction _isActionContextThisOrChildOf(\n actionContext: IActionContext,\n sameOrParent: number | IActionContext | IMiddlewareEvent,\n includeSame: boolean\n) {\n const parentId =\n typeof sameOrParent === \"number\" ? sameOrParent : sameOrParent.id\n\n let current: IActionContext | IMiddlewareEvent | undefined = includeSame\n ? actionContext\n : actionContext.parentActionEvent\n while (current) {\n if (current.id === parentId) {\n return true\n }\n current = current.parentActionEvent\n }\n return false\n}\n\n/**\n * Returns if the given action context is a parent of this action context.\n */\nexport function isActionContextChildOf(\n actionContext: IActionContext,\n parent: number | IActionContext | IMiddlewareEvent\n) {\n return _isActionContextThisOrChildOf(actionContext, parent, false)\n}\n\n/**\n * Returns if the given action context is this or a parent of this action context.\n */\nexport function isActionContextThisOrChildOf(\n actionContext: IActionContext,\n parentOrThis: number | IActionContext | IMiddlewareEvent\n) {\n return _isActionContextThisOrChildOf(actionContext, parentOrThis, true)\n}\n"]}
@@ -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/esm/core/flow.js DELETED
@@ -1,173 +0,0 @@
1
- import { fail, setImmediateWithFallback } from "../utils.js";
2
- import { getCurrentActionContext, getNextActionId, getParentActionContext, runWithActionContext } from "./action.js";
3
- /**
4
- * See [asynchronous actions](concepts/async-actions.md).
5
- *
6
- * @returns The flow as a promise.
7
- */
8
- export function flow(generator) {
9
- return createFlowSpawner(generator.name, generator);
10
- }
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 function castFlowReturn(val) {
19
- return val;
20
- }
21
- /**
22
- * @experimental
23
- * experimental api - might change on minor/patch releases
24
- *
25
- * Convert a promise-returning function to a generator-returning one.
26
- * This is intended to allow for usage of `yield*` in async actions to
27
- * retain the promise return type.
28
- *
29
- * Example:
30
- * ```ts
31
- * function getDataAsync(input: string): Promise<number> { ... }
32
- * const getDataGen = toGeneratorFunction(getDataAsync);
33
- *
34
- * const someModel.actions(self => ({
35
- * someAction: flow(function*() {
36
- * // value is typed as number
37
- * const value = yield* getDataGen("input value");
38
- * ...
39
- * })
40
- * }))
41
- * ```
42
- */
43
- export function toGeneratorFunction(p) {
44
- return function* (...args) {
45
- return (yield p(...args));
46
- };
47
- }
48
- /**
49
- * @experimental
50
- * experimental api - might change on minor/patch releases
51
- *
52
- * Convert a promise to a generator yielding that promise
53
- * This is intended to allow for usage of `yield*` in async actions to
54
- * retain the promise return type.
55
- *
56
- * Example:
57
- * ```ts
58
- * function getDataAsync(input: string): Promise<number> { ... }
59
- *
60
- * const someModel.actions(self => ({
61
- * someAction: flow(function*() {
62
- * // value is typed as number
63
- * const value = yield* toGenerator(getDataAsync("input value"));
64
- * ...
65
- * })
66
- * }))
67
- * ```
68
- */
69
- export function* toGenerator(p) {
70
- return (yield p);
71
- }
72
- /**
73
- * @internal
74
- * @hidden
75
- */
76
- export function createFlowSpawner(name, generator) {
77
- const spawner = function flowSpawner(...flowArgs) {
78
- // Implementation based on https://github.com/tj/co/blob/master/index.js
79
- const runId = getNextActionId();
80
- const parentContext = getCurrentActionContext();
81
- if (!parentContext) {
82
- throw fail("a mst flow must always have a parent context");
83
- }
84
- const parentActionContext = getParentActionContext(parentContext);
85
- if (!parentActionContext) {
86
- throw fail("a mst flow must always have a parent action context");
87
- }
88
- const contextBase = {
89
- name,
90
- id: runId,
91
- tree: parentContext.tree,
92
- context: parentContext.context,
93
- parentId: parentContext.id,
94
- allParentIds: [...parentContext.allParentIds, parentContext.id],
95
- rootId: parentContext.rootId,
96
- parentEvent: parentContext,
97
- parentActionEvent: parentActionContext
98
- };
99
- function wrap(fn, type, arg) {
100
- fn.$mst_middleware = spawner.$mst_middleware; // pick up any middleware attached to the flow
101
- return runWithActionContext({
102
- ...contextBase,
103
- type,
104
- args: [arg]
105
- }, fn);
106
- }
107
- return new Promise(function (resolve, reject) {
108
- let gen;
109
- const init = function asyncActionInit(...initArgs) {
110
- gen = generator(...initArgs);
111
- onFulfilled(undefined); // kick off the flow
112
- };
113
- init.$mst_middleware = spawner.$mst_middleware;
114
- runWithActionContext({
115
- ...contextBase,
116
- type: "flow_spawn",
117
- args: flowArgs
118
- }, init);
119
- function onFulfilled(res) {
120
- let ret;
121
- try {
122
- // prettier-ignore
123
- const cancelError = wrap((_r) => { ret = gen.next(_r); }, "flow_resume", res);
124
- if (cancelError instanceof Error) {
125
- ret = gen.throw(cancelError);
126
- }
127
- }
128
- catch (e) {
129
- // prettier-ignore
130
- setImmediateWithFallback(() => {
131
- wrap((_r) => { reject(e); }, "flow_throw", e);
132
- });
133
- return;
134
- }
135
- next(ret);
136
- return;
137
- }
138
- function onRejected(err) {
139
- let ret;
140
- try {
141
- // prettier-ignore
142
- wrap((_r) => { ret = gen.throw(_r); }, "flow_resume_error", err); // or yieldError?
143
- }
144
- catch (e) {
145
- // prettier-ignore
146
- setImmediateWithFallback(() => {
147
- wrap((_r) => { reject(e); }, "flow_throw", e);
148
- });
149
- return;
150
- }
151
- next(ret);
152
- }
153
- function next(ret) {
154
- if (ret.done) {
155
- // prettier-ignore
156
- setImmediateWithFallback(() => {
157
- wrap((r) => { resolve(r); }, "flow_return", ret.value);
158
- });
159
- return;
160
- }
161
- // TODO: support more type of values? See https://github.com/tj/co/blob/249bbdc72da24ae44076afd716349d2089b31c4c/index.js#L100
162
- if (!ret.value || typeof ret.value.then !== "function") {
163
- // istanbul ignore next
164
- throw fail("Only promises can be yielded to `async`, got: " + ret);
165
- }
166
- return ret.value.then(onFulfilled, onRejected);
167
- }
168
- });
169
- };
170
- spawner._isFlowAction = true;
171
- return spawner;
172
- }
173
- //# sourceMappingURL=flow.js.map
@@ -1 +0,0 @@
1
- {"version":3,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wBAChB,IAAI,CAAC,CAAC,CAAM,EAAE,EAAE,GAAG,OAAO,CAAC,CAAC,CAAC,CAAA,CAAC,CAAC,EAAE,aAAa,EAAE,GAAG,CAAC,KAAK,CAAC,CAAA;oBAC9D,CAAC,CAAC,CAAA;oBACZ,OAAM;gBACR,CAAC;gBACD,8HAA8H;gBAC9H,IAAI,CAAC,GAAG,CAAC,KAAK,IAAI,OAAO,GAAG,CAAC,KAAK,CAAC,IAAI,KAAK,UAAU,EAAE,CAAC;oBACvD,uBAAuB;oBACvB,MAAM,IAAI,CAAC,gDAAgD,GAAG,GAAG,CAAC,CAAA;gBACpE,CAAC;gBACD,OAAO,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,WAAW,EAAE,UAAU,CAAC,CAAA;YAChD,CAAC;QACH,CAAC,CAAC,CAAA;IACJ,CAAC,CACA;IAAC,OAA4B,CAAC,aAAa,GAAG,IAAI,CAAA;IACnD,OAAO,OAAO,CAAA;AAChB,CAAC","sourcesContent":["import { fail, setImmediateWithFallback } from \"../utils.ts\"\nimport {\n getCurrentActionContext,\n getNextActionId,\n getParentActionContext,\n runWithActionContext\n} from \"./action.ts\"\n\nimport type { FunctionWithFlag, IMiddlewareEventType } from \"./action.ts\"\n\n/**\n * @hidden\n */\nexport type FlowReturn<R> = R extends Promise<infer T> ? T : R\n\n/**\n * See [asynchronous actions](concepts/async-actions.md).\n *\n * @returns The flow as a promise.\n */\nexport function flow<R, Args extends any[]>(\n generator: (...args: Args) => Generator<PromiseLike<any>, R, any>\n): (...args: Args) => Promise<FlowReturn<R>> {\n return createFlowSpawner(generator.name, generator) as any\n}\n\n/**\n * @deprecated Not needed since TS3.6.\n * Used for TypeScript to make flows that return a promise return the actual promise result.\n *\n * @param val\n * @returns\n */\nexport function castFlowReturn<T>(val: T): T {\n return val as any\n}\n\n/**\n * @experimental\n * experimental api - might change on minor/patch releases\n *\n * Convert a promise-returning function to a generator-returning one.\n * This is intended to allow for usage of `yield*` in async actions to\n * retain the promise return type.\n *\n * Example:\n * ```ts\n * function getDataAsync(input: string): Promise<number> { ... }\n * const getDataGen = toGeneratorFunction(getDataAsync);\n *\n * const someModel.actions(self => ({\n * someAction: flow(function*() {\n * // value is typed as number\n * const value = yield* getDataGen(\"input value\");\n * ...\n * })\n * }))\n * ```\n */\nexport function toGeneratorFunction<R, Args extends any[]>(\n p: (...args: Args) => Promise<R>\n) {\n return function* (...args: Args) {\n return (yield p(...args)) as R\n }\n}\n\n/**\n * @experimental\n * experimental api - might change on minor/patch releases\n *\n * Convert a promise to a generator yielding that promise\n * This is intended to allow for usage of `yield*` in async actions to\n * retain the promise return type.\n *\n * Example:\n * ```ts\n * function getDataAsync(input: string): Promise<number> { ... }\n *\n * const someModel.actions(self => ({\n * someAction: flow(function*() {\n * // value is typed as number\n * const value = yield* toGenerator(getDataAsync(\"input value\"));\n * ...\n * })\n * }))\n * ```\n */\nexport function* toGenerator<R>(p: Promise<R>) {\n return (yield p) as R\n}\n\n/**\n * @internal\n * @hidden\n */\nexport function createFlowSpawner(name: string, generator: FunctionWithFlag) {\n const spawner = function flowSpawner(this: any, ...flowArgs: any[]) {\n // Implementation based on https://github.com/tj/co/blob/master/index.js\n const runId = getNextActionId()\n const parentContext = getCurrentActionContext()!\n if (!parentContext) {\n throw fail(\"a mst flow must always have a parent context\")\n }\n const parentActionContext = getParentActionContext(parentContext)\n if (!parentActionContext) {\n throw fail(\"a mst flow must always have a parent action context\")\n }\n\n const contextBase = {\n name,\n id: runId,\n tree: parentContext.tree,\n context: parentContext.context,\n parentId: parentContext.id,\n allParentIds: [...parentContext.allParentIds, parentContext.id],\n rootId: parentContext.rootId,\n parentEvent: parentContext,\n parentActionEvent: parentActionContext\n }\n\n function wrap(fn: any, type: IMiddlewareEventType, arg: any) {\n fn.$mst_middleware = (spawner as any).$mst_middleware // pick up any middleware attached to the flow\n return runWithActionContext(\n {\n ...contextBase,\n type,\n args: [arg]\n },\n fn\n )\n }\n\n return new Promise(function (resolve, reject) {\n let gen: any\n const init = function asyncActionInit(...initArgs: any[]) {\n gen = generator(...initArgs)\n onFulfilled(undefined) // kick off the flow\n }\n ;(init as any).$mst_middleware = (spawner as any).$mst_middleware\n\n runWithActionContext(\n {\n ...contextBase,\n type: \"flow_spawn\",\n args: flowArgs\n },\n init\n )\n\n function onFulfilled(res: any) {\n let ret\n try {\n // prettier-ignore\n const cancelError: any = wrap((_r: any) => { ret = gen.next(_r) }, \"flow_resume\", res)\n if (cancelError instanceof Error) {\n ret = gen.throw(cancelError)\n }\n } catch (e) {\n // prettier-ignore\n setImmediateWithFallback(() => {\n wrap((_r: any) => { reject(e) }, \"flow_throw\", e)\n })\n return\n }\n next(ret)\n return\n }\n\n function onRejected(err: any) {\n let ret\n try {\n // prettier-ignore\n wrap((_r: any) => { ret = gen.throw(_r) }, \"flow_resume_error\", err) // or yieldError?\n } catch (e) {\n // prettier-ignore\n setImmediateWithFallback(() => {\n wrap((_r: any) => { reject(e) }, \"flow_throw\", e)\n })\n return\n }\n next(ret)\n }\n\n function next(ret: any) {\n if (ret.done) {\n // prettier-ignore\n setImmediateWithFallback(() => {\n wrap((r: any) => { resolve(r) }, \"flow_return\", ret.value)\n })\n return\n }\n // TODO: support more type of values? See https://github.com/tj/co/blob/249bbdc72da24ae44076afd716349d2089b31c4c/index.js#L100\n if (!ret.value || typeof ret.value.then !== \"function\") {\n // istanbul ignore next\n throw fail(\"Only promises can be yielded to `async`, got: \" + ret)\n }\n return ret.value.then(onFulfilled, onRejected)\n }\n })\n }\n ;(spawner as FunctionWithFlag)._isFlowAction = true\n return spawner\n}\n"]}
@@ -1,46 +0,0 @@
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
- * @internal
15
- * @hidden
16
- */
17
- export declare function splitPatch(patch: IReversibleJsonPatch): [IJsonPatch, IJsonPatch];
18
- /**
19
- * @internal
20
- * @hidden
21
- */
22
- export declare function stripPatch(patch: IReversibleJsonPatch): IJsonPatch;
23
- /**
24
- * Escape slashes and backslashes.
25
- *
26
- * http://tools.ietf.org/html/rfc6901
27
- */
28
- export declare function escapeJsonPath(path: string): string;
29
- /**
30
- * Unescape slashes and backslashes.
31
- */
32
- export declare function unescapeJsonPath(path: string): string;
33
- /**
34
- * Generates a json-path compliant json path from path parts.
35
- *
36
- * @param path
37
- * @returns
38
- */
39
- export declare function joinJsonPath(path: string[]): string;
40
- /**
41
- * Splits and decodes a json path into several parts.
42
- *
43
- * @param path
44
- * @returns
45
- */
46
- export declare function splitJsonPath(path: string): string[];