@gmod/bam 7.9.1 → 8.0.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/dist/bamFile.d.ts +31 -27
- package/dist/bamFile.js +80 -202
- package/dist/bamFile.js.map +1 -1
- package/dist/indexFile.d.ts +3 -3
- package/dist/indexFile.js +14 -12
- package/dist/indexFile.js.map +1 -1
- package/dist/util.d.ts +1 -21
- package/dist/util.js +6 -28
- package/dist/util.js.map +1 -1
- package/esm/bamFile.d.ts +31 -27
- package/esm/bamFile.js +80 -202
- package/esm/bamFile.js.map +1 -1
- package/esm/indexFile.d.ts +3 -3
- package/esm/indexFile.js +14 -12
- package/esm/indexFile.js.map +1 -1
- package/esm/util.d.ts +1 -21
- package/esm/util.js +4 -27
- package/esm/util.js.map +1 -1
- package/package.json +12 -11
- package/src/bamFile.ts +88 -235
- package/src/indexFile.ts +14 -12
- package/src/util.ts +4 -27
package/src/indexFile.ts
CHANGED
|
@@ -53,14 +53,14 @@ export default abstract class IndexFile<
|
|
|
53
53
|
public filehandle: GenericFilehandle
|
|
54
54
|
public renameRefSeq: (s: string) => string
|
|
55
55
|
|
|
56
|
-
private
|
|
56
|
+
private parseP?: Promise<TParsed>
|
|
57
57
|
/**
|
|
58
|
-
* The signal `
|
|
58
|
+
* The signal `parseP` was started under, while it is still in flight. The
|
|
59
59
|
* index is parsed once and shared by every query against the file, so without
|
|
60
60
|
* this the first query to arrive would own a read all the others depend on —
|
|
61
61
|
* see {@link parse}.
|
|
62
62
|
*/
|
|
63
|
-
private
|
|
63
|
+
private parseSignal?: AbortSignal
|
|
64
64
|
|
|
65
65
|
constructor({
|
|
66
66
|
filehandle,
|
|
@@ -128,6 +128,8 @@ export default abstract class IndexFile<
|
|
|
128
128
|
return optimizeChunks(chunks, this.getLowestChunk(ba, min))
|
|
129
129
|
}
|
|
130
130
|
|
|
131
|
+
// SYNC: ~/src/gmod/tabix-js/src/indexFile.ts parse — same owner-signal
|
|
132
|
+
// tracking and one-attempt retry, and the same reasoning below.
|
|
131
133
|
/**
|
|
132
134
|
* Parse the index, or join the parse already running.
|
|
133
135
|
*
|
|
@@ -153,13 +155,13 @@ export default abstract class IndexFile<
|
|
|
153
155
|
*/
|
|
154
156
|
async parse(opts: BaseOpts = {}, retried = false): Promise<TParsed> {
|
|
155
157
|
throwIfAborted(opts.signal)
|
|
156
|
-
const pending = this.
|
|
158
|
+
const pending = this.parseP
|
|
157
159
|
if (!pending) {
|
|
158
160
|
return this.startParse(opts)
|
|
159
161
|
}
|
|
160
162
|
|
|
161
163
|
// read before awaiting: the owner is forgotten as soon as the parse settles
|
|
162
|
-
const ownerSignal = this.
|
|
164
|
+
const ownerSignal = this.parseSignal
|
|
163
165
|
try {
|
|
164
166
|
return await pending
|
|
165
167
|
} catch (e) {
|
|
@@ -172,22 +174,22 @@ export default abstract class IndexFile<
|
|
|
172
174
|
|
|
173
175
|
private startParse(opts: BaseOpts) {
|
|
174
176
|
const pending = this._parse(opts)
|
|
175
|
-
this.
|
|
176
|
-
this.
|
|
177
|
+
this.parseP = pending
|
|
178
|
+
this.parseSignal = opts.signal
|
|
177
179
|
// Drop a rejection rather than keeping it, so one transient failure does not
|
|
178
180
|
// poison the index for the lifetime of the file. Both branches are
|
|
179
181
|
// identity-checked so a retry started after this settles is not cleared by
|
|
180
182
|
// the attempt it already replaced.
|
|
181
183
|
pending.then(
|
|
182
184
|
() => {
|
|
183
|
-
if (this.
|
|
184
|
-
this.
|
|
185
|
+
if (this.parseP === pending) {
|
|
186
|
+
this.parseSignal = undefined
|
|
185
187
|
}
|
|
186
188
|
},
|
|
187
189
|
() => {
|
|
188
|
-
if (this.
|
|
189
|
-
this.
|
|
190
|
-
this.
|
|
190
|
+
if (this.parseP === pending) {
|
|
191
|
+
this.parseP = undefined
|
|
192
|
+
this.parseSignal = undefined
|
|
191
193
|
}
|
|
192
194
|
},
|
|
193
195
|
)
|
package/src/util.ts
CHANGED
|
@@ -39,33 +39,10 @@ export interface BaseOpts {
|
|
|
39
39
|
* underneath you. (The Chunk objects themselves are never mutated; a merged
|
|
40
40
|
* span produces a new instance.)
|
|
41
41
|
*/
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
* `AbortSignal`, and callers pass duck-typed ones — `test/csi.test.ts` casts a
|
|
47
|
-
* bare `{ aborted }` through `as AbortSignal`, which is a fair model of what
|
|
48
|
-
* consumers do; calling a missing method there is a `TypeError` rather than the
|
|
49
|
-
* cancellation the caller asked for, which is a strictly worse failure.
|
|
50
|
-
*
|
|
51
|
-
* And it sets a browser floor. `AbortSignal.prototype.throwIfAborted` and
|
|
52
|
-
* `AbortSignal.reason` are Safari 15.4 / Chrome 100 / Firefox 97 (March 2022) —
|
|
53
|
-
* higher than anything else in this dependency tree needs, since
|
|
54
|
-
* `generic-filehandle2` only ever forwards a signal to `fetch`, and higher than
|
|
55
|
-
* every sibling gmod library, which use plain `.aborted`. Three lines here
|
|
56
|
-
* keeps that floor where it was.
|
|
57
|
-
*
|
|
58
|
-
* Faithful to the spec otherwise: an aborted signal throws its `reason`
|
|
59
|
-
* whatever that is, and only synthesizes an `AbortError` when there is none.
|
|
60
|
-
*/
|
|
61
|
-
export function throwIfAborted(signal?: AbortSignal) {
|
|
62
|
-
if (signal?.aborted) {
|
|
63
|
-
const { reason } = signal
|
|
64
|
-
throw reason === undefined
|
|
65
|
-
? new DOMException('This operation was aborted', 'AbortError')
|
|
66
|
-
: reason
|
|
67
|
-
}
|
|
68
|
-
}
|
|
42
|
+
// Re-exported so the internal import path stays './util.ts'. The
|
|
43
|
+
// implementation moved to @gmod/shared-read-cache, which needs it anyway --
|
|
44
|
+
// every consumer of that package was carrying an identical copy.
|
|
45
|
+
export { throwIfAborted } from '@gmod/shared-read-cache'
|
|
69
46
|
|
|
70
47
|
export function optimizeChunks(chunks: Chunk[], lowest?: OffsetCoords) {
|
|
71
48
|
const n = chunks.length
|