@jbrowse/core 1.7.11 → 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 +20 -4
- package/BaseFeatureWidget/BaseFeatureDetail.js +313 -558
- package/BaseFeatureWidget/SequenceFeatureDetails.js +213 -473
- package/BaseFeatureWidget/index.d.ts +2 -2
- package/BaseFeatureWidget/index.js +88 -124
- package/BaseFeatureWidget/types.d.ts +1 -0
- 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 +84 -117
- package/PluginManager.js +377 -666
- package/ReExports/Attributes.d.ts +2 -0
- package/ReExports/Attributes.js +5 -0
- package/ReExports/BaseCard.d.ts +2 -0
- package/ReExports/BaseCard.js +5 -0
- package/ReExports/DataGrid.d.ts +2 -0
- package/ReExports/DataGrid.js +6 -0
- package/ReExports/FeatureDetails.d.ts +2 -0
- package/ReExports/FeatureDetails.js +5 -0
- package/ReExports/index.js +6 -12
- package/ReExports/list.d.ts +5 -0
- package/ReExports/list.js +271 -7
- package/ReExports/material-ui-colors.d.ts +1 -19
- package/ReExports/material-ui-colors.js +16 -158
- package/ReExports/modules.d.ts +68 -109
- package/ReExports/modules.js +455 -244
- package/TextSearch/BaseResults.js +51 -123
- package/TextSearch/TextSearchManager.d.ts +3 -1
- package/TextSearch/TextSearchManager.js +66 -144
- package/assemblyManager/assembly.js +280 -554
- package/assemblyManager/assemblyConfigSchema.js +47 -64
- package/assemblyManager/assemblyManager.d.ts +12 -10
- package/assemblyManager/assemblyManager.js +126 -270
- 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.d.ts +1 -1
- 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 +16 -18
- 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.d.ts +10 -10
- package/pluggableElementTypes/models/BaseDisplayModel.js +58 -95
- package/pluggableElementTypes/models/BaseTrackModel.d.ts +1 -1
- package/pluggableElementTypes/models/BaseTrackModel.js +139 -200
- 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 -255
- package/pluggableElementTypes/renderers/RendererType.js +31 -105
- package/pluggableElementTypes/renderers/ServerSideRenderedContent.js +61 -72
- package/pluggableElementTypes/renderers/ServerSideRendererType.d.ts +2 -2
- 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.d.ts +1 -3
- package/rpc/coreRpcMethods.js +221 -959
- package/rpc/remoteAbortSignals.js +46 -70
- package/tsconfig.build.tsbuildinfo +1 -1
- package/ui/AboutDialog.js +107 -158
- package/ui/App.js +157 -261
- package/ui/AssemblySelector.d.ts +1 -1
- package/ui/AssemblySelector.js +59 -115
- package/ui/CascadingMenu.js +100 -199
- package/ui/ColorPicker.d.ts +16 -0
- package/ui/ColorPicker.js +97 -0
- package/ui/Drawer.js +28 -58
- package/ui/DrawerWidget.js +109 -209
- package/ui/DropDownMenu.d.ts +0 -8
- package/ui/DropDownMenu.js +60 -97
- package/ui/EditableTypography.d.ts +1 -1
- package/ui/EditableTypography.js +87 -155
- package/ui/ErrorMessage.js +41 -66
- 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 -71
- package/ui/FileSelector/UrlChooser.js +17 -38
- package/ui/FileSelector/index.js +6 -12
- package/ui/Icons.d.ts +1 -1
- package/ui/Icons.js +45 -69
- package/ui/Logo.js +57 -110
- package/ui/Menu.d.ts +1 -1
- package/ui/Menu.js +232 -355
- package/ui/PrerenderedCanvas.js +63 -78
- package/ui/ResizeHandle.js +87 -114
- package/ui/ReturnToImportFormDialog.js +32 -59
- package/ui/SanitizedHTML.js +63 -52
- package/ui/Snackbar.js +74 -99
- package/ui/SnackbarModel.js +37 -51
- package/ui/Tooltip.d.ts +3 -1
- package/ui/Tooltip.js +49 -74
- package/ui/ViewContainer.js +113 -183
- 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.d.ts +279 -131
- package/ui/theme.js +197 -225
- package/util/Base1DUtils.d.ts +32 -0
- package/util/Base1DUtils.js +174 -0
- package/util/Base1DViewModel.d.ts +16 -37
- package/util/Base1DViewModel.js +116 -295
- 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 +18 -39
- package/util/index.js +743 -1236
- 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 -557
- package/util/layouts/MultiLayout.js +41 -109
- package/util/layouts/PrecomputedLayout.js +56 -114
- 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 -171
- package/util/types/index.d.ts +3 -3
- package/util/types/index.js +110 -179
- package/util/types/mst.d.ts +3 -3
- package/util/types/mst.js +91 -142
- 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 -51
- 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 -111
- 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
|
@@ -1,266 +1,97 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
16
|
-
|
|
17
|
-
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
18
|
-
|
|
19
|
-
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
20
|
-
|
|
21
|
-
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
22
|
-
|
|
23
|
-
var _get2 = _interopRequireDefault(require("@babel/runtime/helpers/get"));
|
|
24
|
-
|
|
25
|
-
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
26
|
-
|
|
27
|
-
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
|
|
28
|
-
|
|
29
|
-
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
|
|
30
|
-
|
|
31
|
-
var _httpRangeFetcher = require("http-range-fetcher");
|
|
32
|
-
|
|
33
|
-
var _buffer = require("buffer");
|
|
34
|
-
|
|
35
|
-
var _genericFilehandle = require("generic-filehandle");
|
|
36
|
-
|
|
37
|
-
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
38
|
-
|
|
39
|
-
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
40
|
-
|
|
41
|
-
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
42
|
-
|
|
43
|
-
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; }
|
|
44
|
-
|
|
45
|
-
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; }
|
|
46
|
-
|
|
47
|
-
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2.default)(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2.default)(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2.default)(this, result); }; }
|
|
48
|
-
|
|
49
|
-
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
50
|
-
|
|
51
|
-
var fetchers = {};
|
|
52
|
-
|
|
53
|
-
function binaryRangeFetch(url, start, end) {
|
|
54
|
-
var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
55
|
-
var fetcher = fetchers[url];
|
|
56
|
-
|
|
57
|
-
if (!fetcher) {
|
|
58
|
-
throw new Error("fetch not registered for ".concat(url));
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
return fetcher(url, start, end, options);
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RemoteFileWithRangeCache = exports.clearCache = void 0;
|
|
4
|
+
const http_range_fetcher_1 = require("http-range-fetcher");
|
|
5
|
+
const buffer_1 = require("buffer");
|
|
6
|
+
const generic_filehandle_1 = require("generic-filehandle");
|
|
7
|
+
const fetchers = {};
|
|
8
|
+
function binaryRangeFetch(url, start, end, options = {}) {
|
|
9
|
+
const fetcher = fetchers[url];
|
|
10
|
+
if (!fetcher) {
|
|
11
|
+
throw new Error(`fetch not registered for ${url}`);
|
|
12
|
+
}
|
|
13
|
+
return fetcher(url, start, end, options);
|
|
62
14
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
// 128KiB
|
|
70
|
-
maxFetchSize: 100 * Math.pow(1024, 2),
|
|
71
|
-
// 100MiB
|
|
72
|
-
minimumTTL: 24 * 60 * 60 * 1000 // 1 day
|
|
73
|
-
|
|
15
|
+
const globalRangeCache = new http_range_fetcher_1.HttpRangeFetcher({
|
|
16
|
+
fetch: binaryRangeFetch,
|
|
17
|
+
size: 500 * 1024 ** 2,
|
|
18
|
+
chunkSize: 128 * 124,
|
|
19
|
+
maxFetchSize: 100 * 1024 ** 2,
|
|
20
|
+
minimumTTL: 24 * 60 * 60 * 1000, // 1 day
|
|
74
21
|
});
|
|
75
|
-
|
|
76
22
|
function clearCache() {
|
|
77
|
-
|
|
23
|
+
globalRangeCache.reset();
|
|
78
24
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
;
|
|
112
|
-
_ref = requestHeaders.find(function (_ref3) {
|
|
113
|
-
var _ref4 = (0, _slicedToArray2.default)(_ref3, 1),
|
|
114
|
-
key = _ref4[0];
|
|
115
|
-
|
|
116
|
-
return key === 'range';
|
|
117
|
-
}) || [undefined, undefined];
|
|
118
|
-
_ref2 = (0, _slicedToArray2.default)(_ref, 2);
|
|
119
|
-
range = _ref2[1];
|
|
120
|
-
} else {
|
|
121
|
-
range = requestHeaders.range;
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
if (!range) {
|
|
126
|
-
_context.next = 14;
|
|
127
|
-
break;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
rangeParse = /bytes=(\d+)-(\d+)/.exec(range);
|
|
131
|
-
|
|
132
|
-
if (!rangeParse) {
|
|
133
|
-
_context.next = 14;
|
|
134
|
-
break;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
_rangeParse = (0, _slicedToArray2.default)(rangeParse, 3), _start = _rangeParse[1], _end = _rangeParse[2];
|
|
138
|
-
s = parseInt(_start, 10);
|
|
139
|
-
e = parseInt(_end, 10);
|
|
140
|
-
_context.next = 11;
|
|
141
|
-
return globalRangeCache.getRange(url, s, e - s + 1, {
|
|
142
|
-
signal: init && init.signal
|
|
25
|
+
exports.clearCache = clearCache;
|
|
26
|
+
class RemoteFileWithRangeCache extends generic_filehandle_1.RemoteFile {
|
|
27
|
+
async fetch(url, init) {
|
|
28
|
+
if (!fetchers[String(url)]) {
|
|
29
|
+
fetchers[String(url)] = this.fetchBinaryRange.bind(this);
|
|
30
|
+
}
|
|
31
|
+
// if it is a range request, route it through the range cache
|
|
32
|
+
const requestHeaders = init && init.headers;
|
|
33
|
+
let range;
|
|
34
|
+
if (requestHeaders) {
|
|
35
|
+
if (requestHeaders instanceof Headers) {
|
|
36
|
+
range = requestHeaders.get('range');
|
|
37
|
+
}
|
|
38
|
+
else if (Array.isArray(requestHeaders)) {
|
|
39
|
+
;
|
|
40
|
+
[, range] = requestHeaders.find(([key]) => key === 'range') || [
|
|
41
|
+
undefined,
|
|
42
|
+
undefined,
|
|
43
|
+
];
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
range = requestHeaders.range;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
if (range) {
|
|
50
|
+
const rangeParse = /bytes=(\d+)-(\d+)/.exec(range);
|
|
51
|
+
if (rangeParse) {
|
|
52
|
+
const [, start, end] = rangeParse;
|
|
53
|
+
const s = parseInt(start, 10);
|
|
54
|
+
const e = parseInt(end, 10);
|
|
55
|
+
const response = await globalRangeCache.getRange(url, s, e - s + 1, {
|
|
56
|
+
signal: init && init.signal,
|
|
143
57
|
});
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
response = _context.sent;
|
|
147
|
-
headers = response.headers;
|
|
148
|
-
return _context.abrupt("return", new Response(response.buffer, {
|
|
149
|
-
status: 206,
|
|
150
|
-
headers: headers
|
|
151
|
-
}));
|
|
152
|
-
|
|
153
|
-
case 14:
|
|
154
|
-
return _context.abrupt("return", (0, _get2.default)((0, _getPrototypeOf2.default)(RemoteFileWithRangeCache.prototype), "fetch", this).call(this, url, init));
|
|
155
|
-
|
|
156
|
-
case 15:
|
|
157
|
-
case "end":
|
|
158
|
-
return _context.stop();
|
|
58
|
+
const { headers } = response;
|
|
59
|
+
return new Response(response.buffer, { status: 206, headers });
|
|
159
60
|
}
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
61
|
+
}
|
|
62
|
+
return super.fetch(url, init);
|
|
63
|
+
}
|
|
64
|
+
async fetchBinaryRange(url, start, end, options = {}) {
|
|
65
|
+
const requestDate = new Date();
|
|
66
|
+
const requestHeaders = {
|
|
67
|
+
...options.headers,
|
|
68
|
+
range: `bytes=${start}-${end}`,
|
|
69
|
+
};
|
|
70
|
+
const res = await super.fetch(url, {
|
|
71
|
+
...options,
|
|
72
|
+
headers: requestHeaders,
|
|
73
|
+
});
|
|
74
|
+
const responseDate = new Date();
|
|
75
|
+
if (res.status !== 206) {
|
|
76
|
+
const errorMessage = `HTTP ${res.status} (${res.statusText}) when fetching ${url} bytes ${start}-${end}`;
|
|
77
|
+
const hint = ' (should be 206 for range requests)';
|
|
78
|
+
throw new Error(`${errorMessage}${res.status === 200 ? hint : ''}`);
|
|
79
|
+
}
|
|
80
|
+
// translate the Headers object into a regular key -> value object.
|
|
81
|
+
// will miss duplicate headers of course
|
|
82
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
83
|
+
const headers = {};
|
|
84
|
+
for (const [k, v] of res.headers.entries()) {
|
|
85
|
+
headers[k] = v;
|
|
86
|
+
}
|
|
87
|
+
// return the response headers, and the data buffer
|
|
88
|
+
const arrayBuffer = await res.arrayBuffer();
|
|
89
|
+
return {
|
|
90
|
+
headers,
|
|
175
91
|
requestDate,
|
|
176
|
-
requestHeaders,
|
|
177
|
-
res,
|
|
178
92
|
responseDate,
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
_step$value,
|
|
185
|
-
k,
|
|
186
|
-
v,
|
|
187
|
-
arrayBuffer,
|
|
188
|
-
_args2 = arguments;
|
|
189
|
-
|
|
190
|
-
return _regenerator.default.wrap(function _callee2$(_context2) {
|
|
191
|
-
while (1) {
|
|
192
|
-
switch (_context2.prev = _context2.next) {
|
|
193
|
-
case 0:
|
|
194
|
-
options = _args2.length > 3 && _args2[3] !== undefined ? _args2[3] : {};
|
|
195
|
-
requestDate = new Date();
|
|
196
|
-
requestHeaders = _objectSpread(_objectSpread({}, options.headers), {}, {
|
|
197
|
-
range: "bytes=".concat(start, "-").concat(end)
|
|
198
|
-
});
|
|
199
|
-
_context2.next = 5;
|
|
200
|
-
return (0, _get2.default)((0, _getPrototypeOf2.default)(RemoteFileWithRangeCache.prototype), "fetch", this).call(this, url, _objectSpread(_objectSpread({}, options), {}, {
|
|
201
|
-
headers: requestHeaders
|
|
202
|
-
}));
|
|
203
|
-
|
|
204
|
-
case 5:
|
|
205
|
-
res = _context2.sent;
|
|
206
|
-
responseDate = new Date();
|
|
207
|
-
|
|
208
|
-
if (!(res.status !== 206)) {
|
|
209
|
-
_context2.next = 11;
|
|
210
|
-
break;
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
errorMessage = "HTTP ".concat(res.status, " (").concat(res.statusText, ") when fetching ").concat(url, " bytes ").concat(start, "-").concat(end);
|
|
214
|
-
hint = ' (should be 206 for range requests)';
|
|
215
|
-
throw new Error("".concat(errorMessage).concat(res.status === 200 ? hint : ''));
|
|
216
|
-
|
|
217
|
-
case 11:
|
|
218
|
-
// translate the Headers object into a regular key -> value object.
|
|
219
|
-
// will miss duplicate headers of course
|
|
220
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
221
|
-
headers = {};
|
|
222
|
-
_iterator = _createForOfIteratorHelper(res.headers.entries());
|
|
223
|
-
|
|
224
|
-
try {
|
|
225
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
226
|
-
_step$value = (0, _slicedToArray2.default)(_step.value, 2), k = _step$value[0], v = _step$value[1];
|
|
227
|
-
headers[k] = v;
|
|
228
|
-
} // return the response headers, and the data buffer
|
|
229
|
-
|
|
230
|
-
} catch (err) {
|
|
231
|
-
_iterator.e(err);
|
|
232
|
-
} finally {
|
|
233
|
-
_iterator.f();
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
_context2.next = 16;
|
|
237
|
-
return res.arrayBuffer();
|
|
238
|
-
|
|
239
|
-
case 16:
|
|
240
|
-
arrayBuffer = _context2.sent;
|
|
241
|
-
return _context2.abrupt("return", {
|
|
242
|
-
headers: headers,
|
|
243
|
-
requestDate: requestDate,
|
|
244
|
-
responseDate: responseDate,
|
|
245
|
-
buffer: _buffer.Buffer.from(arrayBuffer)
|
|
246
|
-
});
|
|
247
|
-
|
|
248
|
-
case 18:
|
|
249
|
-
case "end":
|
|
250
|
-
return _context2.stop();
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
}, _callee2, this);
|
|
254
|
-
}));
|
|
255
|
-
|
|
256
|
-
function fetchBinaryRange(_x3, _x4, _x5) {
|
|
257
|
-
return _fetchBinaryRange.apply(this, arguments);
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
return fetchBinaryRange;
|
|
261
|
-
}()
|
|
262
|
-
}]);
|
|
263
|
-
return RemoteFileWithRangeCache;
|
|
264
|
-
}(_genericFilehandle.RemoteFile);
|
|
265
|
-
|
|
266
|
-
exports.RemoteFileWithRangeCache = RemoteFileWithRangeCache;
|
|
93
|
+
buffer: buffer_1.Buffer.from(arrayBuffer),
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
exports.RemoteFileWithRangeCache = RemoteFileWithRangeCache;
|
package/util/io/index.js
CHANGED
|
@@ -1,186 +1,112 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
exports.openLocation = openLocation;
|
|
16
|
-
|
|
17
|
-
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
18
|
-
|
|
19
|
-
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
20
|
-
|
|
21
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
22
|
-
|
|
23
|
-
var _genericFilehandle = require("generic-filehandle");
|
|
24
|
-
|
|
25
|
-
var _detectNode = _interopRequireDefault(require("detect-node"));
|
|
26
|
-
|
|
27
|
-
var _RemoteFileWithRangeCache = require("./RemoteFileWithRangeCache");
|
|
28
|
-
|
|
29
|
-
var _types = require("../types");
|
|
30
|
-
|
|
31
|
-
var _tracks = require("../tracks");
|
|
32
|
-
|
|
33
|
-
var _ = require("../");
|
|
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
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getFetcher = exports.openLocation = exports.RemoteFileWithRangeCache = void 0;
|
|
7
|
+
const generic_filehandle_1 = require("generic-filehandle");
|
|
8
|
+
const detect_node_1 = __importDefault(require("detect-node"));
|
|
9
|
+
// locals
|
|
10
|
+
const RemoteFileWithRangeCache_1 = require("./RemoteFileWithRangeCache");
|
|
11
|
+
Object.defineProperty(exports, "RemoteFileWithRangeCache", { enumerable: true, get: function () { return RemoteFileWithRangeCache_1.RemoteFileWithRangeCache; } });
|
|
12
|
+
const types_1 = require("../types");
|
|
13
|
+
const tracks_1 = require("../tracks");
|
|
14
|
+
const __1 = require("../");
|
|
39
15
|
function isLocalPathLocation(location) {
|
|
40
|
-
|
|
16
|
+
return 'localPath' in location;
|
|
41
17
|
}
|
|
42
|
-
|
|
43
18
|
function isBlobLocation(location) {
|
|
44
|
-
|
|
19
|
+
return 'blobId' in location;
|
|
45
20
|
}
|
|
46
|
-
|
|
47
21
|
function openLocation(location, pluginManager) {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
if (isLocalPathLocation(location)) {
|
|
53
|
-
if (!location.localPath) {
|
|
54
|
-
throw new Error('No local path provided');
|
|
22
|
+
if (!location) {
|
|
23
|
+
throw new Error('must provide a location to openLocation');
|
|
55
24
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
25
|
+
if (isLocalPathLocation(location)) {
|
|
26
|
+
if (!location.localPath) {
|
|
27
|
+
throw new Error('No local path provided');
|
|
28
|
+
}
|
|
29
|
+
if (detect_node_1.default || __1.isElectron) {
|
|
30
|
+
return new generic_filehandle_1.LocalFile(location.localPath);
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
throw new Error("can't use local files in the browser");
|
|
34
|
+
}
|
|
61
35
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
throw new Error("file (\"".concat(location.name, "\") was opened locally from a previous session. To restore it, go to track settings and reopen the file"));
|
|
36
|
+
if (isBlobLocation(location)) {
|
|
37
|
+
// special case where blob is not directly stored on the model, use a getter
|
|
38
|
+
const blob = (0, tracks_1.getBlob)(location.blobId);
|
|
39
|
+
if (!blob) {
|
|
40
|
+
throw new Error(`file ("${location.name}") was opened locally from a previous session. To restore it, go to track settings and reopen the file`);
|
|
41
|
+
}
|
|
42
|
+
return new generic_filehandle_1.BlobFile(blob);
|
|
70
43
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
return new _RemoteFileWithRangeCache.RemoteFileWithRangeCache(absoluteLocation.uri, {
|
|
96
|
-
fetch: checkAuthNeededFetch
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
throw new Error('invalid fileLocation');
|
|
44
|
+
if ((0, types_1.isUriLocation)(location)) {
|
|
45
|
+
// Check for empty string
|
|
46
|
+
if (!location.uri) {
|
|
47
|
+
throw new Error('No URI provided');
|
|
48
|
+
}
|
|
49
|
+
// Resolve any relative URLs to absolute URLs
|
|
50
|
+
const absoluteLocation = location.baseUri
|
|
51
|
+
? { ...location, uri: new URL(location.uri, location.baseUri).href }
|
|
52
|
+
: location;
|
|
53
|
+
// If there is a plugin manager, we can try internet accounts
|
|
54
|
+
if (pluginManager) {
|
|
55
|
+
const internetAccount = getInternetAccount(location, pluginManager);
|
|
56
|
+
// If an internetAccount was found, use it to open the location
|
|
57
|
+
if (internetAccount) {
|
|
58
|
+
return internetAccount.openLocation(absoluteLocation);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
// Otherwise fall back on usual open
|
|
62
|
+
return new RemoteFileWithRangeCache_1.RemoteFileWithRangeCache(absoluteLocation.uri, {
|
|
63
|
+
fetch: checkAuthNeededFetch,
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
throw new Error('invalid fileLocation');
|
|
101
67
|
}
|
|
102
|
-
|
|
68
|
+
exports.openLocation = openLocation;
|
|
103
69
|
function getFetcher(location, pluginManager) {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
return
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
return checkAuthNeededFetch;
|
|
70
|
+
if (!(0, types_1.isUriLocation)(location)) {
|
|
71
|
+
throw new Error(`Not a valid UriLocation: ${JSON.stringify(location)}`);
|
|
72
|
+
}
|
|
73
|
+
const internetAccount = getInternetAccount(location, pluginManager);
|
|
74
|
+
if (internetAccount) {
|
|
75
|
+
return internetAccount.getFetcher(location);
|
|
76
|
+
}
|
|
77
|
+
return checkAuthNeededFetch;
|
|
115
78
|
}
|
|
116
|
-
|
|
79
|
+
exports.getFetcher = getFetcher;
|
|
117
80
|
function getInternetAccount(location, pluginManager) {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
} // If there is no appRootModel, but there is pre-auth, create a temporary
|
|
123
|
-
// internetAccount. This is typical in a worker.
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
if (location.internetAccountPreAuthorization) {
|
|
127
|
-
if (!location.internetAccountPreAuthorization.authInfo.token) {
|
|
128
|
-
throw new Error('Failed to obtain token from internet account. Try reloading the page');
|
|
81
|
+
const { rootModel } = pluginManager;
|
|
82
|
+
// If there is an appRootModel, use it to find the internetAccount
|
|
83
|
+
if (rootModel && (0, types_1.isAppRootModel)(rootModel)) {
|
|
84
|
+
return rootModel.findAppropriateInternetAccount(location);
|
|
129
85
|
}
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
86
|
+
// If there is no appRootModel, but there is pre-auth, create a temporary
|
|
87
|
+
// internetAccount. This is typical in a worker.
|
|
88
|
+
if (location.internetAccountPreAuthorization) {
|
|
89
|
+
if (!location.internetAccountPreAuthorization.authInfo.token) {
|
|
90
|
+
throw new Error('Failed to obtain token from internet account. Try reloading the page');
|
|
91
|
+
}
|
|
92
|
+
const internetAccountType = pluginManager.getInternetAccountType(location.internetAccountPreAuthorization.internetAccountType);
|
|
93
|
+
return internetAccountType.stateModel.create({
|
|
94
|
+
type: location.internetAccountPreAuthorization.internetAccountType,
|
|
95
|
+
configuration: location.internetAccountPreAuthorization.authInfo.configuration,
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
// This fetch throws a special error if the response is "401" and includes a
|
|
140
101
|
// "WWW-Authenticate: Basic" header. This is so downstream code can retry if
|
|
141
102
|
// needed with HTTP Basic authentication included
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
function _checkAuthNeededFetch() {
|
|
149
|
-
_checkAuthNeededFetch = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(url, opts) {
|
|
150
|
-
var response, authHeaders;
|
|
151
|
-
return _regenerator.default.wrap(function _callee$(_context) {
|
|
152
|
-
while (1) {
|
|
153
|
-
switch (_context.prev = _context.next) {
|
|
154
|
-
case 0:
|
|
155
|
-
_context.next = 2;
|
|
156
|
-
return fetch(url, opts);
|
|
157
|
-
|
|
158
|
-
case 2:
|
|
159
|
-
response = _context.sent;
|
|
160
|
-
|
|
161
|
-
if (!(response.status === 401)) {
|
|
162
|
-
_context.next = 7;
|
|
163
|
-
break;
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
authHeaders = response.headers.get('WWW-Authenticate');
|
|
167
|
-
|
|
168
|
-
if (!(authHeaders && authHeaders.includes('Basic'))) {
|
|
169
|
-
_context.next = 7;
|
|
170
|
-
break;
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
throw new _types.AuthNeededError('Accessing HTTPBasic resource without authentication', url.toString());
|
|
174
|
-
|
|
175
|
-
case 7:
|
|
176
|
-
return _context.abrupt("return", response);
|
|
177
|
-
|
|
178
|
-
case 8:
|
|
179
|
-
case "end":
|
|
180
|
-
return _context.stop();
|
|
103
|
+
async function checkAuthNeededFetch(url, opts) {
|
|
104
|
+
const response = await fetch(url, opts);
|
|
105
|
+
if (response.status === 401) {
|
|
106
|
+
const authHeaders = response.headers.get('WWW-Authenticate');
|
|
107
|
+
if (authHeaders && authHeaders.includes('Basic')) {
|
|
108
|
+
throw new types_1.AuthNeededError('Accessing HTTPBasic resource without authentication', url.toString());
|
|
181
109
|
}
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
return _checkAuthNeededFetch.apply(this, arguments);
|
|
186
|
-
}
|
|
110
|
+
}
|
|
111
|
+
return response;
|
|
112
|
+
}
|