@jbrowse/core 2.0.1 → 2.1.0
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/BaseFeatureWidget/BaseFeatureDetail.d.ts +6 -0
- package/BaseFeatureWidget/BaseFeatureDetail.js +313 -592
- package/BaseFeatureWidget/SequenceFeatureDetails.js +213 -479
- package/BaseFeatureWidget/index.js +88 -126
- package/BaseFeatureWidget/types.js +1 -4
- package/BaseFeatureWidget/util.js +40 -75
- package/CorePlugin.js +55 -94
- package/Plugin.js +9 -34
- package/PluginLoader.js +153 -422
- package/PluginManager.d.ts +17 -14
- package/PluginManager.js +377 -666
- package/ReExports/Attributes.js +3 -10
- package/ReExports/BaseCard.js +3 -10
- package/ReExports/DataGrid.js +5 -12
- package/ReExports/FeatureDetails.js +3 -10
- package/ReExports/index.js +6 -12
- package/ReExports/list.d.ts +5 -0
- package/ReExports/list.js +271 -7
- package/ReExports/material-ui-colors.js +15 -16
- package/ReExports/modules.d.ts +0 -1
- package/ReExports/modules.js +453 -798
- package/TextSearch/BaseResults.js +51 -123
- package/TextSearch/TextSearchManager.js +66 -144
- package/assemblyManager/assembly.js +280 -555
- package/assemblyManager/assemblyConfigSchema.js +47 -64
- package/assemblyManager/assemblyManager.js +126 -272
- package/assemblyManager/index.js +9 -22
- package/configuration/configurationSchema.js +167 -203
- package/configuration/configurationSlot.js +248 -326
- package/configuration/index.js +19 -35
- package/configuration/util.js +131 -173
- package/data_adapters/BaseAdapter.d.ts +2 -2
- package/data_adapters/BaseAdapter.js +132 -521
- package/data_adapters/CytobandAdapter.js +40 -126
- package/data_adapters/dataAdapterCache.js +77 -158
- package/package.json +4 -5
- package/pluggableElementTypes/AdapterType.js +24 -79
- package/pluggableElementTypes/AddTrackWorkflowType.d.ts +17 -0
- package/pluggableElementTypes/AddTrackWorkflowType.js +20 -0
- package/pluggableElementTypes/ConnectionType.js +22 -65
- package/pluggableElementTypes/DisplayType.js +35 -82
- package/pluggableElementTypes/InternetAccountType.js +23 -64
- package/pluggableElementTypes/PluggableElementBase.js +8 -20
- package/pluggableElementTypes/RpcMethodType.js +85 -427
- package/pluggableElementTypes/TextSearchAdapterType.js +16 -55
- package/pluggableElementTypes/TrackType.js +26 -70
- package/pluggableElementTypes/ViewType.js +21 -63
- package/pluggableElementTypes/WidgetType.js +21 -64
- package/pluggableElementTypes/index.d.ts +4 -3
- package/pluggableElementTypes/index.js +42 -125
- package/pluggableElementTypes/models/BaseConnectionModelFactory.js +28 -43
- package/pluggableElementTypes/models/BaseDisplayModel.js +58 -95
- package/pluggableElementTypes/models/BaseTrackModel.js +139 -199
- package/pluggableElementTypes/models/BaseViewModel.js +24 -40
- package/pluggableElementTypes/models/InternetAccountModel.js +116 -263
- package/pluggableElementTypes/models/baseConnectionConfig.js +14 -25
- package/pluggableElementTypes/models/baseInternetAccountConfig.js +29 -38
- package/pluggableElementTypes/models/baseTrackConfig.js +106 -133
- package/pluggableElementTypes/models/index.js +21 -70
- package/pluggableElementTypes/renderers/BoxRendererType.js +132 -291
- package/pluggableElementTypes/renderers/CircularChordRendererType.js +8 -38
- package/pluggableElementTypes/renderers/ComparativeServerSideRendererType.js +60 -192
- package/pluggableElementTypes/renderers/FeatureRendererType.d.ts +0 -2
- package/pluggableElementTypes/renderers/FeatureRendererType.js +89 -264
- package/pluggableElementTypes/renderers/RendererType.js +31 -105
- package/pluggableElementTypes/renderers/ServerSideRenderedContent.js +61 -72
- package/pluggableElementTypes/renderers/ServerSideRendererType.js +112 -265
- package/pluggableElementTypes/renderers/index.js +19 -62
- package/pluggableElementTypes/renderers/util/serializableFilterChain.js +27 -65
- package/rpc/BaseRpcDriver.js +169 -405
- package/rpc/MainThreadRpcDriver.js +27 -150
- package/rpc/RpcManager.js +58 -159
- package/rpc/WebWorkerRpcDriver.js +54 -171
- package/rpc/configSchema.js +25 -49
- package/rpc/coreRpcMethods.js +221 -959
- package/rpc/remoteAbortSignals.js +46 -70
- package/tsconfig.build.tsbuildinfo +1 -1
- package/ui/AboutDialog.js +106 -162
- package/ui/App.js +157 -242
- package/ui/AssemblySelector.js +59 -120
- package/ui/CascadingMenu.js +101 -196
- package/ui/ColorPicker.d.ts +16 -0
- package/ui/ColorPicker.js +97 -0
- package/ui/Drawer.js +28 -61
- package/ui/DrawerWidget.js +108 -202
- package/ui/DropDownMenu.js +60 -91
- package/ui/EditableTypography.js +87 -149
- package/ui/ErrorMessage.js +41 -56
- package/ui/FactoryResetDialog.js +24 -57
- package/ui/FatalErrorDialog.js +59 -91
- package/ui/FileSelector/FileSelector.js +123 -189
- package/ui/FileSelector/LocalFileChooser.js +44 -75
- package/ui/FileSelector/UrlChooser.js +17 -38
- package/ui/FileSelector/index.js +6 -12
- package/ui/Icons.js +45 -69
- package/ui/Logo.js +57 -110
- package/ui/Menu.js +232 -354
- package/ui/PrerenderedCanvas.js +63 -87
- package/ui/ResizeHandle.js +87 -116
- package/ui/ReturnToImportFormDialog.js +32 -63
- package/ui/SanitizedHTML.js +64 -47
- package/ui/Snackbar.js +74 -101
- package/ui/SnackbarModel.js +37 -51
- package/ui/Tooltip.js +49 -76
- package/ui/ViewContainer.js +113 -196
- package/ui/colors.d.ts +10 -0
- package/ui/colors.js +78 -0
- package/ui/index.js +51 -181
- package/ui/react-colorful.d.ts +17 -0
- package/ui/react-colorful.js +455 -0
- package/ui/theme.js +199 -247
- package/util/Base1DUtils.js +163 -202
- package/util/Base1DViewModel.js +121 -168
- package/util/QuickLRU.js +84 -332
- package/util/TimeTraveller.d.ts +19 -0
- package/util/TimeTraveller.js +86 -0
- package/util/aborting.js +49 -127
- package/util/analytics.js +91 -154
- package/util/blockTypes.js +106 -240
- package/util/calculateDynamicBlocks.js +98 -128
- package/util/calculateStaticBlocks.js +105 -125
- package/util/color/cssColorsLevel4.js +156 -160
- package/util/color/index.js +33 -55
- package/util/compositeMap.js +49 -333
- package/util/formatFastaStrings.js +9 -14
- package/util/idMaker.js +18 -31
- package/util/index.d.ts +7 -20
- package/util/index.js +742 -1188
- package/util/io/RemoteFileWithRangeCache.js +88 -257
- package/util/io/index.js +95 -169
- package/util/jexl.js +60 -115
- package/util/jexlStrings.js +24 -29
- package/util/layouts/BaseLayout.js +1 -4
- package/util/layouts/GranularRectLayout.js +388 -555
- package/util/layouts/MultiLayout.js +41 -109
- package/util/layouts/PrecomputedLayout.js +56 -112
- package/util/layouts/PrecomputedMultiLayout.js +22 -59
- package/util/layouts/SceneGraph.js +127 -197
- package/util/layouts/index.js +29 -66
- package/util/mst-reflection.js +55 -71
- package/util/offscreenCanvasPonyfill.js +66 -134
- package/util/offscreenCanvasUtils.d.ts +2 -7
- package/util/offscreenCanvasUtils.js +49 -146
- package/util/range.js +29 -40
- package/util/rxjs.js +20 -27
- package/util/simpleFeature.js +88 -152
- package/util/stats.js +91 -151
- package/util/tracks.js +130 -173
- package/util/types/index.js +110 -179
- package/util/types/mst.js +91 -146
- package/util/types/util.js +1 -4
- package/util/when.js +54 -101
- package/BaseFeatureWidget/SequenceFeatureDetails.test.js +0 -122
- package/BaseFeatureWidget/index.test.js +0 -69
- package/TextSearch/BaseResults.test.js +0 -42
- package/configuration/configurationSchema.test.js +0 -266
- package/configuration/configurationSlot.test.js +0 -69
- package/configuration/util.test.js +0 -39
- package/data_adapters/BaseAdapter.test.js +0 -200
- package/declare.d.js +0 -1
- package/pluggableElementTypes/RpcMethodType.test.js +0 -118
- package/pluggableElementTypes/renderers/declare.d.js +0 -1
- package/pluggableElementTypes/renderers/util/serializableFilterChain.test.js +0 -20
- package/rpc/BaseRpcDriver.test.js +0 -540
- package/rpc/declaration.d.js +0 -1
- package/ui/FatalErrorDialog.test.js +0 -82
- package/ui/SanitizedHTML.test.js +0 -36
- package/ui/theme.test.js +0 -92
- package/util/Base1DViewModel.test.js +0 -130
- package/util/calculateDynamicBlocks.test.js +0 -74
- package/util/calculateStaticBlocks.test.js +0 -297
- package/util/declare.d.js +0 -1
- package/util/formatFastaStrings.test.js +0 -40
- package/util/index.test.js +0 -213
- package/util/jexlStrings.test.js +0 -48
- package/util/layouts/GranularRectLayout.test.js +0 -99
- package/util/range.test.js +0 -64
- package/util/simpleFeature.test.js +0 -34
- package/util/stats.test.js +0 -172
package/rpc/BaseRpcDriver.js
CHANGED
|
@@ -1,424 +1,188 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
exports.default = void 0;
|
|
9
|
-
exports.watchWorker = watchWorker;
|
|
10
|
-
|
|
11
|
-
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
12
|
-
|
|
13
|
-
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
14
|
-
|
|
15
|
-
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
16
|
-
|
|
17
|
-
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
|
|
18
|
-
|
|
19
|
-
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
20
|
-
|
|
21
|
-
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
22
|
-
|
|
23
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
24
|
-
|
|
25
|
-
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
26
|
-
|
|
27
|
-
var _mobxStateTree = require("mobx-state-tree");
|
|
28
|
-
|
|
29
|
-
var _util = require("../util");
|
|
30
|
-
|
|
31
|
-
var _remoteAbortSignals = require("./remoteAbortSignals");
|
|
32
|
-
|
|
33
|
-
var _configuration = require("../configuration");
|
|
34
|
-
|
|
35
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
36
|
-
|
|
37
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
38
|
-
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.watchWorker = void 0;
|
|
4
|
+
const mobx_state_tree_1 = require("mobx-state-tree");
|
|
5
|
+
const util_1 = require("../util");
|
|
6
|
+
const remoteAbortSignals_1 = require("./remoteAbortSignals");
|
|
7
|
+
const configuration_1 = require("../configuration");
|
|
39
8
|
function isClonable(thing) {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
return true;
|
|
49
|
-
} // watches the given worker object, returns a promise that will be rejected if
|
|
50
|
-
// the worker times out
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
function watchWorker(_x, _x2, _x3) {
|
|
54
|
-
return _watchWorker.apply(this, arguments);
|
|
9
|
+
if (typeof thing === 'function') {
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
if (thing instanceof Error) {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
return true;
|
|
55
16
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
rpcDriverClassName: rpcDriverClassName
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
case 3:
|
|
78
|
-
delay();
|
|
79
|
-
_context5.next = 9;
|
|
80
|
-
break;
|
|
81
|
-
|
|
82
|
-
case 6:
|
|
83
|
-
_context5.prev = 6;
|
|
84
|
-
_context5.t0 = _context5["catch"](0);
|
|
85
|
-
reject(_context5.t0);
|
|
86
|
-
|
|
87
|
-
case 9:
|
|
88
|
-
case "end":
|
|
89
|
-
return _context5.stop();
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
}, _callee5, null, [[0, 6]]);
|
|
93
|
-
})), pingTime);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
delay();
|
|
97
|
-
}));
|
|
98
|
-
|
|
99
|
-
case 1:
|
|
100
|
-
case "end":
|
|
101
|
-
return _context6.stop();
|
|
17
|
+
// watches the given worker object, returns a promise that will be rejected if
|
|
18
|
+
// the worker times out
|
|
19
|
+
async function watchWorker(worker, pingTime, rpcDriverClassName) {
|
|
20
|
+
// after first ping succeeds, apply wait for timeout
|
|
21
|
+
return new Promise((_resolve, reject) => {
|
|
22
|
+
function delay() {
|
|
23
|
+
setTimeout(async () => {
|
|
24
|
+
try {
|
|
25
|
+
await worker.call('ping', [], {
|
|
26
|
+
timeout: pingTime * 2,
|
|
27
|
+
rpcDriverClassName,
|
|
28
|
+
});
|
|
29
|
+
delay();
|
|
30
|
+
}
|
|
31
|
+
catch (e) {
|
|
32
|
+
reject(e);
|
|
33
|
+
}
|
|
34
|
+
}, pingTime);
|
|
102
35
|
}
|
|
103
|
-
|
|
104
|
-
}
|
|
105
|
-
}));
|
|
106
|
-
return _watchWorker.apply(this, arguments);
|
|
36
|
+
delay();
|
|
37
|
+
});
|
|
107
38
|
}
|
|
108
|
-
|
|
39
|
+
exports.watchWorker = watchWorker;
|
|
109
40
|
function detectHardwareConcurrency() {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
return 1;
|
|
41
|
+
const mainThread = typeof window !== 'undefined';
|
|
42
|
+
const canDetect = mainThread && 'hardwareConcurrency' in window.navigator;
|
|
43
|
+
if (mainThread && canDetect) {
|
|
44
|
+
return window.navigator.hardwareConcurrency;
|
|
45
|
+
}
|
|
46
|
+
return 1;
|
|
118
47
|
}
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
var _getWorker = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee() {
|
|
131
|
-
var _this = this;
|
|
132
|
-
|
|
133
|
-
return _regenerator.default.wrap(function _callee$(_context) {
|
|
134
|
-
while (1) {
|
|
135
|
-
switch (_context.prev = _context.next) {
|
|
136
|
-
case 0:
|
|
137
|
-
if (!this.workerP) {
|
|
138
|
-
this.workerP = this.driver.makeWorker().then(function (worker) {
|
|
139
|
-
watchWorker(worker, _this.driver.maxPingTime, _this.driver.name).catch(function (error) {
|
|
140
|
-
if (worker) {
|
|
48
|
+
class LazyWorker {
|
|
49
|
+
constructor(driver) {
|
|
50
|
+
this.driver = driver;
|
|
51
|
+
}
|
|
52
|
+
async getWorker() {
|
|
53
|
+
if (!this.workerP) {
|
|
54
|
+
this.workerP = this.driver
|
|
55
|
+
.makeWorker()
|
|
56
|
+
.then(worker => {
|
|
57
|
+
watchWorker(worker, this.driver.maxPingTime, this.driver.name).catch(error => {
|
|
58
|
+
if (worker) {
|
|
141
59
|
console.error('worker did not respond, killing and generating new one');
|
|
142
60
|
console.error(error);
|
|
143
61
|
worker.destroy();
|
|
144
62
|
worker.status = 'killed';
|
|
145
63
|
worker.error = error;
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
return _context.abrupt("return", this.workerP);
|
|
157
|
-
|
|
158
|
-
case 2:
|
|
159
|
-
case "end":
|
|
160
|
-
return _context.stop();
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
}, _callee, this);
|
|
164
|
-
}));
|
|
165
|
-
|
|
166
|
-
function getWorker() {
|
|
167
|
-
return _getWorker.apply(this, arguments);
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
return getWorker;
|
|
171
|
-
}()
|
|
172
|
-
}]);
|
|
173
|
-
return LazyWorker;
|
|
174
|
-
}();
|
|
175
|
-
|
|
176
|
-
var BaseRpcDriver = /*#__PURE__*/function () {
|
|
177
|
-
function BaseRpcDriver(args) {
|
|
178
|
-
(0, _classCallCheck2.default)(this, BaseRpcDriver);
|
|
179
|
-
(0, _defineProperty2.default)(this, "name", void 0);
|
|
180
|
-
(0, _defineProperty2.default)(this, "lastWorkerAssignment", -1);
|
|
181
|
-
(0, _defineProperty2.default)(this, "workerAssignments", new Map());
|
|
182
|
-
(0, _defineProperty2.default)(this, "workerPool", void 0);
|
|
183
|
-
(0, _defineProperty2.default)(this, "maxPingTime", 30000);
|
|
184
|
-
(0, _defineProperty2.default)(this, "workerCheckFrequency", 5000);
|
|
185
|
-
(0, _defineProperty2.default)(this, "config", void 0);
|
|
186
|
-
this.config = args.config;
|
|
187
|
-
} // filter the given object and just remove any non-clonable things from it
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
(0, _createClass2.default)(BaseRpcDriver, [{
|
|
191
|
-
key: "filterArgs",
|
|
192
|
-
value: function filterArgs(thing, sessionId) {
|
|
193
|
-
var _this2 = this;
|
|
194
|
-
|
|
195
|
-
if (Array.isArray(thing)) {
|
|
196
|
-
return thing.filter(isClonable).map(function (t) {
|
|
197
|
-
return _this2.filterArgs(t, sessionId);
|
|
198
|
-
});
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
if ((0, _typeof2.default)(thing) === 'object' && thing !== null) {
|
|
202
|
-
// AbortSignals are specially handled
|
|
203
|
-
if (thing instanceof AbortSignal) {
|
|
204
|
-
return (0, _remoteAbortSignals.serializeAbortSignal)(thing, this.remoteAbort.bind(this, sessionId));
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
if ((0, _mobxStateTree.isStateTreeNode)(thing) && !(0, _mobxStateTree.isAlive)(thing)) {
|
|
208
|
-
throw new Error('dead state tree node passed to RPC call');
|
|
209
|
-
} // special case, don't try to iterate the file's subelements as the
|
|
210
|
-
// object entries below would
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
if (thing instanceof File) {
|
|
214
|
-
return thing;
|
|
64
|
+
this.workerP = undefined;
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
return worker;
|
|
68
|
+
})
|
|
69
|
+
.catch(e => {
|
|
70
|
+
this.workerP = undefined;
|
|
71
|
+
throw e;
|
|
72
|
+
});
|
|
215
73
|
}
|
|
216
|
-
|
|
217
|
-
return Object.fromEntries(Object.entries(thing).filter(function (e) {
|
|
218
|
-
return isClonable(e[1]);
|
|
219
|
-
}).map(function (_ref) {
|
|
220
|
-
var _ref2 = (0, _slicedToArray2.default)(_ref, 2),
|
|
221
|
-
k = _ref2[0],
|
|
222
|
-
v = _ref2[1];
|
|
223
|
-
|
|
224
|
-
return [k, _this2.filterArgs(v, sessionId)];
|
|
225
|
-
}));
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
return thing;
|
|
74
|
+
return this.workerP;
|
|
229
75
|
}
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
76
|
+
}
|
|
77
|
+
class BaseRpcDriver {
|
|
78
|
+
constructor(args) {
|
|
79
|
+
this.lastWorkerAssignment = -1;
|
|
80
|
+
this.workerAssignments = new Map(); // sessionId -> worker number
|
|
81
|
+
this.maxPingTime = 30000;
|
|
82
|
+
this.workerCheckFrequency = 5000;
|
|
83
|
+
this.config = args.config;
|
|
84
|
+
}
|
|
85
|
+
// filter the given object and just remove any non-clonable things from it
|
|
86
|
+
filterArgs(thing, sessionId) {
|
|
87
|
+
if (Array.isArray(thing)) {
|
|
88
|
+
return thing
|
|
89
|
+
.filter(isClonable)
|
|
90
|
+
.map(t => this.filterArgs(t, sessionId));
|
|
91
|
+
}
|
|
92
|
+
if (typeof thing === 'object' && thing !== null) {
|
|
93
|
+
// AbortSignals are specially handled
|
|
94
|
+
if (thing instanceof AbortSignal) {
|
|
95
|
+
return (0, remoteAbortSignals_1.serializeAbortSignal)(thing, this.remoteAbort.bind(this, sessionId));
|
|
96
|
+
}
|
|
97
|
+
if ((0, mobx_state_tree_1.isStateTreeNode)(thing) && !(0, mobx_state_tree_1.isAlive)(thing)) {
|
|
98
|
+
throw new Error('dead state tree node passed to RPC call');
|
|
99
|
+
}
|
|
100
|
+
// special case, don't try to iterate the file's subelements as the
|
|
101
|
+
// object entries below would
|
|
102
|
+
if (thing instanceof File) {
|
|
103
|
+
return thing;
|
|
254
104
|
}
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
105
|
+
return Object.fromEntries(Object.entries(thing)
|
|
106
|
+
.filter(e => isClonable(e[1]))
|
|
107
|
+
.map(([k, v]) => [k, this.filterArgs(v, sessionId)]));
|
|
108
|
+
}
|
|
109
|
+
return thing;
|
|
110
|
+
}
|
|
111
|
+
async remoteAbort(sessionId, functionName, signalId) {
|
|
112
|
+
const worker = await this.getWorker(sessionId);
|
|
113
|
+
worker.call(functionName, { signalId }, { timeout: 1000000, rpcDriverClassName: this.name });
|
|
114
|
+
}
|
|
115
|
+
createWorkerPool() {
|
|
116
|
+
const hardwareConcurrency = detectHardwareConcurrency();
|
|
117
|
+
const workerCount = (0, configuration_1.readConfObject)(this.config, 'workerCount') ||
|
|
118
|
+
(0, util_1.clamp)(1, Math.max(1, hardwareConcurrency - 1), 5);
|
|
119
|
+
return [...new Array(workerCount)].map(() => new LazyWorker(this));
|
|
120
|
+
}
|
|
121
|
+
getWorkerPool() {
|
|
122
|
+
if (!this.workerPool) {
|
|
123
|
+
const res = this.createWorkerPool();
|
|
124
|
+
this.workerPool = res;
|
|
125
|
+
return res; // making this several steps makes TS happy
|
|
126
|
+
}
|
|
127
|
+
return this.workerPool;
|
|
275
128
|
}
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
129
|
+
async getWorker(sessionId) {
|
|
130
|
+
const workers = this.getWorkerPool();
|
|
131
|
+
let workerNumber = this.workerAssignments.get(sessionId);
|
|
132
|
+
if (workerNumber === undefined) {
|
|
133
|
+
const workerAssignment = (this.lastWorkerAssignment + 1) % workers.length;
|
|
134
|
+
this.workerAssignments.set(sessionId, workerAssignment);
|
|
135
|
+
this.lastWorkerAssignment = workerAssignment;
|
|
136
|
+
workerNumber = workerAssignment;
|
|
137
|
+
}
|
|
138
|
+
// console.log(`${sessionId} -> worker ${workerNumber}`)
|
|
139
|
+
const worker = workers[workerNumber].getWorker();
|
|
140
|
+
if (!worker) {
|
|
141
|
+
throw new Error('no web workers registered for RPC');
|
|
142
|
+
}
|
|
143
|
+
return worker;
|
|
286
144
|
}
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
145
|
+
async call(pluginManager, sessionId, functionName, args, options = {}) {
|
|
146
|
+
if (!sessionId) {
|
|
147
|
+
throw new TypeError('sessionId is required');
|
|
148
|
+
}
|
|
149
|
+
let done = false;
|
|
150
|
+
const worker = await this.getWorker(sessionId);
|
|
151
|
+
const rpcMethod = pluginManager.getRpcMethodType(functionName);
|
|
152
|
+
const serializedArgs = await rpcMethod.serializeArguments(args, this.name);
|
|
153
|
+
const filteredAndSerializedArgs = this.filterArgs(serializedArgs, sessionId);
|
|
154
|
+
// now actually call the worker
|
|
155
|
+
const callP = worker
|
|
156
|
+
.call(functionName, filteredAndSerializedArgs, {
|
|
157
|
+
timeout: 5 * 60 * 1000,
|
|
158
|
+
statusCallback: args.statusCallback,
|
|
159
|
+
rpcDriverClassName: this.name,
|
|
160
|
+
...options,
|
|
161
|
+
})
|
|
162
|
+
.finally(() => {
|
|
163
|
+
done = true;
|
|
164
|
+
});
|
|
165
|
+
// check every 5 seconds to see if the worker has been killed, and
|
|
166
|
+
// reject the killedP promise if it has
|
|
167
|
+
let killedCheckInterval;
|
|
168
|
+
const killedP = new Promise((resolve, reject) => {
|
|
169
|
+
killedCheckInterval = setInterval(() => {
|
|
170
|
+
// must've been killed
|
|
171
|
+
if (worker.status === 'killed') {
|
|
172
|
+
reject(new Error(`operation timed out, worker process stopped responding, ${worker.error}`));
|
|
312
173
|
}
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
case 6:
|
|
317
|
-
return _context3.abrupt("return", worker);
|
|
318
|
-
|
|
319
|
-
case 7:
|
|
320
|
-
case "end":
|
|
321
|
-
return _context3.stop();
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
}, _callee3, this);
|
|
325
|
-
}));
|
|
326
|
-
|
|
327
|
-
function getWorker(_x7) {
|
|
328
|
-
return _getWorker2.apply(this, arguments);
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
return getWorker;
|
|
332
|
-
}()
|
|
333
|
-
}, {
|
|
334
|
-
key: "call",
|
|
335
|
-
value: function () {
|
|
336
|
-
var _call = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee4(pluginManager, sessionId, functionName, args) {
|
|
337
|
-
var _this4 = this;
|
|
338
|
-
|
|
339
|
-
var options,
|
|
340
|
-
done,
|
|
341
|
-
worker,
|
|
342
|
-
rpcMethod,
|
|
343
|
-
serializedArgs,
|
|
344
|
-
filteredAndSerializedArgs,
|
|
345
|
-
callP,
|
|
346
|
-
killedCheckInterval,
|
|
347
|
-
killedP,
|
|
348
|
-
resultP,
|
|
349
|
-
_args4 = arguments;
|
|
350
|
-
return _regenerator.default.wrap(function _callee4$(_context4) {
|
|
351
|
-
while (1) {
|
|
352
|
-
switch (_context4.prev = _context4.next) {
|
|
353
|
-
case 0:
|
|
354
|
-
options = _args4.length > 4 && _args4[4] !== undefined ? _args4[4] : {};
|
|
355
|
-
|
|
356
|
-
if (sessionId) {
|
|
357
|
-
_context4.next = 3;
|
|
358
|
-
break;
|
|
174
|
+
else if (done) {
|
|
175
|
+
resolve(true);
|
|
359
176
|
}
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
return rpcMethod.serializeArguments(args, this.name);
|
|
373
|
-
|
|
374
|
-
case 10:
|
|
375
|
-
serializedArgs = _context4.sent;
|
|
376
|
-
filteredAndSerializedArgs = this.filterArgs(serializedArgs, sessionId); // now actually call the worker
|
|
377
|
-
|
|
378
|
-
callP = worker.call(functionName, filteredAndSerializedArgs, _objectSpread({
|
|
379
|
-
timeout: 5 * 60 * 1000,
|
|
380
|
-
// 5 minutes
|
|
381
|
-
statusCallback: args.statusCallback,
|
|
382
|
-
rpcDriverClassName: this.name
|
|
383
|
-
}, options)).finally(function () {
|
|
384
|
-
done = true;
|
|
385
|
-
}); // check every 5 seconds to see if the worker has been killed, and
|
|
386
|
-
// reject the killedP promise if it has
|
|
387
|
-
|
|
388
|
-
killedP = new Promise(function (resolve, reject) {
|
|
389
|
-
killedCheckInterval = setInterval(function () {
|
|
390
|
-
// must've been killed
|
|
391
|
-
if (worker.status === 'killed') {
|
|
392
|
-
reject(new Error("operation timed out, worker process stopped responding, ".concat(worker.error)));
|
|
393
|
-
} else if (done) {
|
|
394
|
-
resolve(true);
|
|
395
|
-
}
|
|
396
|
-
}, _this4.workerCheckFrequency);
|
|
397
|
-
}).finally(function () {
|
|
398
|
-
clearInterval(killedCheckInterval);
|
|
399
|
-
}); // the result is a race between the actual result promise, and the "killed"
|
|
400
|
-
// promise. the killed promise will only actually win if the worker was
|
|
401
|
-
// killed before the call could return
|
|
402
|
-
|
|
403
|
-
resultP = Promise.race([callP, killedP]);
|
|
404
|
-
return _context4.abrupt("return", rpcMethod.deserializeReturn(resultP, args, this.name));
|
|
405
|
-
|
|
406
|
-
case 16:
|
|
407
|
-
case "end":
|
|
408
|
-
return _context4.stop();
|
|
409
|
-
}
|
|
410
|
-
}
|
|
411
|
-
}, _callee4, this);
|
|
412
|
-
}));
|
|
413
|
-
|
|
414
|
-
function call(_x8, _x9, _x10, _x11) {
|
|
415
|
-
return _call.apply(this, arguments);
|
|
416
|
-
}
|
|
417
|
-
|
|
418
|
-
return call;
|
|
419
|
-
}()
|
|
420
|
-
}]);
|
|
421
|
-
return BaseRpcDriver;
|
|
422
|
-
}();
|
|
423
|
-
|
|
424
|
-
exports.default = BaseRpcDriver;
|
|
177
|
+
}, this.workerCheckFrequency);
|
|
178
|
+
}).finally(() => {
|
|
179
|
+
clearInterval(killedCheckInterval);
|
|
180
|
+
});
|
|
181
|
+
// the result is a race between the actual result promise, and the "killed"
|
|
182
|
+
// promise. the killed promise will only actually win if the worker was
|
|
183
|
+
// killed before the call could return
|
|
184
|
+
const resultP = Promise.race([callP, killedP]);
|
|
185
|
+
return rpcMethod.deserializeReturn(resultP, args, this.name);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
exports.default = BaseRpcDriver;
|