@gmod/trix 3.0.1 → 3.0.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/README.md +2 -3
- package/dist/dedupe.d.ts +3 -0
- package/dist/dedupe.js +17 -0
- package/dist/dedupe.js.map +1 -0
- package/dist/index.js +4 -11
- package/dist/index.js.map +1 -1
- package/dist/package.json +1 -0
- package/esm/dedupe.d.ts +3 -0
- package/esm/dedupe.js +14 -0
- package/esm/dedupe.js.map +1 -0
- package/esm/index.js +4 -11
- package/esm/index.js.map +1 -1
- package/package.json +5 -3
- package/src/dedupe.ts +18 -0
- package/src/index.ts +6 -13
package/README.md
CHANGED
|
@@ -8,10 +8,9 @@ Read UCSC Trix indexes in pure JavaScript
|
|
|
8
8
|
|
|
9
9
|
```js
|
|
10
10
|
import Trix from '@gmod/trix'
|
|
11
|
-
import { RemoteFile } from 'generic-
|
|
11
|
+
import { RemoteFile } from 'generic-filehandle2'
|
|
12
12
|
|
|
13
|
-
//
|
|
14
|
-
// We use generic-filehandle here to demonstrate searching files on remote servers.
|
|
13
|
+
// We use generic-filehandle2 here to demonstrate searching files on remote servers.
|
|
15
14
|
const ixxFile = new RemoteFile(
|
|
16
15
|
'https://hgdownload.soe.ucsc.edu/gbdb/hg38/knownGene.ixx',
|
|
17
16
|
)
|
package/dist/dedupe.d.ts
ADDED
package/dist/dedupe.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.dedupe = dedupe;
|
|
4
|
+
// from https://github.com/seriousManual/dedupe/blob/master/LICENSE
|
|
5
|
+
function dedupe(list, hasher = JSON.stringify) {
|
|
6
|
+
const clone = [];
|
|
7
|
+
const lookup = new Set();
|
|
8
|
+
for (const entry of list) {
|
|
9
|
+
const hashed = hasher(entry);
|
|
10
|
+
if (!lookup.has(hashed)) {
|
|
11
|
+
clone.push(entry);
|
|
12
|
+
lookup.add(hashed);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
return clone;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=dedupe.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dedupe.js","sourceRoot":"","sources":["../src/dedupe.ts"],"names":[],"mappings":";;AAGA,wBAcC;AAfD,mEAAmE;AACnE,SAAgB,MAAM,CAAI,IAAS,EAAE,SAAoB,IAAI,CAAC,SAAS;IACrE,MAAM,KAAK,GAAQ,EAAE,CAAA;IACrB,MAAM,MAAM,GAAG,IAAI,GAAG,EAAU,CAAA;IAEhC,KAAK,MAAM,KAAK,IAAI,IAAI,EAAE,CAAC;QACzB,MAAM,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,CAAA;QAE5B,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC;YACxB,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;YACjB,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,CAAA;QACpB,CAAC;IACH,CAAC;IAED,OAAO,KAAK,CAAA;AACd,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -9,19 +9,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const dedupe_1 = require("./dedupe");
|
|
12
13
|
const util_1 = require("./util");
|
|
13
14
|
const CHUNK_SIZE = 65536;
|
|
14
15
|
// this is the number of hex characters to use for the address in ixixx, see
|
|
15
16
|
// https://github.com/GMOD/ixixx-js/blob/master/src/index.ts#L182
|
|
16
17
|
const ADDRESS_SIZE = 10;
|
|
17
|
-
// https://stackoverflow.com/a/9229821/2129219
|
|
18
|
-
function uniqBy(a, key) {
|
|
19
|
-
const seen = new Set();
|
|
20
|
-
return a.filter(item => {
|
|
21
|
-
const k = key(item);
|
|
22
|
-
return seen.has(k) ? false : seen.add(k);
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
18
|
class Trix {
|
|
26
19
|
constructor(ixxFile, ixFile, maxResults = 20) {
|
|
27
20
|
this.ixxFile = ixxFile;
|
|
@@ -41,10 +34,10 @@ class Trix {
|
|
|
41
34
|
let { end, buffer } = res;
|
|
42
35
|
let done = false;
|
|
43
36
|
const decoder = new TextDecoder('utf8');
|
|
44
|
-
const str = decoder.decode(buffer);
|
|
45
37
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
46
38
|
while (!done) {
|
|
47
39
|
let foundSomething = false;
|
|
40
|
+
const str = decoder.decode(buffer);
|
|
48
41
|
// slice to lastIndexOf('\n') to make sure we get complete records
|
|
49
42
|
// since the buffer fetch could get halfway into a record
|
|
50
43
|
const lines = str
|
|
@@ -90,8 +83,8 @@ class Trix {
|
|
|
90
83
|
break;
|
|
91
84
|
}
|
|
92
85
|
}
|
|
93
|
-
//
|
|
94
|
-
return
|
|
86
|
+
// de-duplicate results based on the detail column (resultArr[1])
|
|
87
|
+
return (0, dedupe_1.dedupe)(resultArr, elt => elt[1]).slice(0, this.maxResults);
|
|
95
88
|
});
|
|
96
89
|
}
|
|
97
90
|
getIndex(opts) {
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,qCAAiC;AACjC,iCAAyC;AAIzC,MAAM,UAAU,GAAG,KAAK,CAAA;AAExB,4EAA4E;AAC5E,iEAAiE;AACjE,MAAM,YAAY,GAAG,EAAE,CAAA;AAEvB,MAAqB,IAAI;IACvB,YACS,OAA0B,EAC1B,MAAyB,EACzB,aAAa,EAAE;QAFf,YAAO,GAAP,OAAO,CAAmB;QAC1B,WAAM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OAAO,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAA;YACzC,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,OAAO,EAAE,CAAC;gBACnC,MAAM,UAAU,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,UAAU,CAAC,MAAM,CAAC,CAAA;gBAClD,IAAI,UAAU,GAAG,UAAU,EAAE,CAAC;oBAC5B,KAAK,GAAG,KAAK,CAAA;oBACb,GAAG,GAAG,KAAK,GAAG,KAAK,CAAA;gBACrB,CAAC;YACH,CAAC;YAED,sDAAsD;YACtD,MAAM,GAAG,GAAG,GAAG,GAAG,KAAK,CAAA;YACvB,IAAI,GAAG,GAAG,CAAC,EAAE,CAAC;gBACZ,OAAO,SAAS,CAAA;YAClB,CAAC;YACD,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,KAAK,EAAE,IAAI,CAAC,CAAA;YACvD,OAAO;gBACL,MAAM;gBACN,GAAG;aACJ,CAAA;QACH,CAAC;KAAA;CACF;AA5HD,uBA4HC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type": "commonjs"}
|
package/esm/dedupe.d.ts
ADDED
package/esm/dedupe.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// from https://github.com/seriousManual/dedupe/blob/master/LICENSE
|
|
2
|
+
export function dedupe(list, hasher = JSON.stringify) {
|
|
3
|
+
const clone = [];
|
|
4
|
+
const lookup = new Set();
|
|
5
|
+
for (const entry of list) {
|
|
6
|
+
const hashed = hasher(entry);
|
|
7
|
+
if (!lookup.has(hashed)) {
|
|
8
|
+
clone.push(entry);
|
|
9
|
+
lookup.add(hashed);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
return clone;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=dedupe.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dedupe.js","sourceRoot":"","sources":["../src/dedupe.ts"],"names":[],"mappings":"AAEA,mEAAmE;AACnE,MAAM,UAAU,MAAM,CAAI,IAAS,EAAE,SAAoB,IAAI,CAAC,SAAS;IACrE,MAAM,KAAK,GAAQ,EAAE,CAAA;IACrB,MAAM,MAAM,GAAG,IAAI,GAAG,EAAU,CAAA;IAEhC,KAAK,MAAM,KAAK,IAAI,IAAI,EAAE,CAAC;QACzB,MAAM,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,CAAA;QAE5B,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC;YACxB,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;YACjB,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,CAAA;QACpB,CAAC;IACH,CAAC;IAED,OAAO,KAAK,CAAA;AACd,CAAC"}
|
package/esm/index.js
CHANGED
|
@@ -1,16 +1,9 @@
|
|
|
1
|
+
import { dedupe } from './dedupe';
|
|
1
2
|
import { concatUint8Array } from './util';
|
|
2
3
|
const CHUNK_SIZE = 65536;
|
|
3
4
|
// this is the number of hex characters to use for the address in ixixx, see
|
|
4
5
|
// https://github.com/GMOD/ixixx-js/blob/master/src/index.ts#L182
|
|
5
6
|
const ADDRESS_SIZE = 10;
|
|
6
|
-
// https://stackoverflow.com/a/9229821/2129219
|
|
7
|
-
function uniqBy(a, key) {
|
|
8
|
-
const seen = new Set();
|
|
9
|
-
return a.filter(item => {
|
|
10
|
-
const k = key(item);
|
|
11
|
-
return seen.has(k) ? false : seen.add(k);
|
|
12
|
-
});
|
|
13
|
-
}
|
|
14
7
|
export default class Trix {
|
|
15
8
|
ixxFile;
|
|
16
9
|
ixFile;
|
|
@@ -32,10 +25,10 @@ export default class Trix {
|
|
|
32
25
|
let { end, buffer } = res;
|
|
33
26
|
let done = false;
|
|
34
27
|
const decoder = new TextDecoder('utf8');
|
|
35
|
-
const str = decoder.decode(buffer);
|
|
36
28
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
37
29
|
while (!done) {
|
|
38
30
|
let foundSomething = false;
|
|
31
|
+
const str = decoder.decode(buffer);
|
|
39
32
|
// slice to lastIndexOf('\n') to make sure we get complete records
|
|
40
33
|
// since the buffer fetch could get halfway into a record
|
|
41
34
|
const lines = str
|
|
@@ -81,8 +74,8 @@ export default class Trix {
|
|
|
81
74
|
break;
|
|
82
75
|
}
|
|
83
76
|
}
|
|
84
|
-
//
|
|
85
|
-
return
|
|
77
|
+
// de-duplicate results based on the detail column (resultArr[1])
|
|
78
|
+
return dedupe(resultArr, elt => elt[1]).slice(0, this.maxResults);
|
|
86
79
|
}
|
|
87
80
|
async getIndex(opts) {
|
|
88
81
|
const file = await this.ixxFile.readFile({
|
package/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AACjC,OAAO,EAAE,gBAAgB,EAAE,MAAM,QAAQ,CAAA;AAIzC,MAAM,UAAU,GAAG,KAAK,CAAA;AAExB,4EAA4E;AAC5E,iEAAiE;AACjE,MAAM,YAAY,GAAG,EAAE,CAAA;AAEvB,MAAM,CAAC,OAAO,OAAO,IAAI;IAEd;IACA;IACA;IAHT,YACS,OAA0B,EAC1B,MAAyB,EACzB,aAAa,EAAE;QAFf,YAAO,GAAP,OAAO,CAAmB;QAC1B,WAAM,GAAN,MAAM,CAAmB;QACzB,eAAU,GAAV,UAAU,CAAK;IACrB,CAAC;IAEJ,KAAK,CAAC,MAAM,CAAC,YAAoB,EAAE,IAA+B;QAChE,IAAI,SAAS,GAAG,EAAwB,CAAA;QACxC,MAAM,WAAW,GAAG,YAAY,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;QAE3C,o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IAAI,UAAU,GAAG,UAAU,EAAE,CAAC;gBAC5B,KAAK,GAAG,KAAK,CAAA;gBACb,GAAG,GAAG,KAAK,GAAG,KAAK,CAAA;YACrB,CAAC;QACH,CAAC;QAED,sDAAsD;QACtD,MAAM,GAAG,GAAG,GAAG,GAAG,KAAK,CAAA;QACvB,IAAI,GAAG,GAAG,CAAC,EAAE,CAAC;YACZ,OAAO,SAAS,CAAA;QAClB,CAAC;QACD,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,KAAK,EAAE,IAAI,CAAC,CAAA;QACvD,OAAO;YACL,MAAM;YACN,GAAG;SACJ,CAAA;IACH,CAAC;CACF"}
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "3.0.
|
|
2
|
+
"version": "3.0.3",
|
|
3
3
|
"license": "Apache-2.0",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"module": "esm/index.js",
|
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
"build:es5": "tsc --target es2015 --outDir dist --module commonjs",
|
|
19
19
|
"build": "npm run build:esm && npm run build:es5",
|
|
20
20
|
"preversion": "npm run lint && npm test run && npm run build",
|
|
21
|
+
"postbuild:es5": "echo '{\"type\": \"commonjs\"}' > dist/package.json",
|
|
21
22
|
"postversion": "git push --follow-tags",
|
|
22
23
|
"test": "vitest"
|
|
23
24
|
},
|
|
@@ -29,13 +30,14 @@
|
|
|
29
30
|
"@typescript-eslint/eslint-plugin": "^8.4.0",
|
|
30
31
|
"@typescript-eslint/parser": "^8.4.0",
|
|
31
32
|
"eslint": "^9.0.0",
|
|
32
|
-
"eslint-plugin-
|
|
33
|
+
"eslint-plugin-import": "^2.31.0",
|
|
34
|
+
"eslint-plugin-unicorn": "^58.0.0",
|
|
33
35
|
"generic-filehandle2": "^1.0.0",
|
|
34
36
|
"prettier": "^3.3.3",
|
|
35
37
|
"rimraf": "^6.0.1",
|
|
36
38
|
"typescript": "^5.7.0",
|
|
37
39
|
"typescript-eslint": "^8.4.0",
|
|
38
|
-
"vitest": "^
|
|
40
|
+
"vitest": "^3.0.7"
|
|
39
41
|
},
|
|
40
42
|
"publishConfig": {
|
|
41
43
|
"access": "public"
|
package/src/dedupe.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
type Hasher<T> = (input: T) => string
|
|
2
|
+
|
|
3
|
+
// from https://github.com/seriousManual/dedupe/blob/master/LICENSE
|
|
4
|
+
export function dedupe<T>(list: T[], hasher: Hasher<T> = JSON.stringify) {
|
|
5
|
+
const clone: T[] = []
|
|
6
|
+
const lookup = new Set<string>()
|
|
7
|
+
|
|
8
|
+
for (const entry of list) {
|
|
9
|
+
const hashed = hasher(entry)
|
|
10
|
+
|
|
11
|
+
if (!lookup.has(hashed)) {
|
|
12
|
+
clone.push(entry)
|
|
13
|
+
lookup.add(hashed)
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return clone
|
|
18
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,21 +1,14 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { dedupe } from './dedupe'
|
|
2
2
|
import { concatUint8Array } from './util'
|
|
3
3
|
|
|
4
|
+
import type { GenericFilehandle } from 'generic-filehandle2'
|
|
5
|
+
|
|
4
6
|
const CHUNK_SIZE = 65536
|
|
5
7
|
|
|
6
8
|
// this is the number of hex characters to use for the address in ixixx, see
|
|
7
9
|
// https://github.com/GMOD/ixixx-js/blob/master/src/index.ts#L182
|
|
8
10
|
const ADDRESS_SIZE = 10
|
|
9
11
|
|
|
10
|
-
// https://stackoverflow.com/a/9229821/2129219
|
|
11
|
-
function uniqBy<T>(a: T[], key: (elt: T) => string) {
|
|
12
|
-
const seen = new Set()
|
|
13
|
-
return a.filter(item => {
|
|
14
|
-
const k = key(item)
|
|
15
|
-
return seen.has(k) ? false : seen.add(k)
|
|
16
|
-
})
|
|
17
|
-
}
|
|
18
|
-
|
|
19
12
|
export default class Trix {
|
|
20
13
|
constructor(
|
|
21
14
|
public ixxFile: GenericFilehandle,
|
|
@@ -37,10 +30,10 @@ export default class Trix {
|
|
|
37
30
|
let { end, buffer } = res
|
|
38
31
|
let done = false
|
|
39
32
|
const decoder = new TextDecoder('utf8')
|
|
40
|
-
const str = decoder.decode(buffer)
|
|
41
33
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
42
34
|
while (!done) {
|
|
43
35
|
let foundSomething = false
|
|
36
|
+
const str = decoder.decode(buffer)
|
|
44
37
|
|
|
45
38
|
// slice to lastIndexOf('\n') to make sure we get complete records
|
|
46
39
|
// since the buffer fetch could get halfway into a record
|
|
@@ -93,8 +86,8 @@ export default class Trix {
|
|
|
93
86
|
}
|
|
94
87
|
}
|
|
95
88
|
|
|
96
|
-
//
|
|
97
|
-
return
|
|
89
|
+
// de-duplicate results based on the detail column (resultArr[1])
|
|
90
|
+
return dedupe(resultArr, elt => elt[1]).slice(0, this.maxResults)
|
|
98
91
|
}
|
|
99
92
|
|
|
100
93
|
private async getIndex(opts?: { signal?: AbortSignal }) {
|