@gmod/bam 7.1.20 → 7.1.21

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gmod/bam",
3
- "version": "7.1.20",
3
+ "version": "7.1.21",
4
4
  "description": "Parser for BAM and BAM index (bai) files",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -8,21 +8,16 @@
8
8
  "url": "https://github.com/GMOD/bam-js.git"
9
9
  },
10
10
  "type": "module",
11
- "types": "./esm/index.d.ts",
11
+ "main": "dist/index.js",
12
12
  "exports": {
13
- ".": {
14
- "import": "./esm/index.js",
15
- "require": "./dist/index.js"
16
- }
13
+ "import": "./esm/index.js",
14
+ "require": "./dist/index.js"
17
15
  },
18
16
  "author": {
19
17
  "name": "Colin Diesh",
20
18
  "email": "colin.diesh@gmail.com",
21
19
  "url": "https://github.com/cmdcolin"
22
20
  },
23
- "engines": {
24
- "node": ">=20"
25
- },
26
21
  "files": [
27
22
  "dist",
28
23
  "esm",
@@ -30,19 +25,19 @@
30
25
  ],
31
26
  "scripts": {
32
27
  "test": "vitest",
33
- "benchonly": "vitest bench",
34
- "bench": "./scripts/build-both-branches.sh \"$BRANCH1\" \"$BRANCH2\" && vitest bench",
35
- "lint": "eslint --report-unused-disable-directives --max-warnings 0",
36
28
  "clean": "rimraf dist esm",
37
29
  "format": "prettier --write .",
30
+ "lint": "eslint --report-unused-disable-directives --max-warnings 0",
31
+ "prebuild": "pnpm clean",
38
32
  "build:esm": "tsc --outDir esm",
39
33
  "build:es5": "tsc --module commonjs --moduleResolution bundler --outDir dist",
40
- "build": "pnpm build:esm && pnpm build:es5",
41
- "prebuild": "pnpm clean",
42
34
  "postbuild:es5": "echo '{\"type\": \"commonjs\"}' > dist/package.json",
43
35
  "preversion": "pnpm lint && pnpm test --run && pnpm build",
44
- "version": "standard-changelog && git add CHANGELOG.md",
45
- "postversion": "git push --follow-tags"
36
+ "postversion": "git push --follow-tags",
37
+ "build": "pnpm build:esm && pnpm build:es5",
38
+ "benchonly": "vitest bench",
39
+ "bench": "./scripts/build-both-branches.sh \"$BRANCH1\" \"$BRANCH2\" && vitest bench",
40
+ "version": "standard-changelog && git add CHANGELOG.md"
46
41
  },
47
42
  "keywords": [
48
43
  "bionode",
@@ -51,24 +46,24 @@
51
46
  "genomics"
52
47
  ],
53
48
  "dependencies": {
54
- "@gmod/bgzf-filehandle": "^6.0.12",
49
+ "@gmod/bgzf-filehandle": "^6.0.18",
55
50
  "@jbrowse/quick-lru": "^7.3.5",
56
51
  "crc": "^4.3.2",
57
52
  "generic-filehandle2": "^2.1.4"
58
53
  },
59
54
  "devDependencies": {
60
55
  "@eslint/js": "^10.0.1",
61
- "@types/node": "^25.5.0",
62
- "@vitest/coverage-v8": "^4.1.2",
63
- "eslint": "^9.39.4",
64
- "eslint-plugin-import": "^2.32.0",
56
+ "@types/node": "^25.6.0",
57
+ "@vitest/coverage-v8": "^4.1.5",
58
+ "eslint": "^10.2.1",
59
+ "eslint-plugin-import-x": "^4.16.2",
65
60
  "eslint-plugin-unicorn": "^64.0.0",
66
- "prettier": "^3.8.1",
61
+ "prettier": "^3.8.3",
67
62
  "rimraf": "^6.1.3",
68
63
  "standard-changelog": "^7.0.1",
69
- "typescript": "^6.0.2",
70
- "typescript-eslint": "^8.57.2",
71
- "vitest": "^4.1.2"
64
+ "typescript": "^6.0.3",
65
+ "typescript-eslint": "^8.59.0",
66
+ "vitest": "^4.1.5"
72
67
  },
73
68
  "publishConfig": {
74
69
  "access": "public"
package/src/bai.ts CHANGED
@@ -2,13 +2,11 @@ import QuickLRU from '@jbrowse/quick-lru'
2
2
 
3
3
  import Chunk from './chunk.ts'
4
4
  import IndexFile from './indexFile.ts'
5
- import {
6
- BaseOpts,
7
- findFirstData,
8
- optimizeChunks,
9
- parsePseudoBin,
10
- } from './util.ts'
11
- import { VirtualOffset, fromBytes } from './virtualOffset.ts'
5
+ import { findFirstData, optimizeChunks, parsePseudoBin } from './util.ts'
6
+ import { fromBytes } from './virtualOffset.ts'
7
+
8
+ import type { BaseOpts } from './util.ts'
9
+ import type { VirtualOffset } from './virtualOffset.ts'
12
10
 
13
11
  const BAI_MAGIC = 21578050 // BAI\1
14
12
 
package/src/bamFile.ts CHANGED
@@ -4,7 +4,6 @@ import crc32 from 'crc/calculators/crc32'
4
4
  import { LocalFile, RemoteFile } from 'generic-filehandle2'
5
5
 
6
6
  import BAI from './bai.ts'
7
- import Chunk from './chunk.ts'
8
7
  import CSI from './csi.ts'
9
8
  import NullFilehandle from './nullFilehandle.ts'
10
9
  import BAMFeature from './record.ts'
@@ -16,6 +15,7 @@ import {
16
15
  makeOpts,
17
16
  } from './util.ts'
18
17
 
18
+ import type Chunk from './chunk.ts'
19
19
  import type { Bytes } from './record.ts'
20
20
  import type { BamOpts, BaseOpts, FilterBy } from './util.ts'
21
21
  import type { GenericFilehandle } from 'generic-filehandle2'
@@ -35,6 +35,7 @@ export interface BamRecordLike {
35
35
  export type BamRecordClass<T extends BamRecordLike = BAMFeature> = new (args: {
36
36
  bytes: Bytes
37
37
  fileOffset: number
38
+ dataView: DataView
38
39
  }) => T
39
40
 
40
41
  export const BAM_MAGIC = 21840194
@@ -501,6 +502,7 @@ export default class BamFile<T extends BamRecordLike = BAMFeature> {
501
502
  chunk.minv.dataPosition +
502
503
  1
503
504
  : crc32(ba.subarray(blockStart, blockEnd)) >>> 0,
505
+ dataView,
504
506
  })
505
507
 
506
508
  sink.push(feature)
package/src/chunk.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Offset } from './virtualOffset.ts'
1
+ import type { Offset } from './virtualOffset.ts'
2
2
 
3
3
  // little class representing a chunk in the index
4
4
  export default class Chunk {
package/src/htsget.ts CHANGED
@@ -2,11 +2,12 @@ import { unzip } from '@gmod/bgzf-filehandle'
2
2
 
3
3
  import BamFile, { BAM_MAGIC } from './bamFile.ts'
4
4
  import Chunk from './chunk.ts'
5
- import BamRecord from './record.ts'
6
5
  import { parseHeaderText } from './sam.ts'
7
6
  import { concatUint8Array } from './util.ts'
7
+ import { VirtualOffset } from './virtualOffset.ts'
8
8
 
9
9
  import type { BamRecordClass, BamRecordLike } from './bamFile.ts'
10
+ import type BamRecord from './record.ts'
10
11
  import type { BamOpts, BaseOpts } from './util.ts'
11
12
 
12
13
  interface HtsgetChunk {
@@ -14,7 +15,7 @@ interface HtsgetChunk {
14
15
  headers?: Record<string, string>
15
16
  }
16
17
 
17
- async function concat(arr: HtsgetChunk[], opts?: Record<string, any>) {
18
+ async function concat(arr: HtsgetChunk[], opts?: RequestInit) {
18
19
  const res = await Promise.all(
19
20
  arr.map(async chunk => {
20
21
  const { url, headers } = chunk
@@ -29,12 +30,10 @@ async function concat(arr: HtsgetChunk[], opts?: Record<string, any>) {
29
30
  return new Uint8Array(ret)
30
31
  } else {
31
32
  // remove referer header, it is not even allowed to be specified
32
- // @ts-expect-error
33
-
34
- const { referer, ...rest } = headers
33
+ const { referer: _referer, ...rest } = headers ?? {}
35
34
  const res = await fetch(url, {
36
35
  ...opts,
37
- headers: { ...opts?.headers, ...rest },
36
+ headers: rest,
38
37
  })
39
38
  if (!res.ok) {
40
39
  throw new Error(
@@ -85,12 +84,17 @@ export default class HtsgetFile<
85
84
  )
86
85
  }
87
86
  const data = await result.json()
88
- const uncba = await concat(data.htsget.urls.slice(1), opts)
89
-
90
- const allRecords = await this.readBamFeatures(uncba, [], [], {
91
- minv: { dataPosition: 0, blockPosition: 0 },
92
- maxv: { dataPosition: 0, blockPosition: 0 },
93
- } as Chunk)
87
+ const uncba = await concat(data.htsget.urls.slice(1), {
88
+ signal: opts?.signal,
89
+ })
90
+
91
+ const zero = new VirtualOffset(0, 0)
92
+ const allRecords = await this.readBamFeatures(
93
+ uncba,
94
+ [],
95
+ [],
96
+ new Chunk(zero, zero, 0),
97
+ )
94
98
 
95
99
  const records: T[] = []
96
100
  for (let i = 0, l = allRecords.length; i < l; i++) {
@@ -115,7 +119,7 @@ export default class HtsgetFile<
115
119
  )
116
120
  }
117
121
  const data = await result.json()
118
- const uncba = await concat(data.htsget.urls, opts)
122
+ const uncba = await concat(data.htsget.urls, { signal: opts.signal })
119
123
  const dataView = new DataView(uncba.buffer)
120
124
 
121
125
  if (dataView.getInt32(0, true) !== BAM_MAGIC) {
@@ -123,7 +127,7 @@ export default class HtsgetFile<
123
127
  }
124
128
  const headLen = dataView.getInt32(4, true)
125
129
 
126
- const decoder = new TextDecoder('utf8')
130
+ const decoder = new TextDecoder()
127
131
  const headerText = decoder.decode(uncba.subarray(8, 8 + headLen))
128
132
  const samHeader = parseHeaderText(headerText)
129
133
 
package/src/indexFile.ts CHANGED
@@ -1,6 +1,7 @@
1
- import Chunk from './chunk.ts'
2
- import { BaseOpts, optimizeChunks } from './util.ts'
1
+ import { optimizeChunks } from './util.ts'
3
2
 
3
+ import type Chunk from './chunk.ts'
4
+ import type { BaseOpts } from './util.ts'
4
5
  import type { GenericFilehandle } from 'generic-filehandle2'
5
6
 
6
7
  export interface Region {