@gmod/trix 2.0.6 → 2.0.7
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/index.d.ts +2 -2
- package/dist/index.js +105 -185
- package/dist/index.js.map +1 -1
- package/esm/index.d.ts +2 -2
- package/esm/index.js +15 -12
- package/esm/index.js.map +1 -1
- package/package.json +19 -22
- package/src/index.ts +29 -39
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { GenericFilehandle } from 'generic-filehandle';
|
|
2
2
|
export default class Trix {
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
ixxFile: GenericFilehandle;
|
|
4
|
+
ixFile: GenericFilehandle;
|
|
5
5
|
maxResults: number;
|
|
6
6
|
constructor(ixxFile: GenericFilehandle, ixFile: GenericFilehandle, maxResults?: number);
|
|
7
7
|
search(searchString: string, opts?: {
|
package/dist/index.js
CHANGED
|
@@ -1,15 +1,4 @@
|
|
|
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
|
-
};
|
|
13
2
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
3
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
4
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -19,196 +8,127 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
19
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
9
|
});
|
|
21
10
|
};
|
|
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;
|
|
24
|
-
return g = { next: verb(0), "throw": verb(1), "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
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
50
|
-
|
|
12
|
+
const buffer_1 = require("buffer");
|
|
13
|
+
const CHUNK_SIZE = 65536;
|
|
51
14
|
// this is the number of hex characters to use for the address in ixixx, see
|
|
52
15
|
// https://github.com/GMOD/ixixx-js/blob/master/src/index.ts#L182
|
|
53
|
-
|
|
16
|
+
const ADDRESS_SIZE = 10;
|
|
54
17
|
// https://stackoverflow.com/a/9229821/2129219
|
|
55
18
|
function uniqBy(a, key) {
|
|
56
|
-
|
|
57
|
-
return a.filter(
|
|
58
|
-
|
|
19
|
+
const seen = new Set();
|
|
20
|
+
return a.filter(item => {
|
|
21
|
+
const k = key(item);
|
|
59
22
|
return seen.has(k) ? false : seen.add(k);
|
|
60
23
|
});
|
|
61
24
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
if (maxResults === void 0) { maxResults = 20; }
|
|
65
|
-
this.ixFile = ixFile;
|
|
25
|
+
class Trix {
|
|
26
|
+
constructor(ixxFile, ixFile, maxResults = 20) {
|
|
66
27
|
this.ixxFile = ixxFile;
|
|
28
|
+
this.ixFile = ixFile;
|
|
67
29
|
this.maxResults = maxResults;
|
|
68
30
|
}
|
|
69
|
-
|
|
70
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
// search string
|
|
107
|
-
if (word.slice(0, searchWord.length) > searchWord) {
|
|
108
|
-
done = true;
|
|
109
|
-
}
|
|
110
|
-
return match;
|
|
111
|
-
})
|
|
112
|
-
.map(function (line) {
|
|
113
|
-
var _a = line.split(' '), term = _a[0], parts = _a.slice(1);
|
|
114
|
-
return parts.map(function (elt) { return [term, elt.split(',')[0]]; });
|
|
115
|
-
})
|
|
116
|
-
.flat();
|
|
117
|
-
if (!(resultArr.length + hits.length < this_1.maxResults && !done)) return [3 /*break*/, 2];
|
|
118
|
-
return [4 /*yield*/, this_1.ixFile.read(Buffer.alloc(CHUNK_SIZE), 0, CHUNK_SIZE, end, opts)
|
|
119
|
-
// early break if empty response
|
|
120
|
-
];
|
|
121
|
-
case 1:
|
|
122
|
-
res2 = _b.sent();
|
|
123
|
-
// early break if empty response
|
|
124
|
-
if (!res2.bytesRead) {
|
|
125
|
-
resultArr = resultArr.concat(hits);
|
|
126
|
-
return [2 /*return*/, "break"];
|
|
127
|
-
}
|
|
128
|
-
buffer = Buffer.concat([buffer, res2.buffer]);
|
|
129
|
-
end += CHUNK_SIZE;
|
|
130
|
-
return [3 /*break*/, 3];
|
|
131
|
-
case 2:
|
|
132
|
-
if (resultArr.length + hits.length >= this_1.maxResults || done) {
|
|
133
|
-
resultArr = resultArr.concat(hits);
|
|
134
|
-
return [2 /*return*/, "break"];
|
|
135
|
-
}
|
|
136
|
-
_b.label = 3;
|
|
137
|
-
case 3: return [2 /*return*/];
|
|
138
|
-
}
|
|
139
|
-
});
|
|
140
|
-
};
|
|
141
|
-
this_1 = this;
|
|
142
|
-
_a.label = 2;
|
|
143
|
-
case 2:
|
|
144
|
-
if (!!done) return [3 /*break*/, 4];
|
|
145
|
-
return [5 /*yield**/, _loop_1()];
|
|
146
|
-
case 3:
|
|
147
|
-
state_1 = _a.sent();
|
|
148
|
-
if (state_1 === "break")
|
|
149
|
-
return [3 /*break*/, 4];
|
|
150
|
-
return [3 /*break*/, 2];
|
|
151
|
-
case 4:
|
|
152
|
-
// deduplicate results based on the detail column (resultArr[1])
|
|
153
|
-
return [2 /*return*/, uniqBy(resultArr, function (elt) { return elt[1]; }).slice(0, this.maxResults)];
|
|
31
|
+
search(searchString, opts) {
|
|
32
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
33
|
+
let resultArr = [];
|
|
34
|
+
const searchWords = searchString.split(' ');
|
|
35
|
+
// we only search one word at a time
|
|
36
|
+
const searchWord = searchWords[0].toLowerCase();
|
|
37
|
+
const res = yield this._getBuffer(searchWord, opts);
|
|
38
|
+
if (!res) {
|
|
39
|
+
return [];
|
|
40
|
+
}
|
|
41
|
+
let { end, buffer } = res;
|
|
42
|
+
let done = false;
|
|
43
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
44
|
+
while (!done) {
|
|
45
|
+
let foundSomething = false;
|
|
46
|
+
const str = buffer.toString();
|
|
47
|
+
// slice to lastIndexOf('\n') to make sure we get complete records
|
|
48
|
+
// since the buffer fetch could get halfway into a record
|
|
49
|
+
const lines = str
|
|
50
|
+
.slice(0, str.lastIndexOf('\n'))
|
|
51
|
+
.split('\n')
|
|
52
|
+
.filter(f => !!f);
|
|
53
|
+
const hits2 = [];
|
|
54
|
+
for (const line of lines) {
|
|
55
|
+
const word = line.split(' ')[0];
|
|
56
|
+
const match = word.startsWith(searchWord);
|
|
57
|
+
if (!foundSomething && match) {
|
|
58
|
+
foundSomething = true;
|
|
59
|
+
}
|
|
60
|
+
// we are done scanning if we are lexicographically greater than the
|
|
61
|
+
// search string
|
|
62
|
+
if (word.slice(0, searchWord.length) > searchWord) {
|
|
63
|
+
done = true;
|
|
64
|
+
}
|
|
65
|
+
if (match) {
|
|
66
|
+
hits2.push(line);
|
|
67
|
+
}
|
|
154
68
|
}
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
69
|
+
const hits = hits2.flatMap(line => {
|
|
70
|
+
const [term, ...parts] = line.split(' ');
|
|
71
|
+
return parts.map(elt => [term, elt.split(',')[0]]);
|
|
72
|
+
});
|
|
73
|
+
// if we are not done, and we haven't filled up maxResults with hits yet,
|
|
74
|
+
// then refetch
|
|
75
|
+
if (resultArr.length + hits.length < this.maxResults && !done) {
|
|
76
|
+
const res2 = yield this.ixFile.read(buffer_1.Buffer.alloc(CHUNK_SIZE), 0, CHUNK_SIZE, end, opts);
|
|
77
|
+
// early break if empty response
|
|
78
|
+
if (!res2.bytesRead) {
|
|
79
|
+
resultArr = resultArr.concat(hits);
|
|
80
|
+
break;
|
|
81
|
+
}
|
|
82
|
+
buffer = buffer_1.Buffer.concat([buffer, res2.buffer]);
|
|
83
|
+
end += CHUNK_SIZE;
|
|
84
|
+
}
|
|
85
|
+
// if we have filled up the hits, or we are detected to be done via the
|
|
86
|
+
// filtering, then return
|
|
87
|
+
else if (resultArr.length + hits.length >= this.maxResults || done) {
|
|
88
|
+
resultArr = resultArr.concat(hits);
|
|
89
|
+
break;
|
|
176
90
|
}
|
|
91
|
+
}
|
|
92
|
+
// deduplicate results based on the detail column (resultArr[1])
|
|
93
|
+
return uniqBy(resultArr, elt => elt[1]).slice(0, this.maxResults);
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
getIndex(opts) {
|
|
97
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
98
|
+
const file = yield this.ixxFile.readFile(Object.assign({ encoding: 'utf8' }, opts));
|
|
99
|
+
return file
|
|
100
|
+
.split('\n')
|
|
101
|
+
.filter(f => !!f)
|
|
102
|
+
.map(line => {
|
|
103
|
+
const p = line.length - ADDRESS_SIZE;
|
|
104
|
+
const prefix = line.slice(0, p);
|
|
105
|
+
const posStr = line.slice(p);
|
|
106
|
+
const pos = Number.parseInt(posStr, 16);
|
|
107
|
+
return [prefix, pos];
|
|
177
108
|
});
|
|
178
109
|
});
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
indexes = _b.sent();
|
|
191
|
-
for (i = 0; i < indexes.length; i++) {
|
|
192
|
-
_a = indexes[i], key = _a[0], value = _a[1];
|
|
193
|
-
trimmedKey = key.slice(0, searchWord.length);
|
|
194
|
-
if (trimmedKey < searchWord) {
|
|
195
|
-
start = value;
|
|
196
|
-
end = value + 65536;
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
len = end - start;
|
|
200
|
-
if (len < 0) {
|
|
201
|
-
return [2 /*return*/, undefined];
|
|
202
|
-
}
|
|
203
|
-
return [4 /*yield*/, this.ixFile.read(Buffer.alloc(len), 0, len, start, opts)];
|
|
204
|
-
case 2:
|
|
205
|
-
res = _b.sent();
|
|
206
|
-
return [2 /*return*/, __assign(__assign({}, res), { end: end })];
|
|
110
|
+
}
|
|
111
|
+
_getBuffer(searchWord, opts) {
|
|
112
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
113
|
+
let start = 0;
|
|
114
|
+
let end = 65536;
|
|
115
|
+
const indexes = yield this.getIndex(opts);
|
|
116
|
+
for (const [key, value] of indexes) {
|
|
117
|
+
const trimmedKey = key.slice(0, searchWord.length);
|
|
118
|
+
if (trimmedKey < searchWord) {
|
|
119
|
+
start = value;
|
|
120
|
+
end = value + 65536;
|
|
207
121
|
}
|
|
208
|
-
}
|
|
122
|
+
}
|
|
123
|
+
// Return the buffer and its end position in the file.
|
|
124
|
+
const len = end - start;
|
|
125
|
+
if (len < 0) {
|
|
126
|
+
return undefined;
|
|
127
|
+
}
|
|
128
|
+
const res = yield this.ixFile.read(buffer_1.Buffer.alloc(len), 0, len, start, opts);
|
|
129
|
+
return Object.assign(Object.assign({}, res), { end });
|
|
209
130
|
});
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
}());
|
|
131
|
+
}
|
|
132
|
+
}
|
|
213
133
|
exports.default = Trix;
|
|
214
134
|
//# 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,mCAA+B;AAG/B,MAAM,UAAU,GAAG,KAAK,CAAA;AAExB,4EAA4E;AAC5E,iEAAiE;AACjE,MAAM,YAAY,GAAG,EAAE,CAAA;AAEvB,8CAA8C;AAC9C,SAAS,MAAM,CAAI,CAAM,EAAE,GAAuB;IAChD,MAAM,IAAI,GAAG,IAAI,GAAG,EAAE,CAAA;IACtB,OAAO,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE;QACrB,MAAM,CAAC,GAAG,GAAG,CAAC,IAAI,CAAC,CAAA;QACnB,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAA;IAC1C,CAAC,CAAC,CAAA;AACJ,CAAC;AAED,MAAqB,IAAI;IACvB,YACS,OAA0B,EAC1B,MAAyB,EACzB,aAAa,EAAE;QAFf,YAAO,GAAP,OAAO,CAAmB;QAC1B,WAAM,GAAN,MAAM,CAAmB;QACzB,eAAU,GAAV,UAAU,CAAK;IACrB,CAAC;IAEE,MAAM,CAAC,YAAoB,EAAE,IAA+B;;YAChE,IAAI,SAAS,GAAG,EAAwB,CAAA;YACxC,MAAM,WAAW,GAAG,YAAY,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;YAE3C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D,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,GAAG,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,eAAM,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,GAAG,EAAE,KAAK,EAAE,IAAI,CAAC,CAAA;YAC1E,uCACK,GAAG,KACN,GAAG,IACJ;QACH,CAAC;KAAA;CACF;AAjID,uBAiIC"}
|
package/esm/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { GenericFilehandle } from 'generic-filehandle';
|
|
2
2
|
export default class Trix {
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
ixxFile: GenericFilehandle;
|
|
4
|
+
ixFile: GenericFilehandle;
|
|
5
5
|
maxResults: number;
|
|
6
6
|
constructor(ixxFile: GenericFilehandle, ixFile: GenericFilehandle, maxResults?: number);
|
|
7
7
|
search(searchString: string, opts?: {
|
package/esm/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Buffer } from 'buffer';
|
|
1
2
|
const CHUNK_SIZE = 65536;
|
|
2
3
|
// this is the number of hex characters to use for the address in ixixx, see
|
|
3
4
|
// https://github.com/GMOD/ixixx-js/blob/master/src/index.ts#L182
|
|
@@ -11,9 +12,12 @@ function uniqBy(a, key) {
|
|
|
11
12
|
});
|
|
12
13
|
}
|
|
13
14
|
export default class Trix {
|
|
15
|
+
ixxFile;
|
|
16
|
+
ixFile;
|
|
17
|
+
maxResults;
|
|
14
18
|
constructor(ixxFile, ixFile, maxResults = 20) {
|
|
15
|
-
this.ixFile = ixFile;
|
|
16
19
|
this.ixxFile = ixxFile;
|
|
20
|
+
this.ixFile = ixFile;
|
|
17
21
|
this.maxResults = maxResults;
|
|
18
22
|
}
|
|
19
23
|
async search(searchString, opts) {
|
|
@@ -27,6 +31,7 @@ export default class Trix {
|
|
|
27
31
|
}
|
|
28
32
|
let { end, buffer } = res;
|
|
29
33
|
let done = false;
|
|
34
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
30
35
|
while (!done) {
|
|
31
36
|
let foundSomething = false;
|
|
32
37
|
const str = buffer.toString();
|
|
@@ -36,9 +41,8 @@ export default class Trix {
|
|
|
36
41
|
.slice(0, str.lastIndexOf('\n'))
|
|
37
42
|
.split('\n')
|
|
38
43
|
.filter(f => !!f);
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
.filter(line => {
|
|
44
|
+
const hits2 = [];
|
|
45
|
+
for (const line of lines) {
|
|
42
46
|
const word = line.split(' ')[0];
|
|
43
47
|
const match = word.startsWith(searchWord);
|
|
44
48
|
if (!foundSomething && match) {
|
|
@@ -49,17 +53,17 @@ export default class Trix {
|
|
|
49
53
|
if (word.slice(0, searchWord.length) > searchWord) {
|
|
50
54
|
done = true;
|
|
51
55
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
56
|
+
if (match) {
|
|
57
|
+
hits2.push(line);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
const hits = hits2.flatMap(line => {
|
|
55
61
|
const [term, ...parts] = line.split(' ');
|
|
56
62
|
return parts.map(elt => [term, elt.split(',')[0]]);
|
|
57
|
-
})
|
|
58
|
-
.flat();
|
|
63
|
+
});
|
|
59
64
|
// if we are not done, and we haven't filled up maxResults with hits yet,
|
|
60
65
|
// then refetch
|
|
61
66
|
if (resultArr.length + hits.length < this.maxResults && !done) {
|
|
62
|
-
// eslint-disable-next-line no-await-in-loop
|
|
63
67
|
const res2 = await this.ixFile.read(Buffer.alloc(CHUNK_SIZE), 0, CHUNK_SIZE, end, opts);
|
|
64
68
|
// early break if empty response
|
|
65
69
|
if (!res2.bytesRead) {
|
|
@@ -99,8 +103,7 @@ export default class Trix {
|
|
|
99
103
|
let start = 0;
|
|
100
104
|
let end = 65536;
|
|
101
105
|
const indexes = await this.getIndex(opts);
|
|
102
|
-
for (
|
|
103
|
-
const [key, value] = indexes[i];
|
|
106
|
+
for (const [key, value] of indexes) {
|
|
104
107
|
const trimmedKey = key.slice(0, searchWord.length);
|
|
105
108
|
if (trimmedKey < searchWord) {
|
|
106
109
|
start = value;
|
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,QAAQ,CAAA;AAG/B,MAAM,UAAU,GAAG,KAAK,CAAA;AAExB,4EAA4E;AAC5E,iEAAiE;AACjE,MAAM,YAAY,GAAG,EAAE,CAAA;AAEvB,8CAA8C;AAC9C,SAAS,MAAM,CAAI,CAAM,EAAE,GAAuB;IAChD,MAAM,IAAI,GAAG,IAAI,GAAG,EAAE,CAAA;IACtB,OAAO,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE;QACrB,MAAM,CAAC,GAAG,GAAG,CAAC,IAAI,CAAC,CAAA;QACnB,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAA;IAC1C,CAAC,CAAC,CAAA;AACJ,CAAC;AAED,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,e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CAAC,IAAI,CAAC,CAAA;QACzC,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,OAAO,EAAE,CAAC;YACnC,MAAM,UAAU,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,UAAU,CAAC,MAAM,CAAC,CAAA;YAClD,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,GAAG,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,GAAG,EAAE,KAAK,EAAE,IAAI,CAAC,CAAA;QAC1E,OAAO;YACL,GAAG,GAAG;YACN,GAAG;SACJ,CAAA;IACH,CAAC;CACF"}
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "2.0.
|
|
2
|
+
"version": "2.0.7",
|
|
3
3
|
"license": "Apache-2.0",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"module": "esm/index.js",
|
|
@@ -12,37 +12,34 @@
|
|
|
12
12
|
"node": ">=10"
|
|
13
13
|
},
|
|
14
14
|
"scripts": {
|
|
15
|
-
"lint": "eslint --report-unused-disable-directives --max-warnings 0
|
|
15
|
+
"lint": "eslint --report-unused-disable-directives --max-warnings 0",
|
|
16
16
|
"prebuild": "rimraf dist esm",
|
|
17
|
-
"build:esm": "tsc --target
|
|
18
|
-
"build:es5": "tsc --target
|
|
17
|
+
"build:esm": "tsc --target esnext --outDir esm",
|
|
18
|
+
"build:es5": "tsc --target es2015 --outDir dist --module commonjs",
|
|
19
19
|
"build": "npm run build:esm && npm run build:es5",
|
|
20
|
-
"preversion": "npm run lint && npm test && npm run build",
|
|
20
|
+
"preversion": "npm run lint && npm test run && npm run build",
|
|
21
21
|
"postversion": "git push --follow-tags",
|
|
22
|
-
"test": "
|
|
22
|
+
"test": "vitest"
|
|
23
23
|
},
|
|
24
24
|
"name": "@gmod/trix",
|
|
25
25
|
"author": "Matt Morgan",
|
|
26
26
|
"repository": "GMOD/trix-js",
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"@types/
|
|
29
|
-
"@
|
|
30
|
-
"@typescript-eslint/
|
|
31
|
-
"
|
|
32
|
-
"eslint": "^
|
|
33
|
-
"eslint-config-airbnb-base": "^15.0.0",
|
|
34
|
-
"eslint-config-airbnb-typescript": "^17.0.0",
|
|
35
|
-
"eslint-config-prettier": "^8.3.0",
|
|
36
|
-
"eslint-plugin-import": "^2.26.0",
|
|
37
|
-
"eslint-plugin-prettier": "^4.2.1",
|
|
28
|
+
"@types/node": "^20.14.11",
|
|
29
|
+
"@typescript-eslint/eslint-plugin": "^8.4.0",
|
|
30
|
+
"@typescript-eslint/parser": "^8.4.0",
|
|
31
|
+
"eslint": "^9.0.0",
|
|
32
|
+
"eslint-plugin-unicorn": "^55.0.0",
|
|
38
33
|
"generic-filehandle": "^3.0.0",
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
"
|
|
34
|
+
"prettier": "^3.3.3",
|
|
35
|
+
"rimraf": "^6.0.1",
|
|
36
|
+
"typescript": "^5.5.3",
|
|
37
|
+
"typescript-eslint": "^8.4.0",
|
|
38
|
+
"vitest": "^2.0.5"
|
|
39
|
+
},
|
|
40
|
+
"dependencies": {
|
|
41
|
+
"buffer": "^6.0.3"
|
|
44
42
|
},
|
|
45
|
-
"dependencies": {},
|
|
46
43
|
"publishConfig": {
|
|
47
44
|
"access": "public"
|
|
48
45
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Buffer } from 'buffer'
|
|
1
2
|
import type { GenericFilehandle } from 'generic-filehandle'
|
|
2
3
|
|
|
3
4
|
const CHUNK_SIZE = 65536
|
|
@@ -16,21 +17,11 @@ function uniqBy<T>(a: T[], key: (elt: T) => string) {
|
|
|
16
17
|
}
|
|
17
18
|
|
|
18
19
|
export default class Trix {
|
|
19
|
-
private ixFile: GenericFilehandle
|
|
20
|
-
|
|
21
|
-
private ixxFile: GenericFilehandle
|
|
22
|
-
|
|
23
|
-
maxResults: number
|
|
24
|
-
|
|
25
20
|
constructor(
|
|
26
|
-
ixxFile: GenericFilehandle,
|
|
27
|
-
ixFile: GenericFilehandle,
|
|
28
|
-
maxResults = 20,
|
|
29
|
-
) {
|
|
30
|
-
this.ixFile = ixFile
|
|
31
|
-
this.ixxFile = ixxFile
|
|
32
|
-
this.maxResults = maxResults
|
|
33
|
-
}
|
|
21
|
+
public ixxFile: GenericFilehandle,
|
|
22
|
+
public ixFile: GenericFilehandle,
|
|
23
|
+
public maxResults = 20,
|
|
24
|
+
) {}
|
|
34
25
|
|
|
35
26
|
async search(searchString: string, opts?: { signal?: AbortSignal }) {
|
|
36
27
|
let resultArr = [] as [string, string][]
|
|
@@ -45,6 +36,7 @@ export default class Trix {
|
|
|
45
36
|
|
|
46
37
|
let { end, buffer } = res
|
|
47
38
|
let done = false
|
|
39
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
48
40
|
while (!done) {
|
|
49
41
|
let foundSomething = false
|
|
50
42
|
const str = buffer.toString()
|
|
@@ -56,32 +48,31 @@ export default class Trix {
|
|
|
56
48
|
.split('\n')
|
|
57
49
|
.filter(f => !!f)
|
|
58
50
|
|
|
59
|
-
const
|
|
60
|
-
|
|
61
|
-
.
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
51
|
+
const hits2 = [] as string[]
|
|
52
|
+
for (const line of lines) {
|
|
53
|
+
const word = line.split(' ')[0]
|
|
54
|
+
const match = word.startsWith(searchWord)
|
|
55
|
+
if (!foundSomething && match) {
|
|
56
|
+
foundSomething = true
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// we are done scanning if we are lexicographically greater than the
|
|
60
|
+
// search string
|
|
61
|
+
if (word.slice(0, searchWord.length) > searchWord) {
|
|
62
|
+
done = true
|
|
63
|
+
}
|
|
64
|
+
if (match) {
|
|
65
|
+
hits2.push(line)
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
const hits = hits2.flatMap(line => {
|
|
69
|
+
const [term, ...parts] = line.split(' ')
|
|
70
|
+
return parts.map(elt => [term, elt.split(',')[0]] as [string, string])
|
|
71
|
+
})
|
|
80
72
|
|
|
81
73
|
// if we are not done, and we haven't filled up maxResults with hits yet,
|
|
82
74
|
// then refetch
|
|
83
75
|
if (resultArr.length + hits.length < this.maxResults && !done) {
|
|
84
|
-
// eslint-disable-next-line no-await-in-loop
|
|
85
76
|
const res2 = await this.ixFile.read(
|
|
86
77
|
Buffer.alloc(CHUNK_SIZE),
|
|
87
78
|
0,
|
|
@@ -124,7 +115,7 @@ export default class Trix {
|
|
|
124
115
|
const prefix = line.slice(0, p)
|
|
125
116
|
const posStr = line.slice(p)
|
|
126
117
|
const pos = Number.parseInt(posStr, 16)
|
|
127
|
-
return [prefix, pos] as
|
|
118
|
+
return [prefix, pos] as const
|
|
128
119
|
})
|
|
129
120
|
}
|
|
130
121
|
|
|
@@ -135,8 +126,7 @@ export default class Trix {
|
|
|
135
126
|
let start = 0
|
|
136
127
|
let end = 65536
|
|
137
128
|
const indexes = await this.getIndex(opts)
|
|
138
|
-
for (
|
|
139
|
-
const [key, value] = indexes[i]
|
|
129
|
+
for (const [key, value] of indexes) {
|
|
140
130
|
const trimmedKey = key.slice(0, searchWord.length)
|
|
141
131
|
if (trimmedKey < searchWord) {
|
|
142
132
|
start = value
|