@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.
- package/README.md +0 -10
- package/dist/index.d.ts +2135 -2
- package/dist/mobx-state-tree.cjs +6894 -0
- package/dist/mobx-state-tree.cjs.map +1 -0
- package/dist/mobx-state-tree.mjs +6814 -0
- package/dist/mobx-state-tree.mjs.map +1 -0
- package/package.json +30 -26
- 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 -101
- package/dist/core/node/object-node.js +0 -546
- package/dist/core/node/object-node.js.map +0 -1
- package/dist/core/node/scalar-node.d.ts +0 -21
- package/dist/core/node/scalar-node.js +0 -90
- 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.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/package.json +0 -1
- package/dist/types/complex-types/array.d.ts +0 -81
- package/dist/types/complex-types/array.js +0 -353
- package/dist/types/complex-types/array.js.map +0 -1
- package/dist/types/complex-types/map.d.ts +0 -111
- package/dist/types/complex-types/map.js +0 -362
- package/dist/types/complex-types/map.js.map +0 -1
- package/dist/types/complex-types/model.d.ts +0 -193
- package/dist/types/complex-types/model.js +0 -478
- 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 -125
- package/dist/types/primitives.js +0 -183
- package/dist/types/primitives.js.map +0 -1
- package/dist/types/utility-types/custom.d.ts +0 -75
- package/dist/types/utility-types/custom.js +0 -111
- 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 -24
- package/dist/types/utility-types/frozen.js +0 -98
- package/dist/types/utility-types/frozen.js.map +0 -1
- package/dist/types/utility-types/identifier.d.ts +0 -87
- package/dist/types/utility-types/identifier.js +0 -130
- 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 -110
- package/dist/types/utility-types/late.js.map +0 -1
- package/dist/types/utility-types/lazy.d.ts +0 -23
- package/dist/types/utility-types/lazy.js +0 -77
- package/dist/types/utility-types/lazy.js.map +0 -1
- package/dist/types/utility-types/literal.d.ts +0 -38
- package/dist/types/utility-types/literal.js +0 -64
- 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 -42
- package/dist/types/utility-types/optional.js +0 -141
- package/dist/types/utility-types/optional.js.map +0 -1
- package/dist/types/utility-types/reference.d.ts +0 -90
- package/dist/types/utility-types/reference.js +0 -393
- 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 -86
- 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 -121
- 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 -162
- package/dist/types/utility-types/snapshotProcessor.js.map +0 -1
- package/dist/types/utility-types/union.d.ts +0 -78
- package/dist/types/utility-types/union.js +0 -246
- 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/esm/core/action.d.ts +0 -87
- package/esm/core/action.js +0 -219
- package/esm/core/action.js.map +0 -1
- package/esm/core/actionContext.d.ts +0 -27
- package/esm/core/actionContext.js +0 -37
- package/esm/core/actionContext.js.map +0 -1
- package/esm/core/flow.d.ts +0 -69
- package/esm/core/flow.js +0 -173
- package/esm/core/flow.js.map +0 -1
- package/esm/core/json-patch.d.ts +0 -46
- package/esm/core/json-patch.js +0 -125
- package/esm/core/json-patch.js.map +0 -1
- package/esm/core/mst-operations.d.ts +0 -459
- package/esm/core/mst-operations.js +0 -844
- package/esm/core/mst-operations.js.map +0 -1
- package/esm/core/node/BaseNode.d.ts +0 -62
- package/esm/core/node/BaseNode.js +0 -148
- package/esm/core/node/BaseNode.js.map +0 -1
- package/esm/core/node/Hook.d.ts +0 -17
- package/esm/core/node/Hook.js +0 -12
- package/esm/core/node/Hook.js.map +0 -1
- package/esm/core/node/create-node.d.ts +0 -16
- package/esm/core/node/create-node.js +0 -36
- package/esm/core/node/create-node.js.map +0 -1
- package/esm/core/node/identifier-cache.d.ts +0 -19
- package/esm/core/node/identifier-cache.js +0 -111
- package/esm/core/node/identifier-cache.js.map +0 -1
- package/esm/core/node/livelinessChecking.d.ts +0 -37
- package/esm/core/node/livelinessChecking.js +0 -33
- package/esm/core/node/livelinessChecking.js.map +0 -1
- package/esm/core/node/node-utils.d.ts +0 -83
- package/esm/core/node/node-utils.js +0 -153
- package/esm/core/node/node-utils.js.map +0 -1
- package/esm/core/node/object-node.d.ts +0 -101
- package/esm/core/node/object-node.js +0 -542
- package/esm/core/node/object-node.js.map +0 -1
- package/esm/core/node/scalar-node.d.ts +0 -21
- package/esm/core/node/scalar-node.js +0 -86
- package/esm/core/node/scalar-node.js.map +0 -1
- package/esm/core/process.d.ts +0 -50
- package/esm/core/process.js +0 -35
- package/esm/core/process.js.map +0 -1
- package/esm/core/type/type-checker.d.ts +0 -69
- package/esm/core/type/type-checker.js +0 -144
- package/esm/core/type/type-checker.js.map +0 -1
- package/esm/core/type/type.d.ts +0 -317
- package/esm/core/type/type.js +0 -243
- package/esm/core/type/type.js.map +0 -1
- package/esm/index.d.ts +0 -2
- package/esm/index.js +0 -2
- package/esm/index.js.map +0 -1
- package/esm/internal.d.ts +0 -39
- package/esm/internal.js +0 -44
- package/esm/internal.js.map +0 -1
- package/esm/middlewares/create-action-tracking-middleware.d.ts +0 -24
- package/esm/middlewares/create-action-tracking-middleware.js +0 -78
- package/esm/middlewares/create-action-tracking-middleware.js.map +0 -1
- package/esm/middlewares/createActionTrackingMiddleware2.d.ts +0 -34
- package/esm/middlewares/createActionTrackingMiddleware2.js +0 -130
- package/esm/middlewares/createActionTrackingMiddleware2.js.map +0 -1
- package/esm/middlewares/on-action.d.ts +0 -87
- package/esm/middlewares/on-action.js +0 -210
- package/esm/middlewares/on-action.js.map +0 -1
- package/esm/types/complex-types/array.d.ts +0 -81
- package/esm/types/complex-types/array.js +0 -347
- package/esm/types/complex-types/array.js.map +0 -1
- package/esm/types/complex-types/map.d.ts +0 -111
- package/esm/types/complex-types/map.js +0 -356
- package/esm/types/complex-types/map.js.map +0 -1
- package/esm/types/complex-types/model.d.ts +0 -193
- package/esm/types/complex-types/model.js +0 -471
- package/esm/types/complex-types/model.js.map +0 -1
- package/esm/types/index.d.ts +0 -33
- package/esm/types/index.js +0 -35
- package/esm/types/index.js.map +0 -1
- package/esm/types/primitives.d.ts +0 -125
- package/esm/types/primitives.js +0 -177
- package/esm/types/primitives.js.map +0 -1
- package/esm/types/utility-types/custom.d.ts +0 -75
- package/esm/types/utility-types/custom.js +0 -106
- package/esm/types/utility-types/custom.js.map +0 -1
- package/esm/types/utility-types/enumeration.d.ts +0 -5
- package/esm/types/utility-types/enumeration.js +0 -31
- package/esm/types/utility-types/enumeration.js.map +0 -1
- package/esm/types/utility-types/frozen.d.ts +0 -24
- package/esm/types/utility-types/frozen.js +0 -92
- package/esm/types/utility-types/frozen.js.map +0 -1
- package/esm/types/utility-types/identifier.d.ts +0 -87
- package/esm/types/utility-types/identifier.js +0 -121
- package/esm/types/utility-types/identifier.js.map +0 -1
- package/esm/types/utility-types/late.d.ts +0 -10
- package/esm/types/utility-types/late.js +0 -106
- package/esm/types/utility-types/late.js.map +0 -1
- package/esm/types/utility-types/lazy.d.ts +0 -23
- package/esm/types/utility-types/lazy.js +0 -72
- package/esm/types/utility-types/lazy.js.map +0 -1
- package/esm/types/utility-types/literal.d.ts +0 -38
- package/esm/types/utility-types/literal.js +0 -58
- package/esm/types/utility-types/literal.js.map +0 -1
- package/esm/types/utility-types/maybe.d.ts +0 -26
- package/esm/types/utility-types/maybe.js +0 -26
- package/esm/types/utility-types/maybe.js.map +0 -1
- package/esm/types/utility-types/optional.d.ts +0 -42
- package/esm/types/utility-types/optional.js +0 -135
- package/esm/types/utility-types/optional.js.map +0 -1
- package/esm/types/utility-types/reference.d.ts +0 -90
- package/esm/types/utility-types/reference.js +0 -383
- package/esm/types/utility-types/reference.js.map +0 -1
- package/esm/types/utility-types/refinement.d.ts +0 -10
- package/esm/types/utility-types/refinement.js +0 -82
- package/esm/types/utility-types/refinement.js.map +0 -1
- package/esm/types/utility-types/resilient.d.ts +0 -18
- package/esm/types/utility-types/resilient.js +0 -118
- package/esm/types/utility-types/resilient.js.map +0 -1
- package/esm/types/utility-types/snapshotProcessor.d.ts +0 -63
- package/esm/types/utility-types/snapshotProcessor.js +0 -159
- package/esm/types/utility-types/snapshotProcessor.js.map +0 -1
- package/esm/types/utility-types/union.d.ts +0 -78
- package/esm/types/utility-types/union.js +0 -240
- package/esm/types/utility-types/union.js.map +0 -1
- package/esm/utils.d.ts +0 -230
- package/esm/utils.js +0 -449
- package/esm/utils.js.map +0 -1
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;;;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oBACvD,uBAAuB;oBACvB,MAAM,IAAA,eAAI,EAAC,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[];
|
package/dist/core/json-patch.js
DELETED
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.splitPatch = splitPatch;
|
|
4
|
-
exports.stripPatch = stripPatch;
|
|
5
|
-
exports.escapeJsonPath = escapeJsonPath;
|
|
6
|
-
exports.unescapeJsonPath = unescapeJsonPath;
|
|
7
|
-
exports.joinJsonPath = joinJsonPath;
|
|
8
|
-
exports.splitJsonPath = splitJsonPath;
|
|
9
|
-
const internal_ts_1 = require("../internal.js");
|
|
10
|
-
/**
|
|
11
|
-
* @internal
|
|
12
|
-
* @hidden
|
|
13
|
-
*/
|
|
14
|
-
function splitPatch(patch) {
|
|
15
|
-
if (!("oldValue" in patch)) {
|
|
16
|
-
throw (0, internal_ts_1.fail)(`Patches without \`oldValue\` field cannot be inversed`);
|
|
17
|
-
}
|
|
18
|
-
return [stripPatch(patch), invertPatch(patch)];
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* @internal
|
|
22
|
-
* @hidden
|
|
23
|
-
*/
|
|
24
|
-
function stripPatch(patch) {
|
|
25
|
-
// strips `oldvalue` information from the patch, so that it becomes a patch conform the json-patch spec
|
|
26
|
-
// this removes the ability to undo the patch
|
|
27
|
-
switch (patch.op) {
|
|
28
|
-
case "add":
|
|
29
|
-
return { op: "add", path: patch.path, value: patch.value };
|
|
30
|
-
case "remove":
|
|
31
|
-
return { op: "remove", path: patch.path };
|
|
32
|
-
case "replace":
|
|
33
|
-
return { op: "replace", path: patch.path, value: patch.value };
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
function invertPatch(patch) {
|
|
37
|
-
switch (patch.op) {
|
|
38
|
-
case "add":
|
|
39
|
-
return {
|
|
40
|
-
op: "remove",
|
|
41
|
-
path: patch.path
|
|
42
|
-
};
|
|
43
|
-
case "remove":
|
|
44
|
-
return {
|
|
45
|
-
op: "add",
|
|
46
|
-
path: patch.path,
|
|
47
|
-
value: patch.oldValue
|
|
48
|
-
};
|
|
49
|
-
case "replace":
|
|
50
|
-
return {
|
|
51
|
-
op: "replace",
|
|
52
|
-
path: patch.path,
|
|
53
|
-
value: patch.oldValue
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Simple simple check to check it is a number.
|
|
59
|
-
*/
|
|
60
|
-
function isNumber(x) {
|
|
61
|
-
return typeof x === "number";
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* Escape slashes and backslashes.
|
|
65
|
-
*
|
|
66
|
-
* http://tools.ietf.org/html/rfc6901
|
|
67
|
-
*/
|
|
68
|
-
function escapeJsonPath(path) {
|
|
69
|
-
if (isNumber(path) === true) {
|
|
70
|
-
return "" + path;
|
|
71
|
-
}
|
|
72
|
-
if (path.indexOf("/") === -1 && path.indexOf("~") === -1) {
|
|
73
|
-
return path;
|
|
74
|
-
}
|
|
75
|
-
return path.replace(/~/g, "~0").replace(/\//g, "~1");
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Unescape slashes and backslashes.
|
|
79
|
-
*/
|
|
80
|
-
function unescapeJsonPath(path) {
|
|
81
|
-
return path.replace(/~1/g, "/").replace(/~0/g, "~");
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* Generates a json-path compliant json path from path parts.
|
|
85
|
-
*
|
|
86
|
-
* @param path
|
|
87
|
-
* @returns
|
|
88
|
-
*/
|
|
89
|
-
function joinJsonPath(path) {
|
|
90
|
-
// `/` refers to property with an empty name, while `` refers to root itself!
|
|
91
|
-
if (path.length === 0) {
|
|
92
|
-
return "";
|
|
93
|
-
}
|
|
94
|
-
const getPathStr = (p) => p.map(escapeJsonPath).join("/");
|
|
95
|
-
if (path[0] === "." || path[0] === "..") {
|
|
96
|
-
// relative
|
|
97
|
-
return getPathStr(path);
|
|
98
|
-
}
|
|
99
|
-
else {
|
|
100
|
-
// absolute
|
|
101
|
-
return "/" + getPathStr(path);
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
/**
|
|
105
|
-
* Splits and decodes a json path into several parts.
|
|
106
|
-
*
|
|
107
|
-
* @param path
|
|
108
|
-
* @returns
|
|
109
|
-
*/
|
|
110
|
-
function splitJsonPath(path) {
|
|
111
|
-
// `/` refers to property with an empty name, while `` refers to root itself!
|
|
112
|
-
const parts = path.split("/").map(unescapeJsonPath);
|
|
113
|
-
const valid = path === "" ||
|
|
114
|
-
path === "." ||
|
|
115
|
-
path === ".." ||
|
|
116
|
-
(0, internal_ts_1.stringStartsWith)(path, "/") ||
|
|
117
|
-
(0, internal_ts_1.stringStartsWith)(path, "./") ||
|
|
118
|
-
(0, internal_ts_1.stringStartsWith)(path, "../");
|
|
119
|
-
if (!valid) {
|
|
120
|
-
throw (0, internal_ts_1.fail)(`a json path must be either rooted, empty or relative, but got '${path}'`);
|
|
121
|
-
}
|
|
122
|
-
// '/a/b/c' -> ["a", "b", "c"]
|
|
123
|
-
// '../../b/c' -> ["..", "..", "b", "c"]
|
|
124
|
-
// '' -> []
|
|
125
|
-
// '/' -> ['']
|
|
126
|
-
// './a' -> [".", "a"]
|
|
127
|
-
// /./a' -> [".", "a"] equivalent to './a'
|
|
128
|
-
if (parts[0] === "") {
|
|
129
|
-
parts.shift();
|
|
130
|
-
}
|
|
131
|
-
return parts;
|
|
132
|
-
}
|
|
133
|
-
//# sourceMappingURL=json-patch.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"json-patch.js","sourceRoot":"","sources":["../../src/core/json-patch.ts"],"names":[],"mappings":";;AAoBA,gCAOC;AAMD,gCAWC;AAoCD,wCAQC;AAKD,4CAEC;AAQD,oCAcC;AAQD,sCA4BC;AAzJD,gDAAuD;AAgBvD;;;GAGG;AACH,SAAgB,UAAU,CACxB,KAA2B;IAE3B,IAAI,CAAC,CAAC,UAAU,IAAI,KAAK,CAAC,EAAE,CAAC;QAC3B,MAAM,IAAA,kBAAI,EAAC,uDAAuD,CAAC,CAAA;IACrE,CAAC;IACD,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE,WAAW,CAAC,KAAK,CAAC,CAAC,CAAA;AAChD,CAAC;AAED;;;GAGG;AACH,SAAgB,UAAU,CAAC,KAA2B;IACpD,uGAAuG;IACvG,6CAA6C;IAC7C,QAAQ,KAAK,CAAC,EAAE,EAAE,CAAC;QACjB,KAAK,KAAK;YACR,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,CAAA;QAC5D,KAAK,QAAQ;YACX,OAAO,EAAE,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,CAAA;QAC3C,KAAK,SAAS;YACZ,OAAO,EAAE,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,CAAA;IAClE,CAAC;AACH,CAAC;AAED,S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C","sourcesContent":["import { fail, stringStartsWith } from \"../internal.ts\"\n\n/**\n * https://tools.ietf.org/html/rfc6902\n * http://jsonpatch.com/\n */\nexport interface IJsonPatch {\n readonly op: \"replace\" | \"add\" | \"remove\"\n readonly path: string\n readonly value?: any\n}\n\nexport interface IReversibleJsonPatch extends IJsonPatch {\n readonly oldValue: any // This goes beyond JSON-patch, but makes sure each patch can be inverse applied\n}\n\n/**\n * @internal\n * @hidden\n */\nexport function splitPatch(\n patch: IReversibleJsonPatch\n): [IJsonPatch, IJsonPatch] {\n if (!(\"oldValue\" in patch)) {\n throw fail(`Patches without \\`oldValue\\` field cannot be inversed`)\n }\n return [stripPatch(patch), invertPatch(patch)]\n}\n\n/**\n * @internal\n * @hidden\n */\nexport function stripPatch(patch: IReversibleJsonPatch): IJsonPatch {\n // strips `oldvalue` information from the patch, so that it becomes a patch conform the json-patch spec\n // this removes the ability to undo the patch\n switch (patch.op) {\n case \"add\":\n return { op: \"add\", path: patch.path, value: patch.value }\n case \"remove\":\n return { op: \"remove\", path: patch.path }\n case \"replace\":\n return { op: \"replace\", path: patch.path, value: patch.value }\n }\n}\n\nfunction invertPatch(patch: IReversibleJsonPatch): IJsonPatch {\n switch (patch.op) {\n case \"add\":\n return {\n op: \"remove\",\n path: patch.path\n }\n case \"remove\":\n return {\n op: \"add\",\n path: patch.path,\n value: patch.oldValue\n }\n case \"replace\":\n return {\n op: \"replace\",\n path: patch.path,\n value: patch.oldValue\n }\n }\n}\n\n/**\n * Simple simple check to check it is a number.\n */\nfunction isNumber(x: string): boolean {\n return typeof x === \"number\"\n}\n\n/**\n * Escape slashes and backslashes.\n *\n * http://tools.ietf.org/html/rfc6901\n */\nexport function escapeJsonPath(path: string): string {\n if (isNumber(path) === true) {\n return \"\" + path\n }\n if (path.indexOf(\"/\") === -1 && path.indexOf(\"~\") === -1) {\n return path\n }\n return path.replace(/~/g, \"~0\").replace(/\\//g, \"~1\")\n}\n\n/**\n * Unescape slashes and backslashes.\n */\nexport function unescapeJsonPath(path: string): string {\n return path.replace(/~1/g, \"/\").replace(/~0/g, \"~\")\n}\n\n/**\n * Generates a json-path compliant json path from path parts.\n *\n * @param path\n * @returns\n */\nexport function joinJsonPath(path: string[]): string {\n // `/` refers to property with an empty name, while `` refers to root itself!\n if (path.length === 0) {\n return \"\"\n }\n\n const getPathStr = (p: string[]) => p.map(escapeJsonPath).join(\"/\")\n if (path[0] === \".\" || path[0] === \"..\") {\n // relative\n return getPathStr(path)\n } else {\n // absolute\n return \"/\" + getPathStr(path)\n }\n}\n\n/**\n * Splits and decodes a json path into several parts.\n *\n * @param path\n * @returns\n */\nexport function splitJsonPath(path: string): string[] {\n // `/` refers to property with an empty name, while `` refers to root itself!\n const parts = path.split(\"/\").map(unescapeJsonPath)\n\n const valid =\n path === \"\" ||\n path === \".\" ||\n path === \"..\" ||\n stringStartsWith(path, \"/\") ||\n stringStartsWith(path, \"./\") ||\n stringStartsWith(path, \"../\")\n if (!valid) {\n throw fail(\n `a json path must be either rooted, empty or relative, but got '${path}'`\n )\n }\n\n // '/a/b/c' -> [\"a\", \"b\", \"c\"]\n // '../../b/c' -> [\"..\", \"..\", \"b\", \"c\"]\n // '' -> []\n // '/' -> ['']\n // './a' -> [\".\", \"a\"]\n // /./a' -> [\".\", \"a\"] equivalent to './a'\n\n if (parts[0] === \"\") {\n parts.shift()\n }\n return parts\n}\n"]}
|