@gmod/trix 3.0.4 → 3.0.6
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/dedupe.js +7 -5
- package/dist/dedupe.js.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +160 -105
- package/dist/index.js.map +1 -1
- package/dist/package.json +1 -0
- package/dist/util.js +9 -7
- package/dist/util.js.map +1 -1
- package/esm/dedupe.js +10 -5
- package/esm/dedupe.js.map +1 -1
- package/esm/index.d.ts +3 -1
- package/esm/index.js +174 -107
- package/esm/index.js.map +1 -1
- package/esm/util.js +15 -9
- package/esm/util.js.map +1 -1
- package/package.json +28 -18
- package/src/index.ts +58 -72
- package/src/util.ts +3 -3
package/dist/dedupe.js
CHANGED
|
@@ -2,11 +2,13 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.dedupe = dedupe;
|
|
4
4
|
// from https://github.com/seriousManual/dedupe/blob/master/LICENSE
|
|
5
|
-
function dedupe(list, hasher
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
function dedupe(list, hasher) {
|
|
6
|
+
if (hasher === void 0) { hasher = JSON.stringify; }
|
|
7
|
+
var clone = [];
|
|
8
|
+
var lookup = new Set();
|
|
9
|
+
for (var _i = 0, list_1 = list; _i < list_1.length; _i++) {
|
|
10
|
+
var entry = list_1[_i];
|
|
11
|
+
var hashed = hasher(entry);
|
|
10
12
|
if (!lookup.has(hashed)) {
|
|
11
13
|
clone.push(entry);
|
|
12
14
|
lookup.add(hashed);
|
package/dist/dedupe.js.map
CHANGED
|
@@ -1 +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,
|
|
1
|
+
{"version":3,"file":"dedupe.js","sourceRoot":"","sources":["../src/dedupe.ts"],"names":[],"mappings":";;AAGA,wBAcC;AAfD,mEAAmE;AACnE,SAAgB,MAAM,CAAI,IAAS,EAAE,MAAkC;IAAlC,uBAAA,EAAA,SAAoB,IAAI,CAAC,SAAS;IACrE,IAAM,KAAK,GAAQ,EAAE,CAAA;IACrB,IAAM,MAAM,GAAG,IAAI,GAAG,EAAU,CAAA;IAEhC,KAAoB,UAAI,EAAJ,aAAI,EAAJ,kBAAI,EAAJ,IAAI,EAAE,CAAC;QAAtB,IAAM,KAAK,aAAA;QACd,IAAM,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.d.ts
CHANGED
|
@@ -3,10 +3,12 @@ export default class Trix {
|
|
|
3
3
|
ixxFile: GenericFilehandle;
|
|
4
4
|
ixFile: GenericFilehandle;
|
|
5
5
|
maxResults: number;
|
|
6
|
+
private decoder;
|
|
7
|
+
private indexCache?;
|
|
6
8
|
constructor(ixxFile: GenericFilehandle, ixFile: GenericFilehandle, maxResults?: number);
|
|
7
9
|
search(searchString: string, opts?: {
|
|
8
10
|
signal?: AbortSignal;
|
|
9
11
|
}): Promise<[string, string][]>;
|
|
10
12
|
private getIndex;
|
|
11
|
-
private
|
|
13
|
+
private getBuffer;
|
|
12
14
|
}
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
2
13
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
14
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
15
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -8,124 +19,168 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
19
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
20
|
});
|
|
10
21
|
};
|
|
22
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
24
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
|
+
function step(op) {
|
|
27
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
29
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
30
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
+
switch (op[0]) {
|
|
32
|
+
case 0: case 1: t = op; break;
|
|
33
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
+
default:
|
|
37
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
+
if (t[2]) _.ops.pop();
|
|
42
|
+
_.trys.pop(); continue;
|
|
43
|
+
}
|
|
44
|
+
op = body.call(thisArg, _);
|
|
45
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
|
+
}
|
|
48
|
+
};
|
|
11
49
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
50
|
+
var dedupe_ts_1 = require("./dedupe.js");
|
|
51
|
+
var util_ts_1 = require("./util.js");
|
|
52
|
+
var CHUNK_SIZE = 65536;
|
|
15
53
|
// this is the number of hex characters to use for the address in ixixx, see
|
|
16
54
|
// https://github.com/GMOD/ixixx-js/blob/master/src/index.ts#L182
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
55
|
+
var ADDRESS_SIZE = 10;
|
|
56
|
+
var Trix = /** @class */ (function () {
|
|
57
|
+
function Trix(ixxFile, ixFile, maxResults) {
|
|
58
|
+
if (maxResults === void 0) { maxResults = 20; }
|
|
20
59
|
this.ixxFile = ixxFile;
|
|
21
60
|
this.ixFile = ixFile;
|
|
22
61
|
this.maxResults = maxResults;
|
|
62
|
+
this.decoder = new TextDecoder('utf8');
|
|
23
63
|
}
|
|
24
|
-
search(searchString, opts) {
|
|
25
|
-
return __awaiter(this, void 0, void 0, function
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
// if we are not done, and we haven't filled up maxResults with hits yet,
|
|
68
|
-
// then refetch
|
|
69
|
-
if (resultArr.length + hits.length < this.maxResults && !done) {
|
|
70
|
-
const res2 = yield this.ixFile.read(CHUNK_SIZE, end, opts);
|
|
71
|
-
// early break if empty response
|
|
72
|
-
if (res2.length === 0) {
|
|
64
|
+
Trix.prototype.search = function (searchString, opts) {
|
|
65
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
66
|
+
var resultArr, searchWords, firstWord, searchWord, res, end, buffer, done, str, lines, hits2, _i, lines_1, line, word, hits, res2;
|
|
67
|
+
return __generator(this, function (_a) {
|
|
68
|
+
switch (_a.label) {
|
|
69
|
+
case 0:
|
|
70
|
+
resultArr = [];
|
|
71
|
+
searchWords = searchString.split(' ');
|
|
72
|
+
firstWord = searchWords[0];
|
|
73
|
+
if (!firstWord) return [3 /*break*/, 4];
|
|
74
|
+
searchWord = firstWord.toLowerCase();
|
|
75
|
+
return [4 /*yield*/, this.getBuffer(searchWord, opts)];
|
|
76
|
+
case 1:
|
|
77
|
+
res = _a.sent();
|
|
78
|
+
end = res.end, buffer = res.buffer;
|
|
79
|
+
done = false;
|
|
80
|
+
_a.label = 2;
|
|
81
|
+
case 2:
|
|
82
|
+
if (!!done) return [3 /*break*/, 4];
|
|
83
|
+
str = this.decoder.decode(buffer);
|
|
84
|
+
lines = str
|
|
85
|
+
.slice(0, str.lastIndexOf('\n'))
|
|
86
|
+
.split('\n')
|
|
87
|
+
.filter(Boolean);
|
|
88
|
+
hits2 = [];
|
|
89
|
+
for (_i = 0, lines_1 = lines; _i < lines_1.length; _i++) {
|
|
90
|
+
line = lines_1[_i];
|
|
91
|
+
word = line.split(' ')[0];
|
|
92
|
+
if (word.startsWith(searchWord)) {
|
|
93
|
+
hits2.push(line);
|
|
94
|
+
}
|
|
95
|
+
else if (word > searchWord) {
|
|
96
|
+
// we are done scanning if we are lexicographically greater than
|
|
97
|
+
// the search string
|
|
98
|
+
done = true;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
hits = hits2.flatMap(function (line) {
|
|
102
|
+
var _a = line.split(' '), term = _a[0], parts = _a.slice(1);
|
|
103
|
+
return parts
|
|
104
|
+
.filter(Boolean)
|
|
105
|
+
.map(function (elt) { return [term, elt.split(',')[0]]; });
|
|
106
|
+
});
|
|
73
107
|
resultArr = resultArr.concat(hits);
|
|
74
|
-
break
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
108
|
+
// if we are done or have filled up maxResults, break
|
|
109
|
+
if (done || resultArr.length >= this.maxResults) {
|
|
110
|
+
return [3 /*break*/, 4];
|
|
111
|
+
}
|
|
112
|
+
return [4 /*yield*/, this.ixFile.read(CHUNK_SIZE, end, opts)];
|
|
113
|
+
case 3:
|
|
114
|
+
res2 = _a.sent();
|
|
115
|
+
if (res2.length === 0) {
|
|
116
|
+
return [3 /*break*/, 4];
|
|
117
|
+
}
|
|
118
|
+
buffer = (0, util_ts_1.concatUint8Array)([buffer, res2]);
|
|
119
|
+
end += CHUNK_SIZE;
|
|
120
|
+
return [3 /*break*/, 2];
|
|
121
|
+
case 4:
|
|
122
|
+
// de-duplicate results based on the detail column (resultArr[1])
|
|
123
|
+
return [2 /*return*/, (0, dedupe_ts_1.dedupe)(resultArr, function (elt) { return elt[1]; }).slice(0, this.maxResults)];
|
|
78
124
|
}
|
|
79
|
-
|
|
80
|
-
// filtering, then return
|
|
81
|
-
else if (resultArr.length + hits.length >= this.maxResults || done) {
|
|
82
|
-
resultArr = resultArr.concat(hits);
|
|
83
|
-
break;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
// de-duplicate results based on the detail column (resultArr[1])
|
|
87
|
-
return (0, dedupe_ts_1.dedupe)(resultArr, elt => elt[1]).slice(0, this.maxResults);
|
|
125
|
+
});
|
|
88
126
|
});
|
|
89
|
-
}
|
|
90
|
-
getIndex(opts) {
|
|
91
|
-
return __awaiter(this, void 0, void 0, function
|
|
92
|
-
|
|
93
|
-
return
|
|
94
|
-
.
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
127
|
+
};
|
|
128
|
+
Trix.prototype.getIndex = function (opts) {
|
|
129
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
130
|
+
var file, result;
|
|
131
|
+
return __generator(this, function (_a) {
|
|
132
|
+
switch (_a.label) {
|
|
133
|
+
case 0:
|
|
134
|
+
if (this.indexCache) {
|
|
135
|
+
return [2 /*return*/, this.indexCache];
|
|
136
|
+
}
|
|
137
|
+
return [4 /*yield*/, this.ixxFile.readFile(__assign({ encoding: 'utf8' }, opts))];
|
|
138
|
+
case 1:
|
|
139
|
+
file = _a.sent();
|
|
140
|
+
result = file
|
|
141
|
+
.split('\n')
|
|
142
|
+
.filter(Boolean)
|
|
143
|
+
.map(function (line) {
|
|
144
|
+
var p = line.length - ADDRESS_SIZE;
|
|
145
|
+
var prefix = line.slice(0, p);
|
|
146
|
+
var posStr = line.slice(p);
|
|
147
|
+
var pos = Number.parseInt(posStr, 16);
|
|
148
|
+
return [prefix, pos];
|
|
149
|
+
});
|
|
150
|
+
this.indexCache = result;
|
|
151
|
+
return [2 /*return*/, result];
|
|
152
|
+
}
|
|
102
153
|
});
|
|
103
154
|
});
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
return __awaiter(this, void 0, void 0, function
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
155
|
+
};
|
|
156
|
+
Trix.prototype.getBuffer = function (searchWord, opts) {
|
|
157
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
158
|
+
var start, end, indexes, _i, indexes_1, _a, key, value, trimmedKey, buffer;
|
|
159
|
+
return __generator(this, function (_b) {
|
|
160
|
+
switch (_b.label) {
|
|
161
|
+
case 0:
|
|
162
|
+
start = 0;
|
|
163
|
+
end = CHUNK_SIZE;
|
|
164
|
+
return [4 /*yield*/, this.getIndex(opts)];
|
|
165
|
+
case 1:
|
|
166
|
+
indexes = _b.sent();
|
|
167
|
+
for (_i = 0, indexes_1 = indexes; _i < indexes_1.length; _i++) {
|
|
168
|
+
_a = indexes_1[_i], key = _a[0], value = _a[1];
|
|
169
|
+
trimmedKey = key.slice(0, searchWord.length);
|
|
170
|
+
if (trimmedKey < searchWord) {
|
|
171
|
+
start = value;
|
|
172
|
+
end = value + CHUNK_SIZE;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
return [4 /*yield*/, this.ixFile.read(end - start, start, opts)];
|
|
176
|
+
case 2:
|
|
177
|
+
buffer = _b.sent();
|
|
178
|
+
return [2 /*return*/, { buffer: buffer, end: end }];
|
|
115
179
|
}
|
|
116
|
-
}
|
|
117
|
-
// Return the buffer and its end position in the file.
|
|
118
|
-
const len = end - start;
|
|
119
|
-
if (len < 0) {
|
|
120
|
-
return undefined;
|
|
121
|
-
}
|
|
122
|
-
const buffer = yield this.ixFile.read(len, start, opts);
|
|
123
|
-
return {
|
|
124
|
-
buffer,
|
|
125
|
-
end,
|
|
126
|
-
};
|
|
180
|
+
});
|
|
127
181
|
});
|
|
128
|
-
}
|
|
129
|
-
|
|
182
|
+
};
|
|
183
|
+
return Trix;
|
|
184
|
+
}());
|
|
130
185
|
exports.default = Trix;
|
|
131
186
|
//# sourceMappingURL=index.js.map
|
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,yCAAoC;AACpC,qCAA4C;AAI5C,IAAM,UAAU,GAAG,KAAK,CAAA;AAExB,4EAA4E;AAC5E,iEAAiE;AACjE,IAAM,YAAY,GAAG,EAAE,CAAA;AAEvB;IAIE,cACS,OAA0B,EAC1B,MAAyB,EACzB,UAAe;QAAf,2BAAA,EAAA,eAAe;QAFf,YAAO,GAAP,OAAO,CAAmB;QAC1B,WAAM,GAAN,MAAM,CAAmB;QACzB,eAAU,GAAV,UAAU,CAAK;QANhB,YAAO,GAAG,IAAI,WAAW,CAAC,MAAM,CAAC,CAAA;IAOtC,CAAC;IAEE,qBAAM,GAAZ,UAAa,YAAoB,EAAE,IAA+B;;;;;;wBAC5D,SAAS,GAAG,EAAwB,CAAA;wBAClC,WAAW,GAAG,YAAY,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;wBACrC,SAAS,GAAG,WAAW,CAAC,CAAC,CAAC,CAAA;6BAG5B,SAAS,EAAT,wBAAS;wBACL,UAAU,GAAG,SAAS,CAAC,WAAW,EAAE,CAAA;wBAC9B,qBAAM,IAAI,CAAC,SAAS,CAAC,UAAU,EAAE,IAAI,CAAC,EAAA;;wBAA5C,GAAG,GAAG,SAAsC;wBAE5C,GAAG,GAAa,GAAG,IAAhB,EAAE,MAAM,GAAK,GAAG,OAAR,CAAQ;wBACrB,IAAI,GAAG,KAAK,CAAA;;;6BAET,CAAC,IAAI;wBACJ,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,CA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AAC,UAAU,GAAG,MAAM,CAAA;wBACxB,sBAAO,MAAM,EAAA;;;;KACd;IAEa,wBAAS,GAAvB,UAAwB,UAAkB,EAAE,IAA+B;;;;;;wBACrE,KAAK,GAAG,CAAC,CAAA;wBACT,GAAG,GAAG,UAAU,CAAA;wBACJ,qBAAM,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAA;;wBAAnC,OAAO,GAAG,SAAyB;wBACzC,WAAkC,EAAP,mBAAO,EAAP,qBAAO,EAAP,IAAO,EAAE,CAAC;4BAA1B,kBAAY,EAAX,GAAG,QAAA,EAAE,KAAK,QAAA;4BACd,UAAU,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,UAAU,CAAC,MAAM,CAAC,CAAA;4BAClD,IAAI,UAAU,GAAG,UAAU,EAAE,CAAC;gCAC5B,KAAK,GAAG,KAAK,CAAA;gCACb,GAAG,GAAG,KAAK,GAAG,UAAU,CAAA;4BAC1B,CAAC;wBACH,CAAC;wBAEc,qBAAM,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,GAAG,KAAK,EAAE,KAAK,EAAE,IAAI,CAAC,EAAA;;wBAAzD,MAAM,GAAG,SAAgD;wBAC/D,sBAAO,EAAE,MAAM,QAAA,EAAE,GAAG,KAAA,EAAE,EAAA;;;;KACvB;IACH,WAAC;AAAD,CAAC,AA9GD,IA8GC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type": "commonjs"}
|
package/dist/util.js
CHANGED
|
@@ -3,16 +3,18 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.sum = sum;
|
|
4
4
|
exports.concatUint8Array = concatUint8Array;
|
|
5
5
|
function sum(array) {
|
|
6
|
-
|
|
7
|
-
for (
|
|
8
|
-
|
|
6
|
+
var total = 0;
|
|
7
|
+
for (var _i = 0, array_1 = array; _i < array_1.length; _i++) {
|
|
8
|
+
var entry = array_1[_i];
|
|
9
|
+
total += entry.length;
|
|
9
10
|
}
|
|
10
|
-
return
|
|
11
|
+
return total;
|
|
11
12
|
}
|
|
12
13
|
function concatUint8Array(args) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
for (
|
|
14
|
+
var mergedArray = new Uint8Array(sum(args));
|
|
15
|
+
var offset = 0;
|
|
16
|
+
for (var _i = 0, args_1 = args; _i < args_1.length; _i++) {
|
|
17
|
+
var entry = args_1[_i];
|
|
16
18
|
mergedArray.set(entry, offset);
|
|
17
19
|
offset += entry.length;
|
|
18
20
|
}
|
package/dist/util.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"util.js","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":";;AAAA,kBAMC;AACD,4CAQC;AAfD,SAAgB,GAAG,CAAC,KAAmB;IACrC,IAAI,
|
|
1
|
+
{"version":3,"file":"util.js","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":";;AAAA,kBAMC;AACD,4CAQC;AAfD,SAAgB,GAAG,CAAC,KAAmB;IACrC,IAAI,KAAK,GAAG,CAAC,CAAA;IACb,KAAoB,UAAK,EAAL,eAAK,EAAL,mBAAK,EAAL,IAAK,EAAE,CAAC;QAAvB,IAAM,KAAK,cAAA;QACd,KAAK,IAAI,KAAK,CAAC,MAAM,CAAA;IACvB,CAAC;IACD,OAAO,KAAK,CAAA;AACd,CAAC;AACD,SAAgB,gBAAgB,CAAC,IAAkB;IACjD,IAAM,WAAW,GAAG,IAAI,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAA;IAC7C,IAAI,MAAM,GAAG,CAAC,CAAA;IACd,KAAoB,UAAI,EAAJ,aAAI,EAAJ,kBAAI,EAAJ,IAAI,EAAE,CAAC;QAAtB,IAAM,KAAK,aAAA;QACd,WAAW,CAAC,GAAG,CAAC,KAAK,EAAE,MAAM,CAAC,CAAA;QAC9B,MAAM,IAAI,KAAK,CAAC,MAAM,CAAA;IACxB,CAAC;IACD,OAAO,WAAW,CAAA;AACpB,CAAC"}
|
package/esm/dedupe.js
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.dedupe = dedupe;
|
|
1
4
|
// from https://github.com/seriousManual/dedupe/blob/master/LICENSE
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
function dedupe(list, hasher) {
|
|
6
|
+
if (hasher === void 0) { hasher = JSON.stringify; }
|
|
7
|
+
var clone = [];
|
|
8
|
+
var lookup = new Set();
|
|
9
|
+
for (var _i = 0, list_1 = list; _i < list_1.length; _i++) {
|
|
10
|
+
var entry = list_1[_i];
|
|
11
|
+
var hashed = hasher(entry);
|
|
7
12
|
if (!lookup.has(hashed)) {
|
|
8
13
|
clone.push(entry);
|
|
9
14
|
lookup.add(hashed);
|
package/esm/dedupe.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dedupe.js","sourceRoot":"","sources":["../src/dedupe.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"dedupe.js","sourceRoot":"","sources":["../src/dedupe.ts"],"names":[],"mappings":";;AAGA,wBAcC;AAfD,mEAAmE;AACnE,SAAgB,MAAM,CAAI,IAAS,EAAE,MAAkC;IAAlC,uBAAA,EAAA,SAAoB,IAAI,CAAC,SAAS;IACrE,IAAM,KAAK,GAAQ,EAAE,CAAA;IACrB,IAAM,MAAM,GAAG,IAAI,GAAG,EAAU,CAAA;IAEhC,KAAoB,UAAI,EAAJ,aAAI,EAAJ,kBAAI,EAAJ,IAAI,EAAE,CAAC;QAAtB,IAAM,KAAK,aAAA;QACd,IAAM,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.d.ts
CHANGED
|
@@ -3,10 +3,12 @@ export default class Trix {
|
|
|
3
3
|
ixxFile: GenericFilehandle;
|
|
4
4
|
ixFile: GenericFilehandle;
|
|
5
5
|
maxResults: number;
|
|
6
|
+
private decoder;
|
|
7
|
+
private indexCache?;
|
|
6
8
|
constructor(ixxFile: GenericFilehandle, ixFile: GenericFilehandle, maxResults?: number);
|
|
7
9
|
search(searchString: string, opts?: {
|
|
8
10
|
signal?: AbortSignal;
|
|
9
11
|
}): Promise<[string, string][]>;
|
|
10
12
|
private getIndex;
|
|
11
|
-
private
|
|
13
|
+
private getBuffer;
|
|
12
14
|
}
|
package/esm/index.js
CHANGED
|
@@ -1,119 +1,186 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
16
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
17
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
18
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
19
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
24
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
|
+
function step(op) {
|
|
27
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
29
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
30
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
+
switch (op[0]) {
|
|
32
|
+
case 0: case 1: t = op; break;
|
|
33
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
+
default:
|
|
37
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
+
if (t[2]) _.ops.pop();
|
|
42
|
+
_.trys.pop(); continue;
|
|
43
|
+
}
|
|
44
|
+
op = body.call(thisArg, _);
|
|
45
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
50
|
+
var dedupe_ts_1 = require("./dedupe.js");
|
|
51
|
+
var util_ts_1 = require("./util.js");
|
|
52
|
+
var CHUNK_SIZE = 65536;
|
|
4
53
|
// this is the number of hex characters to use for the address in ixixx, see
|
|
5
54
|
// https://github.com/GMOD/ixixx-js/blob/master/src/index.ts#L182
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
ixxFile
|
|
9
|
-
|
|
10
|
-
maxResults;
|
|
11
|
-
constructor(ixxFile, ixFile, maxResults = 20) {
|
|
55
|
+
var ADDRESS_SIZE = 10;
|
|
56
|
+
var Trix = /** @class */ (function () {
|
|
57
|
+
function Trix(ixxFile, ixFile, maxResults) {
|
|
58
|
+
if (maxResults === void 0) { maxResults = 20; }
|
|
12
59
|
this.ixxFile = ixxFile;
|
|
13
60
|
this.ixFile = ixFile;
|
|
14
61
|
this.maxResults = maxResults;
|
|
62
|
+
this.decoder = new TextDecoder('utf8');
|
|
15
63
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
64
|
+
Trix.prototype.search = function (searchString, opts) {
|
|
65
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
66
|
+
var resultArr, searchWords, firstWord, searchWord, res, end, buffer, done, str, lines, hits2, _i, lines_1, line, word, hits, res2;
|
|
67
|
+
return __generator(this, function (_a) {
|
|
68
|
+
switch (_a.label) {
|
|
69
|
+
case 0:
|
|
70
|
+
resultArr = [];
|
|
71
|
+
searchWords = searchString.split(' ');
|
|
72
|
+
firstWord = searchWords[0];
|
|
73
|
+
if (!firstWord) return [3 /*break*/, 4];
|
|
74
|
+
searchWord = firstWord.toLowerCase();
|
|
75
|
+
return [4 /*yield*/, this.getBuffer(searchWord, opts)];
|
|
76
|
+
case 1:
|
|
77
|
+
res = _a.sent();
|
|
78
|
+
end = res.end, buffer = res.buffer;
|
|
79
|
+
done = false;
|
|
80
|
+
_a.label = 2;
|
|
81
|
+
case 2:
|
|
82
|
+
if (!!done) return [3 /*break*/, 4];
|
|
83
|
+
str = this.decoder.decode(buffer);
|
|
84
|
+
lines = str
|
|
85
|
+
.slice(0, str.lastIndexOf('\n'))
|
|
86
|
+
.split('\n')
|
|
87
|
+
.filter(Boolean);
|
|
88
|
+
hits2 = [];
|
|
89
|
+
for (_i = 0, lines_1 = lines; _i < lines_1.length; _i++) {
|
|
90
|
+
line = lines_1[_i];
|
|
91
|
+
word = line.split(' ')[0];
|
|
92
|
+
if (word.startsWith(searchWord)) {
|
|
93
|
+
hits2.push(line);
|
|
94
|
+
}
|
|
95
|
+
else if (word > searchWord) {
|
|
96
|
+
// we are done scanning if we are lexicographically greater than
|
|
97
|
+
// the search string
|
|
98
|
+
done = true;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
hits = hits2.flatMap(function (line) {
|
|
102
|
+
var _a = line.split(' '), term = _a[0], parts = _a.slice(1);
|
|
103
|
+
return parts
|
|
104
|
+
.filter(Boolean)
|
|
105
|
+
.map(function (elt) { return [term, elt.split(',')[0]]; });
|
|
106
|
+
});
|
|
107
|
+
resultArr = resultArr.concat(hits);
|
|
108
|
+
// if we are done or have filled up maxResults, break
|
|
109
|
+
if (done || resultArr.length >= this.maxResults) {
|
|
110
|
+
return [3 /*break*/, 4];
|
|
111
|
+
}
|
|
112
|
+
return [4 /*yield*/, this.ixFile.read(CHUNK_SIZE, end, opts)];
|
|
113
|
+
case 3:
|
|
114
|
+
res2 = _a.sent();
|
|
115
|
+
if (res2.length === 0) {
|
|
116
|
+
return [3 /*break*/, 4];
|
|
117
|
+
}
|
|
118
|
+
buffer = (0, util_ts_1.concatUint8Array)([buffer, res2]);
|
|
119
|
+
end += CHUNK_SIZE;
|
|
120
|
+
return [3 /*break*/, 2];
|
|
121
|
+
case 4:
|
|
122
|
+
// de-duplicate results based on the detail column (resultArr[1])
|
|
123
|
+
return [2 /*return*/, (0, dedupe_ts_1.dedupe)(resultArr, function (elt) { return elt[1]; }).slice(0, this.maxResults)];
|
|
49
124
|
}
|
|
50
|
-
if (match) {
|
|
51
|
-
hits2.push(line);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
const hits = hits2.flatMap(line => {
|
|
55
|
-
const [term, ...parts] = line.split(' ');
|
|
56
|
-
return parts.map(elt => [term, elt.split(',')[0]]);
|
|
57
125
|
});
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
126
|
+
});
|
|
127
|
+
};
|
|
128
|
+
Trix.prototype.getIndex = function (opts) {
|
|
129
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
130
|
+
var file, result;
|
|
131
|
+
return __generator(this, function (_a) {
|
|
132
|
+
switch (_a.label) {
|
|
133
|
+
case 0:
|
|
134
|
+
if (this.indexCache) {
|
|
135
|
+
return [2 /*return*/, this.indexCache];
|
|
136
|
+
}
|
|
137
|
+
return [4 /*yield*/, this.ixxFile.readFile(__assign({ encoding: 'utf8' }, opts))];
|
|
138
|
+
case 1:
|
|
139
|
+
file = _a.sent();
|
|
140
|
+
result = file
|
|
141
|
+
.split('\n')
|
|
142
|
+
.filter(Boolean)
|
|
143
|
+
.map(function (line) {
|
|
144
|
+
var p = line.length - ADDRESS_SIZE;
|
|
145
|
+
var prefix = line.slice(0, p);
|
|
146
|
+
var posStr = line.slice(p);
|
|
147
|
+
var pos = Number.parseInt(posStr, 16);
|
|
148
|
+
return [prefix, pos];
|
|
149
|
+
});
|
|
150
|
+
this.indexCache = result;
|
|
151
|
+
return [2 /*return*/, result];
|
|
66
152
|
}
|
|
67
|
-
|
|
68
|
-
end += CHUNK_SIZE;
|
|
69
|
-
}
|
|
70
|
-
// if we have filled up the hits, or we are detected to be done via the
|
|
71
|
-
// filtering, then return
|
|
72
|
-
else if (resultArr.length + hits.length >= this.maxResults || done) {
|
|
73
|
-
resultArr = resultArr.concat(hits);
|
|
74
|
-
break;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
// de-duplicate results based on the detail column (resultArr[1])
|
|
78
|
-
return dedupe(resultArr, elt => elt[1]).slice(0, this.maxResults);
|
|
79
|
-
}
|
|
80
|
-
async getIndex(opts) {
|
|
81
|
-
const file = await this.ixxFile.readFile({
|
|
82
|
-
encoding: 'utf8',
|
|
83
|
-
...opts,
|
|
153
|
+
});
|
|
84
154
|
});
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
155
|
+
};
|
|
156
|
+
Trix.prototype.getBuffer = function (searchWord, opts) {
|
|
157
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
158
|
+
var start, end, indexes, _i, indexes_1, _a, key, value, trimmedKey, buffer;
|
|
159
|
+
return __generator(this, function (_b) {
|
|
160
|
+
switch (_b.label) {
|
|
161
|
+
case 0:
|
|
162
|
+
start = 0;
|
|
163
|
+
end = CHUNK_SIZE;
|
|
164
|
+
return [4 /*yield*/, this.getIndex(opts)];
|
|
165
|
+
case 1:
|
|
166
|
+
indexes = _b.sent();
|
|
167
|
+
for (_i = 0, indexes_1 = indexes; _i < indexes_1.length; _i++) {
|
|
168
|
+
_a = indexes_1[_i], key = _a[0], value = _a[1];
|
|
169
|
+
trimmedKey = key.slice(0, searchWord.length);
|
|
170
|
+
if (trimmedKey < searchWord) {
|
|
171
|
+
start = value;
|
|
172
|
+
end = value + CHUNK_SIZE;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
return [4 /*yield*/, this.ixFile.read(end - start, start, opts)];
|
|
176
|
+
case 2:
|
|
177
|
+
buffer = _b.sent();
|
|
178
|
+
return [2 /*return*/, { buffer: buffer, end: end }];
|
|
179
|
+
}
|
|
180
|
+
});
|
|
94
181
|
});
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
const indexes = await this.getIndex(opts);
|
|
100
|
-
for (const [key, value] of indexes) {
|
|
101
|
-
const trimmedKey = key.slice(0, searchWord.length);
|
|
102
|
-
if (trimmedKey < searchWord) {
|
|
103
|
-
start = value;
|
|
104
|
-
end = value + 65536;
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
// Return the buffer and its end position in the file.
|
|
108
|
-
const len = end - start;
|
|
109
|
-
if (len < 0) {
|
|
110
|
-
return undefined;
|
|
111
|
-
}
|
|
112
|
-
const buffer = await this.ixFile.read(len, start, opts);
|
|
113
|
-
return {
|
|
114
|
-
buffer,
|
|
115
|
-
end,
|
|
116
|
-
};
|
|
117
|
-
}
|
|
118
|
-
}
|
|
182
|
+
};
|
|
183
|
+
return Trix;
|
|
184
|
+
}());
|
|
185
|
+
exports.default = Trix;
|
|
119
186
|
//# sourceMappingURL=index.js.map
|
package/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAA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EAAE,CAAC;4BAA1B,kBAAY,EAAX,GAAG,QAAA,EAAE,KAAK,QAAA;4BACd,UAAU,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,UAAU,CAAC,MAAM,CAAC,CAAA;4BAClD,IAAI,UAAU,GAAG,UAAU,EAAE,CAAC;gCAC5B,KAAK,GAAG,KAAK,CAAA;gCACb,GAAG,GAAG,KAAK,GAAG,UAAU,CAAA;4BAC1B,CAAC;wBACH,CAAC;wBAEc,qBAAM,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,GAAG,KAAK,EAAE,KAAK,EAAE,IAAI,CAAC,EAAA;;wBAAzD,MAAM,GAAG,SAAgD;wBAC/D,sBAAO,EAAE,MAAM,QAAA,EAAE,GAAG,KAAA,EAAE,EAAA;;;;KACvB;IACH,WAAC;AAAD,CAAC,AA9GD,IA8GC"}
|
package/esm/util.js
CHANGED
|
@@ -1,14 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.sum = sum;
|
|
4
|
+
exports.concatUint8Array = concatUint8Array;
|
|
5
|
+
function sum(array) {
|
|
6
|
+
var total = 0;
|
|
7
|
+
for (var _i = 0, array_1 = array; _i < array_1.length; _i++) {
|
|
8
|
+
var entry = array_1[_i];
|
|
9
|
+
total += entry.length;
|
|
5
10
|
}
|
|
6
|
-
return
|
|
11
|
+
return total;
|
|
7
12
|
}
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
for (
|
|
13
|
+
function concatUint8Array(args) {
|
|
14
|
+
var mergedArray = new Uint8Array(sum(args));
|
|
15
|
+
var offset = 0;
|
|
16
|
+
for (var _i = 0, args_1 = args; _i < args_1.length; _i++) {
|
|
17
|
+
var entry = args_1[_i];
|
|
12
18
|
mergedArray.set(entry, offset);
|
|
13
19
|
offset += entry.length;
|
|
14
20
|
}
|
package/esm/util.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"util.js","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"util.js","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":";;AAAA,kBAMC;AACD,4CAQC;AAfD,SAAgB,GAAG,CAAC,KAAmB;IACrC,IAAI,KAAK,GAAG,CAAC,CAAA;IACb,KAAoB,UAAK,EAAL,eAAK,EAAL,mBAAK,EAAL,IAAK,EAAE,CAAC;QAAvB,IAAM,KAAK,cAAA;QACd,KAAK,IAAI,KAAK,CAAC,MAAM,CAAA;IACvB,CAAC;IACD,OAAO,KAAK,CAAA;AACd,CAAC;AACD,SAAgB,gBAAgB,CAAC,IAAkB;IACjD,IAAM,WAAW,GAAG,IAAI,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAA;IAC7C,IAAI,MAAM,GAAG,CAAC,CAAA;IACd,KAAoB,UAAI,EAAJ,aAAI,EAAJ,kBAAI,EAAJ,IAAI,EAAE,CAAC;QAAtB,IAAM,KAAK,aAAA;QACd,WAAW,CAAC,GAAG,CAAC,KAAK,EAAE,MAAM,CAAC,CAAA;QAC9B,MAAM,IAAI,KAAK,CAAC,MAAM,CAAA;IACxB,CAAC;IACD,OAAO,WAAW,CAAA;AACpB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,8 +1,17 @@
|
|
|
1
1
|
{
|
|
2
|
-
"
|
|
2
|
+
"name": "@gmod/trix",
|
|
3
|
+
"version": "3.0.6",
|
|
3
4
|
"license": "Apache-2.0",
|
|
4
|
-
"
|
|
5
|
-
"
|
|
5
|
+
"type": "module",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
"import": {
|
|
9
|
+
"import": "./esm/index.js"
|
|
10
|
+
},
|
|
11
|
+
"require": {
|
|
12
|
+
"require": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
6
15
|
"files": [
|
|
7
16
|
"dist",
|
|
8
17
|
"esm",
|
|
@@ -12,32 +21,33 @@
|
|
|
12
21
|
"node": ">=10"
|
|
13
22
|
},
|
|
14
23
|
"scripts": {
|
|
24
|
+
"test": "vitest",
|
|
15
25
|
"lint": "eslint --report-unused-disable-directives --max-warnings 0",
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
"build:
|
|
19
|
-
"build": "
|
|
20
|
-
"
|
|
26
|
+
"clean": "rimraf dist esm",
|
|
27
|
+
"format": "prettier --write .",
|
|
28
|
+
"build:esm": "tsc --outDir esm",
|
|
29
|
+
"build:es5": "tsc --module commonjs --outDir dist",
|
|
30
|
+
"build": "yarn build:esm && yarn build:es5",
|
|
31
|
+
"prebuild": "yarn clean",
|
|
21
32
|
"postbuild:es5": "echo '{\"type\": \"commonjs\"}' > dist/package.json",
|
|
22
|
-
"
|
|
23
|
-
"
|
|
33
|
+
"preversion": "yarn lint && yarn test --run && yarn build",
|
|
34
|
+
"postversion": "git push --follow-tags"
|
|
24
35
|
},
|
|
25
|
-
"name": "@gmod/trix",
|
|
26
36
|
"author": "Matt Morgan",
|
|
27
37
|
"repository": "GMOD/trix-js",
|
|
28
38
|
"devDependencies": {
|
|
29
|
-
"@types/node": "^
|
|
30
|
-
"@typescript-eslint/eslint-plugin": "^8.
|
|
31
|
-
"@typescript-eslint/parser": "^8.
|
|
39
|
+
"@types/node": "^25.0.9",
|
|
40
|
+
"@typescript-eslint/eslint-plugin": "^8.53.0",
|
|
41
|
+
"@typescript-eslint/parser": "^8.53.0",
|
|
32
42
|
"eslint": "^9.0.0",
|
|
33
43
|
"eslint-plugin-import": "^2.31.0",
|
|
34
44
|
"eslint-plugin-unicorn": "^62.0.0",
|
|
35
|
-
"generic-filehandle2": "^2.0.
|
|
36
|
-
"prettier": "^3.
|
|
45
|
+
"generic-filehandle2": "^2.0.18",
|
|
46
|
+
"prettier": "^3.8.0",
|
|
37
47
|
"rimraf": "^6.0.1",
|
|
38
48
|
"typescript": "^5.7.0",
|
|
39
|
-
"typescript-eslint": "^8.
|
|
40
|
-
"vitest": "^4.0.
|
|
49
|
+
"typescript-eslint": "^8.53.0",
|
|
50
|
+
"vitest": "^4.0.17"
|
|
41
51
|
},
|
|
42
52
|
"publishConfig": {
|
|
43
53
|
"access": "public"
|
package/src/index.ts
CHANGED
|
@@ -10,6 +10,9 @@ const CHUNK_SIZE = 65536
|
|
|
10
10
|
const ADDRESS_SIZE = 10
|
|
11
11
|
|
|
12
12
|
export default class Trix {
|
|
13
|
+
private decoder = new TextDecoder('utf8')
|
|
14
|
+
private indexCache?: readonly (readonly [string, number])[]
|
|
15
|
+
|
|
13
16
|
constructor(
|
|
14
17
|
public ixxFile: GenericFilehandle,
|
|
15
18
|
public ixFile: GenericFilehandle,
|
|
@@ -19,71 +22,60 @@ export default class Trix {
|
|
|
19
22
|
async search(searchString: string, opts?: { signal?: AbortSignal }) {
|
|
20
23
|
let resultArr = [] as [string, string][]
|
|
21
24
|
const searchWords = searchString.split(' ')
|
|
25
|
+
const firstWord = searchWords[0]
|
|
26
|
+
|
|
27
|
+
// validate that we have a non-empty search term
|
|
28
|
+
if (firstWord) {
|
|
29
|
+
const searchWord = firstWord.toLowerCase()
|
|
30
|
+
const res = await this.getBuffer(searchWord, opts)
|
|
31
|
+
|
|
32
|
+
let { end, buffer } = res
|
|
33
|
+
let done = false
|
|
34
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
35
|
+
while (!done) {
|
|
36
|
+
const str = this.decoder.decode(buffer)
|
|
37
|
+
|
|
38
|
+
// slice to lastIndexOf('\n') to make sure we get complete records
|
|
39
|
+
// since the buffer fetch could get halfway into a record
|
|
40
|
+
const lines = str
|
|
41
|
+
.slice(0, str.lastIndexOf('\n'))
|
|
42
|
+
.split('\n')
|
|
43
|
+
.filter(Boolean)
|
|
44
|
+
|
|
45
|
+
const hits2 = [] as string[]
|
|
46
|
+
for (const line of lines) {
|
|
47
|
+
const word = line.split(' ')[0]
|
|
48
|
+
|
|
49
|
+
if (word.startsWith(searchWord)) {
|
|
50
|
+
hits2.push(line)
|
|
51
|
+
} else if (word > searchWord) {
|
|
52
|
+
// we are done scanning if we are lexicographically greater than
|
|
53
|
+
// the search string
|
|
54
|
+
done = true
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
const hits = hits2.flatMap(line => {
|
|
58
|
+
const [term, ...parts] = line.split(' ')
|
|
59
|
+
return parts
|
|
60
|
+
.filter(Boolean)
|
|
61
|
+
.map(elt => [term, elt.split(',')[0]] as [string, string])
|
|
62
|
+
})
|
|
22
63
|
|
|
23
|
-
|
|
24
|
-
const searchWord = searchWords[0].toLowerCase()
|
|
25
|
-
const res = await this._getBuffer(searchWord, opts)
|
|
26
|
-
if (!res) {
|
|
27
|
-
return []
|
|
28
|
-
}
|
|
64
|
+
resultArr = resultArr.concat(hits)
|
|
29
65
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
34
|
-
while (!done) {
|
|
35
|
-
let foundSomething = false
|
|
36
|
-
const str = decoder.decode(buffer)
|
|
37
|
-
|
|
38
|
-
// slice to lastIndexOf('\n') to make sure we get complete records
|
|
39
|
-
// since the buffer fetch could get halfway into a record
|
|
40
|
-
const lines = str
|
|
41
|
-
.slice(0, str.lastIndexOf('\n'))
|
|
42
|
-
.split('\n')
|
|
43
|
-
.filter(f => !!f)
|
|
44
|
-
|
|
45
|
-
const hits2 = [] as string[]
|
|
46
|
-
for (const line of lines) {
|
|
47
|
-
const word = line.split(' ')[0]
|
|
48
|
-
const match = word.startsWith(searchWord)
|
|
49
|
-
if (!foundSomething && match) {
|
|
50
|
-
foundSomething = true
|
|
66
|
+
// if we are done or have filled up maxResults, break
|
|
67
|
+
if (done || resultArr.length >= this.maxResults) {
|
|
68
|
+
break
|
|
51
69
|
}
|
|
52
70
|
|
|
53
|
-
//
|
|
54
|
-
// search string
|
|
55
|
-
if (word.slice(0, searchWord.length) > searchWord) {
|
|
56
|
-
done = true
|
|
57
|
-
}
|
|
58
|
-
if (match) {
|
|
59
|
-
hits2.push(line)
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
const hits = hits2.flatMap(line => {
|
|
63
|
-
const [term, ...parts] = line.split(' ')
|
|
64
|
-
return parts.map(elt => [term, elt.split(',')[0]] as [string, string])
|
|
65
|
-
})
|
|
66
|
-
|
|
67
|
-
// if we are not done, and we haven't filled up maxResults with hits yet,
|
|
68
|
-
// then refetch
|
|
69
|
-
if (resultArr.length + hits.length < this.maxResults && !done) {
|
|
71
|
+
// fetch more data
|
|
70
72
|
const res2 = await this.ixFile.read(CHUNK_SIZE, end, opts)
|
|
71
|
-
|
|
72
|
-
// early break if empty response
|
|
73
73
|
if (res2.length === 0) {
|
|
74
|
-
resultArr = resultArr.concat(hits)
|
|
75
74
|
break
|
|
76
75
|
}
|
|
77
76
|
buffer = concatUint8Array([buffer, res2])
|
|
78
77
|
end += CHUNK_SIZE
|
|
79
78
|
}
|
|
80
|
-
|
|
81
|
-
// if we have filled up the hits, or we are detected to be done via the
|
|
82
|
-
// filtering, then return
|
|
83
|
-
else if (resultArr.length + hits.length >= this.maxResults || done) {
|
|
84
|
-
resultArr = resultArr.concat(hits)
|
|
85
|
-
break
|
|
86
|
-
}
|
|
87
79
|
}
|
|
88
80
|
|
|
89
81
|
// de-duplicate results based on the detail column (resultArr[1])
|
|
@@ -91,13 +83,16 @@ export default class Trix {
|
|
|
91
83
|
}
|
|
92
84
|
|
|
93
85
|
private async getIndex(opts?: { signal?: AbortSignal }) {
|
|
86
|
+
if (this.indexCache) {
|
|
87
|
+
return this.indexCache
|
|
88
|
+
}
|
|
94
89
|
const file = await this.ixxFile.readFile({
|
|
95
90
|
encoding: 'utf8',
|
|
96
91
|
...opts,
|
|
97
92
|
})
|
|
98
|
-
|
|
93
|
+
const result = file
|
|
99
94
|
.split('\n')
|
|
100
|
-
.filter(
|
|
95
|
+
.filter(Boolean)
|
|
101
96
|
.map(line => {
|
|
102
97
|
const p = line.length - ADDRESS_SIZE
|
|
103
98
|
const prefix = line.slice(0, p)
|
|
@@ -105,32 +100,23 @@ export default class Trix {
|
|
|
105
100
|
const pos = Number.parseInt(posStr, 16)
|
|
106
101
|
return [prefix, pos] as const
|
|
107
102
|
})
|
|
103
|
+
this.indexCache = result
|
|
104
|
+
return result
|
|
108
105
|
}
|
|
109
106
|
|
|
110
|
-
private async
|
|
111
|
-
searchWord: string,
|
|
112
|
-
opts?: { signal?: AbortSignal },
|
|
113
|
-
) {
|
|
107
|
+
private async getBuffer(searchWord: string, opts?: { signal?: AbortSignal }) {
|
|
114
108
|
let start = 0
|
|
115
|
-
let end =
|
|
109
|
+
let end = CHUNK_SIZE
|
|
116
110
|
const indexes = await this.getIndex(opts)
|
|
117
111
|
for (const [key, value] of indexes) {
|
|
118
112
|
const trimmedKey = key.slice(0, searchWord.length)
|
|
119
113
|
if (trimmedKey < searchWord) {
|
|
120
114
|
start = value
|
|
121
|
-
end = value +
|
|
115
|
+
end = value + CHUNK_SIZE
|
|
122
116
|
}
|
|
123
117
|
}
|
|
124
118
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
if (len < 0) {
|
|
128
|
-
return undefined
|
|
129
|
-
}
|
|
130
|
-
const buffer = await this.ixFile.read(len, start, opts)
|
|
131
|
-
return {
|
|
132
|
-
buffer,
|
|
133
|
-
end,
|
|
134
|
-
}
|
|
119
|
+
const buffer = await this.ixFile.read(end - start, start, opts)
|
|
120
|
+
return { buffer, end }
|
|
135
121
|
}
|
|
136
122
|
}
|
package/src/util.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
export function sum(array: Uint8Array[]) {
|
|
2
|
-
let
|
|
2
|
+
let total = 0
|
|
3
3
|
for (const entry of array) {
|
|
4
|
-
|
|
4
|
+
total += entry.length
|
|
5
5
|
}
|
|
6
|
-
return
|
|
6
|
+
return total
|
|
7
7
|
}
|
|
8
8
|
export function concatUint8Array(args: Uint8Array[]) {
|
|
9
9
|
const mergedArray = new Uint8Array(sum(args))
|