@gmod/tabix 1.5.0 → 1.5.1

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/esm/util.d.ts ADDED
@@ -0,0 +1,25 @@
1
+ /// <reference types="long" />
2
+ import Chunk from './chunk';
3
+ import VirtualOffset from './virtualOffset';
4
+ export declare function longToNumber(long: Long): number;
5
+ /**
6
+ * Properly check if the given AbortSignal is aborted.
7
+ * Per the standard, if the signal reads as aborted,
8
+ * this function throws either a DOMException AbortError, or a regular error
9
+ * with a `code` attribute set to `ERR_ABORTED`.
10
+ *
11
+ * For convenience, passing `undefined` is a no-op
12
+ *
13
+ * @param {AbortSignal} [signal] an AbortSignal, or anything with an `aborted` attribute
14
+ * @returns nothing
15
+ */
16
+ export declare function checkAbortSignal(signal?: AbortSignal): void;
17
+ /**
18
+ * Skips to the next tick, then runs `checkAbortSignal`.
19
+ * Await this to inside an otherwise synchronous loop to
20
+ * provide a place to break when an abort signal is received.
21
+ * @param {AbortSignal} signal
22
+ */
23
+ export declare function abortBreakPoint(signal?: AbortSignal): Promise<void>;
24
+ export declare function canMergeBlocks(chunk1: Chunk, chunk2: Chunk): boolean;
25
+ export declare function optimizeChunks(chunks: Chunk[], lowest: VirtualOffset): Chunk[];
package/esm/util.js ADDED
@@ -0,0 +1,98 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.optimizeChunks = exports.canMergeBlocks = exports.abortBreakPoint = exports.checkAbortSignal = exports.longToNumber = void 0;
4
+ function longToNumber(long) {
5
+ if (long.greaterThan(Number.MAX_SAFE_INTEGER) ||
6
+ long.lessThan(Number.MIN_SAFE_INTEGER)) {
7
+ throw new Error('integer overflow');
8
+ }
9
+ return long.toNumber();
10
+ }
11
+ exports.longToNumber = longToNumber;
12
+ class AbortError extends Error {
13
+ }
14
+ /**
15
+ * Properly check if the given AbortSignal is aborted.
16
+ * Per the standard, if the signal reads as aborted,
17
+ * this function throws either a DOMException AbortError, or a regular error
18
+ * with a `code` attribute set to `ERR_ABORTED`.
19
+ *
20
+ * For convenience, passing `undefined` is a no-op
21
+ *
22
+ * @param {AbortSignal} [signal] an AbortSignal, or anything with an `aborted` attribute
23
+ * @returns nothing
24
+ */
25
+ function checkAbortSignal(signal) {
26
+ if (!signal) {
27
+ return;
28
+ }
29
+ if (signal.aborted) {
30
+ // console.log('bam aborted!')
31
+ if (typeof DOMException !== 'undefined') {
32
+ // eslint-disable-next-line no-undef
33
+ throw new DOMException('aborted', 'AbortError');
34
+ }
35
+ else {
36
+ const e = new AbortError('aborted');
37
+ e.code = 'ERR_ABORTED';
38
+ throw e;
39
+ }
40
+ }
41
+ }
42
+ exports.checkAbortSignal = checkAbortSignal;
43
+ /**
44
+ * Skips to the next tick, then runs `checkAbortSignal`.
45
+ * Await this to inside an otherwise synchronous loop to
46
+ * provide a place to break when an abort signal is received.
47
+ * @param {AbortSignal} signal
48
+ */
49
+ async function abortBreakPoint(signal) {
50
+ await Promise.resolve();
51
+ checkAbortSignal(signal);
52
+ }
53
+ exports.abortBreakPoint = abortBreakPoint;
54
+ function canMergeBlocks(chunk1, chunk2) {
55
+ return (chunk2.minv.blockPosition - chunk1.maxv.blockPosition < 65000 &&
56
+ chunk2.maxv.blockPosition - chunk1.minv.blockPosition < 5000000);
57
+ }
58
+ exports.canMergeBlocks = canMergeBlocks;
59
+ function optimizeChunks(chunks, lowest) {
60
+ const mergedChunks = [];
61
+ let lastChunk = null;
62
+ if (chunks.length === 0) {
63
+ return chunks;
64
+ }
65
+ chunks.sort(function (c0, c1) {
66
+ const dif = c0.minv.blockPosition - c1.minv.blockPosition;
67
+ if (dif !== 0) {
68
+ return dif;
69
+ }
70
+ else {
71
+ return c0.minv.dataPosition - c1.minv.dataPosition;
72
+ }
73
+ });
74
+ chunks.forEach(chunk => {
75
+ if (!lowest || chunk.maxv.compareTo(lowest) > 0) {
76
+ if (lastChunk === null) {
77
+ mergedChunks.push(chunk);
78
+ lastChunk = chunk;
79
+ }
80
+ else {
81
+ if (canMergeBlocks(lastChunk, chunk)) {
82
+ if (chunk.maxv.compareTo(lastChunk.maxv) > 0) {
83
+ lastChunk.maxv = chunk.maxv;
84
+ }
85
+ }
86
+ else {
87
+ mergedChunks.push(chunk);
88
+ lastChunk = chunk;
89
+ }
90
+ }
91
+ }
92
+ // else {
93
+ // console.log(`skipping chunk ${chunk}`)
94
+ // }
95
+ });
96
+ return mergedChunks;
97
+ }
98
+ exports.optimizeChunks = optimizeChunks;
@@ -0,0 +1,10 @@
1
+ /// <reference types="node" />
2
+ export default class VirtualOffset {
3
+ blockPosition: number;
4
+ dataPosition: number;
5
+ constructor(blockPosition: number, dataPosition: number);
6
+ toString(): string;
7
+ compareTo(b: VirtualOffset): number;
8
+ static min(...args: VirtualOffset[]): VirtualOffset;
9
+ }
10
+ export declare function fromBytes(bytes: Buffer, offset?: number, bigendian?: boolean): VirtualOffset;
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.fromBytes = void 0;
4
+ class VirtualOffset {
5
+ constructor(blockPosition, dataPosition) {
6
+ this.blockPosition = blockPosition; // < offset of the compressed data block
7
+ this.dataPosition = dataPosition; // < offset into the uncompressed data
8
+ }
9
+ toString() {
10
+ return `${this.blockPosition}:${this.dataPosition}`;
11
+ }
12
+ compareTo(b) {
13
+ return (this.blockPosition - b.blockPosition || this.dataPosition - b.dataPosition);
14
+ }
15
+ static min(...args) {
16
+ let min;
17
+ let i = 0;
18
+ for (; !min; i += 1) {
19
+ min = args[i];
20
+ }
21
+ for (; i < args.length; i += 1) {
22
+ if (min.compareTo(args[i]) > 0) {
23
+ min = args[i];
24
+ }
25
+ }
26
+ return min;
27
+ }
28
+ }
29
+ exports.default = VirtualOffset;
30
+ function fromBytes(bytes, offset = 0, bigendian = false) {
31
+ if (bigendian) {
32
+ throw new Error('big-endian virtual file offsets not implemented');
33
+ }
34
+ return new VirtualOffset(bytes[offset + 7] * 0x10000000000 +
35
+ bytes[offset + 6] * 0x100000000 +
36
+ bytes[offset + 5] * 0x1000000 +
37
+ bytes[offset + 4] * 0x10000 +
38
+ bytes[offset + 3] * 0x100 +
39
+ bytes[offset + 2], (bytes[offset + 1] << 8) | bytes[offset]);
40
+ }
41
+ exports.fromBytes = fromBytes;
package/package.json CHANGED
@@ -1,10 +1,11 @@
1
1
  {
2
2
  "name": "@gmod/tabix",
3
- "version": "1.5.0",
3
+ "version": "1.5.1",
4
4
  "description": "Read Tabix-indexed files, supports both .tbi and .csi indexes",
5
5
  "license": "MIT",
6
6
  "repository": "GMOD/tabix-js",
7
7
  "main": "dist/index.js",
8
+ "module": "esm/index.js",
8
9
  "author": {
9
10
  "name": "Robert Buels",
10
11
  "email": "rbuels@gmail.com",
@@ -14,30 +15,22 @@
14
15
  "node": ">=6"
15
16
  },
16
17
  "files": [
17
- "dist"
18
+ "dist",
19
+ "esm"
18
20
  ],
19
21
  "scripts": {
20
22
  "test": "jest",
21
23
  "coverage": "npm test -- --coverage",
22
24
  "lint": "eslint --ext .js,.ts src test",
23
- "clean": "rimraf dist",
25
+ "clean": "rimraf dist esm",
24
26
  "prebuild": "npm run clean && npm run lint",
25
- "build:types": "tsc --emitDeclarationOnly",
26
- "build:js": "babel src --out-dir dist --extensions \".ts,.tsx\" --source-maps inline",
27
- "build": "npm run build:types && npm run build:js",
27
+ "build:esm": "tsc --target es2018 --outDir esm",
28
+ "build:es5": "tsc --target es5 --outDir dist",
29
+ "build": "npm run build:esm && npm run build:es5",
28
30
  "preversion": "npm run lint && npm test && npm run build",
29
- "watch": "npm-watch",
30
31
  "prepublishOnly": "npm run lint && npm test && npm run build",
31
- "postpublish": "git push origin master --follow-tags",
32
- "version": "standard-changelog && git add CHANGELOG.md"
33
- },
34
- "watch": {
35
- "test": "{src,test}/*.js",
36
- "lint": "{src,test}/*.js",
37
- "build": "src"
38
- },
39
- "jest": {
40
- "testEnvironment": "node"
32
+ "version": "standard-changelog && git add CHANGELOG.md",
33
+ "postversion": "git push --follow-tags"
41
34
  },
42
35
  "keywords": [
43
36
  "bionode",
@@ -45,41 +38,31 @@
45
38
  "genomics"
46
39
  ],
47
40
  "dependencies": {
48
- "@babel/runtime-corejs2": "^7.3.1",
49
41
  "@gmod/bgzf-filehandle": "^1.3.3",
50
- "abortable-promise-cache": "^1.0.1",
42
+ "abortable-promise-cache": "^1.4.1",
51
43
  "es6-promisify": "^6.0.1",
52
44
  "generic-filehandle": "^2.0.1",
53
45
  "long": "^4.0.0",
54
- "quick-lru": "^2.0.0"
46
+ "quick-lru": "^4.0.0"
55
47
  },
56
48
  "devDependencies": {
57
- "@babel/cli": "^7.2.3",
58
- "@babel/core": "^7.3.3",
59
- "@babel/plugin-transform-runtime": "^7.2.0",
60
- "@babel/preset-env": "^7.3.1",
61
- "@babel/preset-flow": "^7.0.0",
62
- "@babel/preset-typescript": "^7.6.0",
49
+ "@types/jest": "^27.0.3",
63
50
  "@types/long": "^4.0.0",
64
51
  "@types/node": "^12.7.11",
65
52
  "@types/quick-lru": "2.0.0",
66
- "@typescript-eslint/eslint-plugin": "^2.3.3",
67
- "@typescript-eslint/parser": "^2.3.3",
68
- "babel-eslint": "^10.0.1",
69
- "babel-jest": "^24.1.0",
53
+ "@typescript-eslint/eslint-plugin": "^5.7.0",
54
+ "@typescript-eslint/parser": "^5.7.0",
70
55
  "documentation": "^9.1.1",
71
- "eslint": "^5.12.0",
72
- "eslint-config-airbnb-base": "^13.1.0",
73
- "eslint-config-prettier": "^5.0.0",
74
- "eslint-plugin-import": "^2.10.0",
75
- "eslint-plugin-jest": "^22.17.0",
76
- "eslint-plugin-prettier": "^3.0.1",
77
- "jest": "^24.1.0",
78
- "npm-watch": "^0.5.0",
79
- "prettier": "^1.11.1",
56
+ "eslint": "^7.0.0",
57
+ "eslint-config-prettier": "^8.3.0",
58
+ "eslint-plugin-import": "^2.25.3",
59
+ "eslint-plugin-prettier": "^4.0.0",
60
+ "jest": "^27.4.3",
61
+ "prettier": "^2.5.1",
80
62
  "rimraf": "^2.6.2",
81
63
  "standard-changelog": "^1.0.0",
82
- "typescript": "^3.6.3"
64
+ "ts-jest": "^27.0.7",
65
+ "typescript": "^4.5.2"
83
66
  },
84
67
  "publishConfig": {
85
68
  "access": "public"
package/dist/declare.d.js DELETED
@@ -1,2 +0,0 @@
1
- "use strict";
2
- //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IiIsInNvdXJjZXNDb250ZW50IjpbXX0=