@gmod/trix 2.0.5 → 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/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ # v2.0.6
2
+
3
+ - Re-publish v2.0.5 to npm
4
+
1
5
  # v2.0.5
2
6
 
3
7
  - Improve prefix searches
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
- private ixFile;
4
- private ixxFile;
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
- var CHUNK_SIZE = 65536;
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
- var ADDRESS_SIZE = 10;
16
+ const ADDRESS_SIZE = 10;
54
17
  // https://stackoverflow.com/a/9229821/2129219
55
18
  function uniqBy(a, key) {
56
- var seen = new Set();
57
- return a.filter(function (item) {
58
- var k = key(item);
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
- var Trix = /** @class */ (function () {
63
- function Trix(ixxFile, ixFile, maxResults) {
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
- Trix.prototype.search = function (searchString, opts) {
70
- return __awaiter(this, void 0, void 0, function () {
71
- var resultArr, searchWords, searchWord, res, end, buffer, done, _loop_1, this_1, state_1;
72
- return __generator(this, function (_a) {
73
- switch (_a.label) {
74
- case 0:
75
- resultArr = [];
76
- searchWords = searchString.split(' ');
77
- searchWord = searchWords[0].toLowerCase();
78
- return [4 /*yield*/, this._getBuffer(searchWord, opts)];
79
- case 1:
80
- res = _a.sent();
81
- if (!res) {
82
- return [2 /*return*/, []];
83
- }
84
- end = res.end, buffer = res.buffer;
85
- done = false;
86
- _loop_1 = function () {
87
- var foundSomething, str, lines, hits, res2;
88
- return __generator(this, function (_b) {
89
- switch (_b.label) {
90
- case 0:
91
- foundSomething = false;
92
- str = buffer.toString();
93
- lines = str
94
- .slice(0, str.lastIndexOf('\n'))
95
- .split('\n')
96
- .filter(function (f) { return !!f; });
97
- hits = lines
98
- // eslint-disable-next-line @typescript-eslint/no-loop-func
99
- .filter(function (line) {
100
- var word = line.split(' ')[0];
101
- var match = word.startsWith(searchWord);
102
- if (!foundSomething && match) {
103
- foundSomething = true;
104
- }
105
- // we are done scanning if we are lexicographically greater than the
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
- Trix.prototype.getIndex = function (opts) {
159
- return __awaiter(this, void 0, void 0, function () {
160
- var file;
161
- return __generator(this, function (_a) {
162
- switch (_a.label) {
163
- case 0: return [4 /*yield*/, this.ixxFile.readFile(__assign({ encoding: 'utf8' }, opts))];
164
- case 1:
165
- file = _a.sent();
166
- return [2 /*return*/, file
167
- .split('\n')
168
- .filter(function (f) { return !!f; })
169
- .map(function (line) {
170
- var p = line.length - ADDRESS_SIZE;
171
- var prefix = line.slice(0, p);
172
- var posStr = line.slice(p);
173
- var pos = Number.parseInt(posStr, 16);
174
- return [prefix, pos];
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
- Trix.prototype._getBuffer = function (searchWord, opts) {
181
- return __awaiter(this, void 0, void 0, function () {
182
- var start, end, indexes, i, _a, key, value, trimmedKey, len, res;
183
- return __generator(this, function (_b) {
184
- switch (_b.label) {
185
- case 0:
186
- start = 0;
187
- end = 65536;
188
- return [4 /*yield*/, this.getIndex(opts)];
189
- case 1:
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
- return Trix;
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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,IAAM,UAAU,GAAG,KAAK,CAAA;AAExB,4EAA4E;AAC5E,iEAAiE;AACjE,IAAM,YAAY,GAAG,EAAE,CAAA;AAEvB,8CAA8C;AAC9C,SAAS,MAAM,CAAI,CAAM,EAAE,GAAuB;IAChD,IAAM,IAAI,GAAG,IAAI,GAAG,EAAE,CAAA;IACtB,OAAO,CAAC,CAAC,MAAM,CAAC,UAAA,IAAI;QAClB,IAAM,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;IAOE,cACE,OAA0B,EAC1B,MAAyB,EACzB,UAAe;QAAf,2BAAA,EAAA,eAAe;QAEf,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACtB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAA;IAC9B,CAAC;IAEK,qBAAM,GAAZ,UAAa,YAAoB,EAAE,IAA+B;;;;;;wBAC5D,SAAS,GAAG,EAAwB,CAAA;wBAClC,WAAW,GAAG,YAAY,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;wBAGrC,UAAU,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,CAAA;wBACnC,qBAAM,IAAI,CAAC,UAAU,CAAC,UAAU,EAAE,IAAI,CAAC,EAAA;;wBAA7C,GAAG,GAAG,SAAuC;wBACnD,IAAI,CAAC,GAAG,EAAE;4BACR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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
- private ixFile;
4
- private ixxFile;
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 hits = lines
40
- // eslint-disable-next-line @typescript-eslint/no-loop-func
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
- return match;
53
- })
54
- .map(line => {
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 (let i = 0; i < indexes.length; i++) {
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":"AAEA,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,IAA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AE,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.5",
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 --ext .js,.ts src ",
15
+ "lint": "eslint --report-unused-disable-directives --max-warnings 0",
16
16
  "prebuild": "rimraf dist esm",
17
- "build:esm": "tsc --target es2018 --outDir esm --module es2020",
18
- "build:es5": "tsc --target es5 --outDir dist --module commonjs",
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": "jest"
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/jest": "^29.2.4",
29
- "@types/node": "^18.11.16",
30
- "@typescript-eslint/eslint-plugin": "^5.46.1",
31
- "@typescript-eslint/parser": "^5.46.1",
32
- "eslint": "^8.29.0",
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
- "jest": "^29.3.1",
40
- "prettier": "^2.8.1",
41
- "rimraf": "^3.0.2",
42
- "ts-jest": "^29.0.3",
43
- "typescript": "^4.9.4"
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 hits = lines
60
- // eslint-disable-next-line @typescript-eslint/no-loop-func
61
- .filter(line => {
62
- const word = line.split(' ')[0]
63
- const match = word.startsWith(searchWord)
64
- if (!foundSomething && match) {
65
- foundSomething = true
66
- }
67
-
68
- // we are done scanning if we are lexicographically greater than the
69
- // search string
70
- if (word.slice(0, searchWord.length) > searchWord) {
71
- done = true
72
- }
73
- return match
74
- })
75
- .map(line => {
76
- const [term, ...parts] = line.split(' ')
77
- return parts.map(elt => [term, elt.split(',')[0]])
78
- })
79
- .flat() as [string, string][]
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 [string, number]
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 (let i = 0; i < indexes.length; i++) {
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