@jbrowse/core 2.1.2 → 2.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/ui/AboutDialog.js CHANGED
@@ -84,7 +84,7 @@ function AboutDialog({ config, handleClose, }) {
84
84
  if ((0, configuration_1.readConfObject)(config, 'type') === 'ReferenceSequenceTrack') {
85
85
  const asm = session.assemblies.find(a => a.sequence === config.configuration);
86
86
  trackName = asm
87
- ? `Reference Sequence (${(0, configuration_1.readConfObject)(asm, 'name')})`
87
+ ? `Reference Sequence (${(0, configuration_1.readConfObject)(asm, 'displayName') || (0, configuration_1.readConfObject)(asm, 'name')})`
88
88
  : 'Reference Sequence';
89
89
  }
90
90
  const details = typeof info === 'string'
@@ -1,24 +1,32 @@
1
- export default QuickLRU;
2
- /**
3
- * Heavily based on [quick-lru](https://www.npmjs.com/package/quick-lru)
4
- * (quick-lru didn't work for us because the export wouldn't compile in Webpack
5
- * properly)
6
- */
7
- declare class QuickLRU {
1
+ export default class QuickLRU extends Map<any, any> {
8
2
  constructor(options?: {});
9
3
  maxSize: any;
4
+ maxAge: any;
5
+ onEviction: any;
10
6
  cache: Map<any, any>;
11
7
  oldCache: Map<any, any>;
12
8
  _size: number;
9
+ _emitEvictions(cache: any): void;
10
+ _deleteIfExpired(key: any, item: any): boolean;
11
+ _getOrDeleteIfExpired(key: any, item: any): any;
12
+ _getItemValue(key: any, item: any): any;
13
+ _peek(key: any, cache: any): any;
13
14
  _set(key: any, value: any): void;
15
+ _moveToRecent(key: any, item: any): void;
16
+ _entriesAscending(): Generator<[any, any], void, unknown>;
14
17
  get(key: any): any;
15
- set(key: any, value: any): QuickLRU;
18
+ set(key: any, value: any, { maxAge }?: {
19
+ maxAge?: any;
20
+ }): void;
16
21
  has(key: any): boolean;
17
22
  peek(key: any): any;
18
23
  delete(key: any): boolean;
19
- clear(): void;
24
+ resize(newSize: any): void;
20
25
  keys(): Generator<any, void, unknown>;
21
26
  values(): Generator<any, void, unknown>;
22
- get size(): number;
23
- [Symbol.iterator](): Generator<[any, any], void, unknown>;
27
+ entriesDescending(): Generator<any[], void, unknown>;
28
+ entriesAscending(): Generator<any[], void, unknown>;
29
+ entries(): Generator<any[], void, unknown>;
30
+ forEach(callbackFunction: any, thisArgument?: QuickLRU): void;
31
+ [Symbol.iterator](): Generator<any[], void, unknown>;
24
32
  }
package/util/QuickLRU.js CHANGED
@@ -1,67 +1,140 @@
1
1
  "use strict";
2
+ // vendored from quick-lru@6.1.1, didn't like being compiled as a 'pure-esm' nodejs dependency
3
+ // the license is reproduced below https://github.com/sindresorhus/quick-lru/blob/main/license
4
+ // MIT License
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
- /* eslint-disable no-underscore-dangle */
4
- /**
5
- * Heavily based on [quick-lru](https://www.npmjs.com/package/quick-lru)
6
- * (quick-lru didn't work for us because the export wouldn't compile in Webpack
7
- * properly)
8
- */
9
- class QuickLRU {
6
+ // Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
7
+ // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
8
+ // The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
9
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
10
+ class QuickLRU extends Map {
10
11
  constructor(options = {}) {
12
+ super();
11
13
  if (!(options.maxSize && options.maxSize > 0)) {
12
14
  throw new TypeError('`maxSize` must be a number greater than 0');
13
15
  }
16
+ if (typeof options.maxAge === 'number' && options.maxAge === 0) {
17
+ throw new TypeError('`maxAge` must be a number greater than 0');
18
+ }
19
+ // TODO: Use private class fields when ESLint supports them.
14
20
  this.maxSize = options.maxSize;
21
+ this.maxAge = options.maxAge || Number.POSITIVE_INFINITY;
22
+ this.onEviction = options.onEviction;
15
23
  this.cache = new Map();
16
24
  this.oldCache = new Map();
17
25
  this._size = 0;
18
26
  }
27
+ // TODO: Use private class methods when targeting Node.js 16.
28
+ _emitEvictions(cache) {
29
+ if (typeof this.onEviction !== 'function') {
30
+ return;
31
+ }
32
+ for (const [key, item] of cache) {
33
+ this.onEviction(key, item.value);
34
+ }
35
+ }
36
+ _deleteIfExpired(key, item) {
37
+ if (typeof item.expiry === 'number' && item.expiry <= Date.now()) {
38
+ if (typeof this.onEviction === 'function') {
39
+ this.onEviction(key, item.value);
40
+ }
41
+ return this.delete(key);
42
+ }
43
+ return false;
44
+ }
45
+ _getOrDeleteIfExpired(key, item) {
46
+ const deleted = this._deleteIfExpired(key, item);
47
+ if (deleted === false) {
48
+ return item.value;
49
+ }
50
+ }
51
+ _getItemValue(key, item) {
52
+ return item.expiry ? this._getOrDeleteIfExpired(key, item) : item.value;
53
+ }
54
+ _peek(key, cache) {
55
+ const item = cache.get(key);
56
+ return this._getItemValue(key, item);
57
+ }
19
58
  _set(key, value) {
20
59
  this.cache.set(key, value);
21
- this._size += 1;
60
+ this._size++;
22
61
  if (this._size >= this.maxSize) {
23
62
  this._size = 0;
63
+ this._emitEvictions(this.oldCache);
24
64
  this.oldCache = this.cache;
25
65
  this.cache = new Map();
26
66
  }
27
67
  }
68
+ _moveToRecent(key, item) {
69
+ this.oldCache.delete(key);
70
+ this._set(key, item);
71
+ }
72
+ *_entriesAscending() {
73
+ for (const item of this.oldCache) {
74
+ const [key, value] = item;
75
+ if (!this.cache.has(key)) {
76
+ const deleted = this._deleteIfExpired(key, value);
77
+ if (deleted === false) {
78
+ yield item;
79
+ }
80
+ }
81
+ }
82
+ for (const item of this.cache) {
83
+ const [key, value] = item;
84
+ const deleted = this._deleteIfExpired(key, value);
85
+ if (deleted === false) {
86
+ yield item;
87
+ }
88
+ }
89
+ }
28
90
  get(key) {
29
91
  if (this.cache.has(key)) {
30
- return this.cache.get(key);
92
+ const item = this.cache.get(key);
93
+ return this._getItemValue(key, item);
31
94
  }
32
95
  if (this.oldCache.has(key)) {
33
- const value = this.oldCache.get(key);
34
- this.oldCache.delete(key);
35
- this._set(key, value);
36
- return value;
96
+ const item = this.oldCache.get(key);
97
+ if (this._deleteIfExpired(key, item) === false) {
98
+ this._moveToRecent(key, item);
99
+ return item.value;
100
+ }
37
101
  }
38
- return undefined;
39
102
  }
40
- set(key, value) {
103
+ set(key, value, { maxAge = this.maxAge } = {}) {
104
+ const expiry = typeof maxAge === 'number' && maxAge !== Number.POSITIVE_INFINITY
105
+ ? Date.now() + maxAge
106
+ : undefined;
41
107
  if (this.cache.has(key)) {
42
- this.cache.set(key, value);
108
+ this.cache.set(key, {
109
+ value,
110
+ expiry,
111
+ });
43
112
  }
44
113
  else {
45
- this._set(key, value);
114
+ this._set(key, { value, expiry });
46
115
  }
47
- return this;
48
116
  }
49
117
  has(key) {
50
- return this.cache.has(key) || this.oldCache.has(key);
118
+ if (this.cache.has(key)) {
119
+ return !this._deleteIfExpired(key, this.cache.get(key));
120
+ }
121
+ if (this.oldCache.has(key)) {
122
+ return !this._deleteIfExpired(key, this.oldCache.get(key));
123
+ }
124
+ return false;
51
125
  }
52
126
  peek(key) {
53
127
  if (this.cache.has(key)) {
54
- return this.cache.get(key);
128
+ return this._peek(key, this.cache);
55
129
  }
56
130
  if (this.oldCache.has(key)) {
57
- return this.oldCache.get(key);
131
+ return this._peek(key, this.oldCache);
58
132
  }
59
- return undefined;
60
133
  }
61
134
  delete(key) {
62
135
  const deleted = this.cache.delete(key);
63
136
  if (deleted) {
64
- this._size -= 1;
137
+ this._size--;
65
138
  }
66
139
  return this.oldCache.delete(key) || deleted;
67
140
  }
@@ -70,6 +143,27 @@ class QuickLRU {
70
143
  this.oldCache.clear();
71
144
  this._size = 0;
72
145
  }
146
+ resize(newSize) {
147
+ if (!(newSize && newSize > 0)) {
148
+ throw new TypeError('`maxSize` must be a number greater than 0');
149
+ }
150
+ const items = [...this._entriesAscending()];
151
+ const removeCount = items.length - newSize;
152
+ if (removeCount < 0) {
153
+ this.cache = new Map(items);
154
+ this.oldCache = new Map();
155
+ this._size = items.length;
156
+ }
157
+ else {
158
+ if (removeCount > 0) {
159
+ this._emitEvictions(items.slice(0, removeCount));
160
+ }
161
+ this.oldCache = new Map(items.slice(removeCount));
162
+ this.cache = new Map();
163
+ this._size = 0;
164
+ }
165
+ this.maxSize = newSize;
166
+ }
73
167
  *keys() {
74
168
  for (const [key] of this) {
75
169
  yield key;
@@ -82,23 +176,71 @@ class QuickLRU {
82
176
  }
83
177
  *[Symbol.iterator]() {
84
178
  for (const item of this.cache) {
85
- yield item;
179
+ const [key, value] = item;
180
+ const deleted = this._deleteIfExpired(key, value);
181
+ if (deleted === false) {
182
+ yield [key, value.value];
183
+ }
86
184
  }
87
185
  for (const item of this.oldCache) {
88
- const [key] = item;
186
+ const [key, value] = item;
89
187
  if (!this.cache.has(key)) {
90
- yield item;
188
+ const deleted = this._deleteIfExpired(key, value);
189
+ if (deleted === false) {
190
+ yield [key, value.value];
191
+ }
91
192
  }
92
193
  }
93
194
  }
195
+ *entriesDescending() {
196
+ let items = [...this.cache];
197
+ for (let i = items.length - 1; i >= 0; --i) {
198
+ const item = items[i];
199
+ const [key, value] = item;
200
+ const deleted = this._deleteIfExpired(key, value);
201
+ if (deleted === false) {
202
+ yield [key, value.value];
203
+ }
204
+ }
205
+ items = [...this.oldCache];
206
+ for (let i = items.length - 1; i >= 0; --i) {
207
+ const item = items[i];
208
+ const [key, value] = item;
209
+ if (!this.cache.has(key)) {
210
+ const deleted = this._deleteIfExpired(key, value);
211
+ if (deleted === false) {
212
+ yield [key, value.value];
213
+ }
214
+ }
215
+ }
216
+ }
217
+ *entriesAscending() {
218
+ for (const [key, value] of this._entriesAscending()) {
219
+ yield [key, value.value];
220
+ }
221
+ }
94
222
  get size() {
223
+ if (!this._size) {
224
+ return this.oldCache.size;
225
+ }
95
226
  let oldCacheSize = 0;
96
227
  for (const key of this.oldCache.keys()) {
97
228
  if (!this.cache.has(key)) {
98
- oldCacheSize += 1;
229
+ oldCacheSize++;
99
230
  }
100
231
  }
101
- return this._size + oldCacheSize;
232
+ return Math.min(this._size + oldCacheSize, this.maxSize);
233
+ }
234
+ entries() {
235
+ return this.entriesAscending();
236
+ }
237
+ forEach(callbackFunction, thisArgument = this) {
238
+ for (const [key, value] of this.entriesAscending()) {
239
+ callbackFunction.call(thisArgument, value, key, this);
240
+ }
241
+ }
242
+ get [Symbol.toStringTag]() {
243
+ return JSON.stringify([...this.entriesAscending()]);
102
244
  }
103
245
  }
104
246
  exports.default = QuickLRU;
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ const mobx_state_tree_1 = require("mobx-state-tree");
3
4
  const range_1 = require("./range");
4
5
  const _1 = require(".");
5
6
  const blockTypes_1 = require("./blockTypes");
@@ -35,6 +36,7 @@ function calculateDynamicBlocks(model, padding = true, elision = true) {
35
36
  const { assemblyName, refName, start: regionStart, end: regionEnd, reversed, } = region;
36
37
  const displayedRegionRightPx = displayedRegionLeftPx + (regionEnd - regionStart) / bpPerPx;
37
38
  const regionWidthPx = (regionEnd - regionStart) / bpPerPx;
39
+ const parentRegion = (0, mobx_state_tree_1.isStateTreeNode)(region) ? (0, mobx_state_tree_1.getSnapshot)(region) : region;
38
40
  if (displayedRegionLeftPx < windowRightPx &&
39
41
  displayedRegionRightPx > windowLeftPx) {
40
42
  // this displayed region overlaps the view, so make a record for it
@@ -66,7 +68,7 @@ function calculateDynamicBlocks(model, padding = true, elision = true) {
66
68
  end,
67
69
  reversed,
68
70
  offsetPx: blockOffsetPx,
69
- parentRegion: region,
71
+ parentRegion,
70
72
  regionNumber,
71
73
  widthPx,
72
74
  isLeftEndOfDisplayedRegion,
@@ -1,9 +1,11 @@
1
+ import { Instance } from 'mobx-state-tree';
1
2
  import { BlockSet } from './blockTypes';
2
3
  import { Region } from './types';
4
+ import { Region as RegionModel } from './types/mst';
3
5
  export interface Base1DViewModel {
4
6
  offsetPx: number;
5
7
  width: number;
6
- displayedRegions: Region[];
8
+ displayedRegions: (Region | Instance<typeof RegionModel>)[];
7
9
  bpPerPx: number;
8
10
  minimumBlockWidth: number;
9
11
  interRegionPaddingWidth: number;
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ const mobx_state_tree_1 = require("mobx-state-tree");
3
4
  const _1 = require(".");
4
5
  const blockTypes_1 = require("./blockTypes");
5
6
  function calculateStaticBlocks(model, padding = true, elision = true, extra = 0,
@@ -21,6 +22,7 @@ width = (typeof window !== 'undefined' && window.innerWidth) || model.width) {
21
22
  // clamp those to the region range, and then make blocks for that range
22
23
  const { assemblyName, refName, start: regionStart, end: regionEnd, reversed, } = region;
23
24
  const regionBlockCount = Math.ceil((regionEnd - regionStart) / blockSizeBp);
25
+ const parentRegion = (0, mobx_state_tree_1.isStateTreeNode)(region) ? (0, mobx_state_tree_1.getSnapshot)(region) : region;
24
26
  let windowRightBlockNum = Math.floor((windowRightBp - regionBpOffset) / blockSizeBp) + extra;
25
27
  if (windowRightBlockNum >= regionBlockCount) {
26
28
  windowRightBlockNum = regionBlockCount - 1;
@@ -55,7 +57,7 @@ width = (typeof window !== 'undefined' && window.innerWidth) || model.width) {
55
57
  end,
56
58
  reversed,
57
59
  offsetPx: (regionBpOffset + blockNum * blockSizeBp) / bpPerPx,
58
- parentRegion: region,
60
+ parentRegion,
59
61
  regionNumber,
60
62
  widthPx,
61
63
  isLeftEndOfDisplayedRegion,
package/util/index.d.ts CHANGED
@@ -188,7 +188,7 @@ export declare function renameRegionsIfNeeded<ARGTYPE extends {
188
188
  signal?: AbortSignal;
189
189
  adapterConfig: unknown;
190
190
  sessionId: string;
191
- statusCallback?: Function;
191
+ statusCallback?: (arg: string) => void;
192
192
  }>(assemblyManager: AssemblyManager, args: ARGTYPE): Promise<ARGTYPE & {
193
193
  regions: (Region & {
194
194
  originalRefName?: string | undefined;
@@ -4,4 +4,4 @@ import { FileLocation } from '../types';
4
4
  import PluginManager from '../../PluginManager';
5
5
  export { RemoteFileWithRangeCache };
6
6
  export declare function openLocation(location: FileLocation, pluginManager?: PluginManager): GenericFilehandle;
7
- export declare function getFetcher(location: FileLocation, pluginManager: PluginManager): Fetcher;
7
+ export declare function getFetcher(location: FileLocation, pluginManager?: PluginManager): Fetcher;
package/util/io/index.js CHANGED
@@ -70,9 +70,11 @@ function getFetcher(location, pluginManager) {
70
70
  if (!(0, types_1.isUriLocation)(location)) {
71
71
  throw new Error(`Not a valid UriLocation: ${JSON.stringify(location)}`);
72
72
  }
73
- const internetAccount = getInternetAccount(location, pluginManager);
74
- if (internetAccount) {
75
- return internetAccount.getFetcher(location);
73
+ if (pluginManager) {
74
+ const internetAccount = getInternetAccount(location, pluginManager);
75
+ if (internetAccount) {
76
+ return internetAccount.getFetcher(location);
77
+ }
76
78
  }
77
79
  return checkAuthNeededFetch;
78
80
  }
@@ -13,13 +13,9 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
13
13
  var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
- var __importDefault = (this && this.__importDefault) || function (mod) {
17
- return (mod && mod.__esModule) ? mod : { "default": mod };
18
- };
19
16
  Object.defineProperty(exports, "__esModule", { value: true });
20
17
  exports.isRetryException = exports.isAuthNeededException = exports.RetryError = exports.AuthNeededError = exports.isUriLocation = exports.isAbstractMenuManager = exports.isAppRootModel = exports.isTrackViewModel = exports.isDisplayModel = exports.isTrackModel = exports.isViewModel = exports.isSelectionContainer = exports.isSessionWithSessionPlugins = exports.isSessionModelWithConnections = exports.isSessionModelWithWidgets = exports.isSessionWithAddTracks = exports.isSessionModelWithConfigEditing = exports.isSessionModel = exports.isViewContainer = void 0;
21
18
  const mobx_state_tree_1 = require("mobx-state-tree");
22
- const TextSearchManager_1 = __importDefault(require("../../TextSearch/TextSearchManager"));
23
19
  __exportStar(require("./util"), exports);
24
20
  function isViewContainer(thing) {
25
21
  return ((0, mobx_state_tree_1.isStateTreeNode)(thing) &&
package/util/when.d.ts CHANGED
@@ -1,7 +1,6 @@
1
- interface WhenOpts {
2
- timeout?: number;
1
+ import { IWhenOptions } from 'mobx';
2
+ interface WhenOpts extends IWhenOptions {
3
3
  signal?: AbortSignal;
4
- name?: string;
5
4
  }
6
5
  /**
7
6
  * Wrapper for mobx `when` that adds timeout and aborting support.