@gmod/trix 2.0.6 → 2.0.8

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 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,126 @@ 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 CHUNK_SIZE = 65536;
51
13
  // this is the number of hex characters to use for the address in ixixx, see
52
14
  // https://github.com/GMOD/ixixx-js/blob/master/src/index.ts#L182
53
- var ADDRESS_SIZE = 10;
15
+ const ADDRESS_SIZE = 10;
54
16
  // https://stackoverflow.com/a/9229821/2129219
55
17
  function uniqBy(a, key) {
56
- var seen = new Set();
57
- return a.filter(function (item) {
58
- var k = key(item);
18
+ const seen = new Set();
19
+ return a.filter(item => {
20
+ const k = key(item);
59
21
  return seen.has(k) ? false : seen.add(k);
60
22
  });
61
23
  }
62
- var Trix = /** @class */ (function () {
63
- function Trix(ixxFile, ixFile, maxResults) {
64
- if (maxResults === void 0) { maxResults = 20; }
65
- this.ixFile = ixFile;
24
+ class Trix {
25
+ constructor(ixxFile, ixFile, maxResults = 20) {
66
26
  this.ixxFile = ixxFile;
27
+ this.ixFile = ixFile;
67
28
  this.maxResults = maxResults;
68
29
  }
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)];
30
+ search(searchString, opts) {
31
+ return __awaiter(this, void 0, void 0, function* () {
32
+ let resultArr = [];
33
+ const searchWords = searchString.split(' ');
34
+ // we only search one word at a time
35
+ const searchWord = searchWords[0].toLowerCase();
36
+ const res = yield this._getBuffer(searchWord, opts);
37
+ if (!res) {
38
+ return [];
39
+ }
40
+ let { end, buffer } = res;
41
+ let done = false;
42
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
43
+ while (!done) {
44
+ let foundSomething = false;
45
+ const str = buffer.toString();
46
+ // slice to lastIndexOf('\n') to make sure we get complete records
47
+ // since the buffer fetch could get halfway into a record
48
+ const lines = str
49
+ .slice(0, str.lastIndexOf('\n'))
50
+ .split('\n')
51
+ .filter(f => !!f);
52
+ const hits2 = [];
53
+ for (const line of lines) {
54
+ const word = line.split(' ')[0];
55
+ const match = word.startsWith(searchWord);
56
+ if (!foundSomething && match) {
57
+ foundSomething = true;
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
+ }
154
67
  }
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
- })];
68
+ const hits = hits2.flatMap(line => {
69
+ const [term, ...parts] = line.split(' ');
70
+ return parts.map(elt => [term, elt.split(',')[0]]);
71
+ });
72
+ // if we are not done, and we haven't filled up maxResults with hits yet,
73
+ // then refetch
74
+ if (resultArr.length + hits.length < this.maxResults && !done) {
75
+ const res2 = yield this.ixFile.read(Buffer.alloc(CHUNK_SIZE), 0, CHUNK_SIZE, end, opts);
76
+ // early break if empty response
77
+ if (!res2.bytesRead) {
78
+ resultArr = resultArr.concat(hits);
79
+ break;
80
+ }
81
+ buffer = Buffer.concat([buffer, res2.buffer]);
82
+ end += CHUNK_SIZE;
83
+ }
84
+ // if we have filled up the hits, or we are detected to be done via the
85
+ // filtering, then return
86
+ else if (resultArr.length + hits.length >= this.maxResults || done) {
87
+ resultArr = resultArr.concat(hits);
88
+ break;
176
89
  }
90
+ }
91
+ // deduplicate results based on the detail column (resultArr[1])
92
+ return uniqBy(resultArr, elt => elt[1]).slice(0, this.maxResults);
93
+ });
94
+ }
95
+ getIndex(opts) {
96
+ return __awaiter(this, void 0, void 0, function* () {
97
+ const file = yield this.ixxFile.readFile(Object.assign({ encoding: 'utf8' }, opts));
98
+ return file
99
+ .split('\n')
100
+ .filter(f => !!f)
101
+ .map(line => {
102
+ const p = line.length - ADDRESS_SIZE;
103
+ const prefix = line.slice(0, p);
104
+ const posStr = line.slice(p);
105
+ const pos = Number.parseInt(posStr, 16);
106
+ return [prefix, pos];
177
107
  });
178
108
  });
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 })];
109
+ }
110
+ _getBuffer(searchWord, opts) {
111
+ return __awaiter(this, void 0, void 0, function* () {
112
+ let start = 0;
113
+ let end = 65536;
114
+ const indexes = yield this.getIndex(opts);
115
+ for (const [key, value] of indexes) {
116
+ const trimmedKey = key.slice(0, searchWord.length);
117
+ if (trimmedKey < searchWord) {
118
+ start = value;
119
+ end = value + 65536;
207
120
  }
208
- });
121
+ }
122
+ // Return the buffer and its end position in the file.
123
+ const len = end - start;
124
+ if (len < 0) {
125
+ return undefined;
126
+ }
127
+ const res = yield this.ixFile.read(Buffer.alloc(len), 0, len, start, opts);
128
+ return Object.assign(Object.assign({}, res), { end });
209
129
  });
210
- };
211
- return Trix;
212
- }());
130
+ }
131
+ }
213
132
  exports.default = Trix;
214
133
  //# 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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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AAI,CAAC,MAAM,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
@@ -11,9 +11,12 @@ function uniqBy(a, key) {
11
11
  });
12
12
  }
13
13
  export default class Trix {
14
+ ixxFile;
15
+ ixFile;
16
+ maxResults;
14
17
  constructor(ixxFile, ixFile, maxResults = 20) {
15
- this.ixFile = ixFile;
16
18
  this.ixxFile = ixxFile;
19
+ this.ixFile = ixFile;
17
20
  this.maxResults = maxResults;
18
21
  }
19
22
  async search(searchString, opts) {
@@ -27,6 +30,7 @@ export default class Trix {
27
30
  }
28
31
  let { end, buffer } = res;
29
32
  let done = false;
33
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
30
34
  while (!done) {
31
35
  let foundSomething = false;
32
36
  const str = buffer.toString();
@@ -36,9 +40,8 @@ export default class Trix {
36
40
  .slice(0, str.lastIndexOf('\n'))
37
41
  .split('\n')
38
42
  .filter(f => !!f);
39
- const hits = lines
40
- // eslint-disable-next-line @typescript-eslint/no-loop-func
41
- .filter(line => {
43
+ const hits2 = [];
44
+ for (const line of lines) {
42
45
  const word = line.split(' ')[0];
43
46
  const match = word.startsWith(searchWord);
44
47
  if (!foundSomething && match) {
@@ -49,17 +52,17 @@ export default class Trix {
49
52
  if (word.slice(0, searchWord.length) > searchWord) {
50
53
  done = true;
51
54
  }
52
- return match;
53
- })
54
- .map(line => {
55
+ if (match) {
56
+ hits2.push(line);
57
+ }
58
+ }
59
+ const hits = hits2.flatMap(line => {
55
60
  const [term, ...parts] = line.split(' ');
56
61
  return parts.map(elt => [term, elt.split(',')[0]]);
57
- })
58
- .flat();
62
+ });
59
63
  // if we are not done, and we haven't filled up maxResults with hits yet,
60
64
  // then refetch
61
65
  if (resultArr.length + hits.length < this.maxResults && !done) {
62
- // eslint-disable-next-line no-await-in-loop
63
66
  const res2 = await this.ixFile.read(Buffer.alloc(CHUNK_SIZE), 0, CHUNK_SIZE, end, opts);
64
67
  // early break if empty response
65
68
  if (!res2.bytesRead) {
@@ -99,8 +102,7 @@ export default class Trix {
99
102
  let start = 0;
100
103
  let end = 65536;
101
104
  const indexes = await this.getIndex(opts);
102
- for (let i = 0; i < indexes.length; i++) {
103
- const [key, value] = indexes[i];
105
+ for (const [key, value] of indexes) {
104
106
  const trimmedKey = key.slice(0, searchWord.length);
105
107
  if (trimmedKey < searchWord) {
106
108
  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,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,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EAAE,CAAC,CAAA;YACvC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAU,CAAA;QAC/B,CAAC,CAAC,CAAA;IACN,CAAC;IAEO,KAAK,CAAC,UAAU,CACtB,UAAkB,EAClB,IAA+B;QAE/B,IAAI,KAAK,GAAG,CAAC,CAAA;QACb,IAAI,GAAG,GAAG,KAAK,CAAA;QACf,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,QAAQ,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.6",
2
+ "version": "2.0.8",
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
@@ -16,21 +16,11 @@ function uniqBy<T>(a: T[], key: (elt: T) => string) {
16
16
  }
17
17
 
18
18
  export default class Trix {
19
- private ixFile: GenericFilehandle
20
-
21
- private ixxFile: GenericFilehandle
22
-
23
- maxResults: number
24
-
25
19
  constructor(
26
- ixxFile: GenericFilehandle,
27
- ixFile: GenericFilehandle,
28
- maxResults = 20,
29
- ) {
30
- this.ixFile = ixFile
31
- this.ixxFile = ixxFile
32
- this.maxResults = maxResults
33
- }
20
+ public ixxFile: GenericFilehandle,
21
+ public ixFile: GenericFilehandle,
22
+ public maxResults = 20,
23
+ ) {}
34
24
 
35
25
  async search(searchString: string, opts?: { signal?: AbortSignal }) {
36
26
  let resultArr = [] as [string, string][]
@@ -45,6 +35,7 @@ export default class Trix {
45
35
 
46
36
  let { end, buffer } = res
47
37
  let done = false
38
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
48
39
  while (!done) {
49
40
  let foundSomething = false
50
41
  const str = buffer.toString()
@@ -56,32 +47,31 @@ export default class Trix {
56
47
  .split('\n')
57
48
  .filter(f => !!f)
58
49
 
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][]
50
+ const hits2 = [] as string[]
51
+ for (const line of lines) {
52
+ const word = line.split(' ')[0]
53
+ const match = word.startsWith(searchWord)
54
+ if (!foundSomething && match) {
55
+ foundSomething = true
56
+ }
57
+
58
+ // we are done scanning if we are lexicographically greater than the
59
+ // search string
60
+ if (word.slice(0, searchWord.length) > searchWord) {
61
+ done = true
62
+ }
63
+ if (match) {
64
+ hits2.push(line)
65
+ }
66
+ }
67
+ const hits = hits2.flatMap(line => {
68
+ const [term, ...parts] = line.split(' ')
69
+ return parts.map(elt => [term, elt.split(',')[0]] as [string, string])
70
+ })
80
71
 
81
72
  // if we are not done, and we haven't filled up maxResults with hits yet,
82
73
  // then refetch
83
74
  if (resultArr.length + hits.length < this.maxResults && !done) {
84
- // eslint-disable-next-line no-await-in-loop
85
75
  const res2 = await this.ixFile.read(
86
76
  Buffer.alloc(CHUNK_SIZE),
87
77
  0,
@@ -124,7 +114,7 @@ export default class Trix {
124
114
  const prefix = line.slice(0, p)
125
115
  const posStr = line.slice(p)
126
116
  const pos = Number.parseInt(posStr, 16)
127
- return [prefix, pos] as [string, number]
117
+ return [prefix, pos] as const
128
118
  })
129
119
  }
130
120
 
@@ -135,8 +125,7 @@ export default class Trix {
135
125
  let start = 0
136
126
  let end = 65536
137
127
  const indexes = await this.getIndex(opts)
138
- for (let i = 0; i < indexes.length; i++) {
139
- const [key, value] = indexes[i]
128
+ for (const [key, value] of indexes) {
140
129
  const trimmedKey = key.slice(0, searchWord.length)
141
130
  if (trimmedKey < searchWord) {
142
131
  start = value