@gmod/bam 7.1.19 → 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.
Files changed (66) hide show
  1. package/README.md +22 -13
  2. package/dist/bai.d.ts +2 -2
  3. package/dist/bai.js +1 -0
  4. package/dist/bai.js.map +1 -1
  5. package/dist/bamFile.d.ts +2 -1
  6. package/dist/bamFile.js +15 -6
  7. package/dist/bamFile.js.map +1 -1
  8. package/dist/chunk.d.ts +1 -1
  9. package/dist/chunk.js +5 -0
  10. package/dist/chunk.js.map +1 -1
  11. package/dist/csi.js +4 -6
  12. package/dist/csi.js.map +1 -1
  13. package/dist/htsget.d.ts +1 -1
  14. package/dist/htsget.js +15 -9
  15. package/dist/htsget.js.map +1 -1
  16. package/dist/indexFile.d.ts +2 -2
  17. package/dist/indexFile.js +2 -0
  18. package/dist/indexFile.js.map +1 -1
  19. package/dist/nullFilehandle.d.ts +4 -4
  20. package/dist/nullIndex.d.ts +4 -4
  21. package/dist/record.d.ts +11 -14
  22. package/dist/record.js +119 -117
  23. package/dist/record.js.map +1 -1
  24. package/dist/util.d.ts +2 -2
  25. package/dist/util.js +4 -7
  26. package/dist/util.js.map +1 -1
  27. package/dist/virtualOffset.js +2 -0
  28. package/dist/virtualOffset.js.map +1 -1
  29. package/esm/bai.d.ts +2 -2
  30. package/esm/bai.js +2 -1
  31. package/esm/bai.js.map +1 -1
  32. package/esm/bamFile.d.ts +2 -1
  33. package/esm/bamFile.js +15 -6
  34. package/esm/bamFile.js.map +1 -1
  35. package/esm/chunk.d.ts +1 -1
  36. package/esm/chunk.js +5 -0
  37. package/esm/chunk.js.map +1 -1
  38. package/esm/csi.js +4 -6
  39. package/esm/csi.js.map +1 -1
  40. package/esm/htsget.d.ts +1 -1
  41. package/esm/htsget.js +12 -9
  42. package/esm/htsget.js.map +1 -1
  43. package/esm/indexFile.d.ts +2 -2
  44. package/esm/indexFile.js +2 -0
  45. package/esm/indexFile.js.map +1 -1
  46. package/esm/nullFilehandle.d.ts +4 -4
  47. package/esm/nullIndex.d.ts +4 -4
  48. package/esm/record.d.ts +11 -14
  49. package/esm/record.js +119 -117
  50. package/esm/record.js.map +1 -1
  51. package/esm/util.d.ts +2 -2
  52. package/esm/util.js +4 -7
  53. package/esm/util.js.map +1 -1
  54. package/esm/virtualOffset.js +2 -0
  55. package/esm/virtualOffset.js.map +1 -1
  56. package/package.json +28 -32
  57. package/src/bai.ts +5 -7
  58. package/src/bamFile.ts +3 -1
  59. package/src/chunk.ts +1 -1
  60. package/src/htsget.ts +18 -14
  61. package/src/indexFile.ts +3 -2
  62. package/src/nullFilehandle.ts +4 -4
  63. package/src/nullIndex.ts +4 -4
  64. package/src/record.ts +137 -140
  65. package/src/util.ts +11 -11
  66. package/CHANGELOG.md +0 -530
package/package.json CHANGED
@@ -1,27 +1,23 @@
1
1
  {
2
2
  "name": "@gmod/bam",
3
- "version": "7.1.19",
3
+ "version": "7.1.21",
4
4
  "description": "Parser for BAM and BAM index (bai) files",
5
5
  "license": "MIT",
6
- "repository": "GMOD/bam-js",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/GMOD/bam-js.git"
9
+ },
7
10
  "type": "module",
8
- "types": "./dist/index.d.ts",
11
+ "main": "dist/index.js",
9
12
  "exports": {
10
- "import": {
11
- "import": "./esm/index.js"
12
- },
13
- "require": {
14
- "require": "./dist/index.js"
15
- }
13
+ "import": "./esm/index.js",
14
+ "require": "./dist/index.js"
16
15
  },
17
16
  "author": {
18
17
  "name": "Colin Diesh",
19
18
  "email": "colin.diesh@gmail.com",
20
19
  "url": "https://github.com/cmdcolin"
21
20
  },
22
- "engines": {
23
- "node": ">=6"
24
- },
25
21
  "files": [
26
22
  "dist",
27
23
  "esm",
@@ -29,19 +25,19 @@
29
25
  ],
30
26
  "scripts": {
31
27
  "test": "vitest",
32
- "benchonly": "vitest bench",
33
- "bench": "./scripts/build-both-branches.sh \"$BRANCH1\" \"$BRANCH2\" && vitest bench",
34
- "lint": "eslint --report-unused-disable-directives --max-warnings 0",
35
28
  "clean": "rimraf dist esm",
36
29
  "format": "prettier --write .",
30
+ "lint": "eslint --report-unused-disable-directives --max-warnings 0",
31
+ "prebuild": "pnpm clean",
37
32
  "build:esm": "tsc --outDir esm",
38
- "build:es5": "tsc --module commonjs --outDir dist",
39
- "build": "yarn build:esm && yarn build:es5",
40
- "prebuild": "yarn clean",
33
+ "build:es5": "tsc --module commonjs --moduleResolution bundler --outDir dist",
41
34
  "postbuild:es5": "echo '{\"type\": \"commonjs\"}' > dist/package.json",
42
- "preversion": "yarn lint && yarn test --run && yarn build",
43
- "version": "standard-changelog && git add CHANGELOG.md",
44
- "postversion": "git push --follow-tags"
35
+ "preversion": "pnpm lint && pnpm test --run && pnpm build",
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"
45
41
  },
46
42
  "keywords": [
47
43
  "bionode",
@@ -50,24 +46,24 @@
50
46
  "genomics"
51
47
  ],
52
48
  "dependencies": {
53
- "@gmod/bgzf-filehandle": "^6.0.12",
49
+ "@gmod/bgzf-filehandle": "^6.0.18",
54
50
  "@jbrowse/quick-lru": "^7.3.5",
55
51
  "crc": "^4.3.2",
56
- "generic-filehandle2": "^2.0.18"
52
+ "generic-filehandle2": "^2.1.4"
57
53
  },
58
54
  "devDependencies": {
59
55
  "@eslint/js": "^10.0.1",
60
- "@types/node": "^25.3.3",
61
- "@vitest/coverage-v8": "^4.0.18",
62
- "eslint": "^10.0.2",
63
- "eslint-plugin-import": "^2.31.0",
64
- "eslint-plugin-unicorn": "^63.0.0",
65
- "prettier": "^3.8.1",
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",
60
+ "eslint-plugin-unicorn": "^64.0.0",
61
+ "prettier": "^3.8.3",
66
62
  "rimraf": "^6.1.3",
67
63
  "standard-changelog": "^7.0.1",
68
- "typescript": "^5.0.4",
69
- "typescript-eslint": "^8.56.1",
70
- "vitest": "^4.0.18"
64
+ "typescript": "^6.0.3",
65
+ "typescript-eslint": "^8.59.0",
66
+ "vitest": "^4.1.5"
71
67
  },
72
68
  "publishConfig": {
73
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 {
@@ -1,16 +1,16 @@
1
1
  export default class NullFilehandle {
2
- public read(): Promise<any> {
2
+ public read(): Promise<never> {
3
3
  throw new Error('never called')
4
4
  }
5
- public stat(): Promise<any> {
5
+ public stat(): Promise<never> {
6
6
  throw new Error('never called')
7
7
  }
8
8
 
9
- public readFile(): Promise<any> {
9
+ public readFile(): Promise<never> {
10
10
  throw new Error('never called')
11
11
  }
12
12
 
13
- public close(): Promise<any> {
13
+ public close(): Promise<never> {
14
14
  throw new Error('never called')
15
15
  }
16
16
  }
package/src/nullIndex.ts CHANGED
@@ -1,18 +1,18 @@
1
1
  import IndexFile from './indexFile.ts'
2
2
 
3
3
  export default class NullIndex extends IndexFile {
4
- public lineCount(): Promise<any> {
4
+ public lineCount(): Promise<never> {
5
5
  throw new Error('never called')
6
6
  }
7
- protected _parse(): Promise<any> {
7
+ protected _parse(): Promise<never> {
8
8
  throw new Error('never called')
9
9
  }
10
10
 
11
- public async indexCov(): Promise<any> {
11
+ public async indexCov(): Promise<never> {
12
12
  throw new Error('never called')
13
13
  }
14
14
 
15
- public blocksForRange(): Promise<any> {
15
+ public blocksForRange(): Promise<never> {
16
16
  throw new Error('never called')
17
17
  }
18
18
  }