@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 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 = JSON.stringify) {
6
- const clone = [];
7
- const lookup = new Set();
8
- for (const entry of list) {
9
- const hashed = hasher(entry);
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);
@@ -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,MAAM,KAAK,GAAQ,EAAE,CAAA;IACrB,MAAM,MAAM,GAAG,IAAI,GAAG,EAAU,CAAA;IAEhC,KAAK,MAAM,KAAK,IAAI,IAAI,EAAE,CAAC;QACzB,MAAM,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,CAAA;QAE5B,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC;YACxB,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;YACjB,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,CAAA;QACpB,CAAC;IACH,CAAC;IAED,OAAO,KAAK,CAAA;AACd,CAAC"}
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 _getBuffer;
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
- const dedupe_ts_1 = require("./dedupe.js");
13
- const util_ts_1 = require("./util.js");
14
- const CHUNK_SIZE = 65536;
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
- const ADDRESS_SIZE = 10;
18
- class Trix {
19
- 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; }
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
- let resultArr = [];
27
- const searchWords = searchString.split(' ');
28
- // we only search one word at a time
29
- const searchWord = searchWords[0].toLowerCase();
30
- const res = yield this._getBuffer(searchWord, opts);
31
- if (!res) {
32
- return [];
33
- }
34
- let { end, buffer } = res;
35
- let done = false;
36
- const decoder = new TextDecoder('utf8');
37
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
38
- while (!done) {
39
- let foundSomething = false;
40
- const str = decoder.decode(buffer);
41
- // slice to lastIndexOf('\n') to make sure we get complete records
42
- // since the buffer fetch could get halfway into a record
43
- const lines = str
44
- .slice(0, str.lastIndexOf('\n'))
45
- .split('\n')
46
- .filter(f => !!f);
47
- const hits2 = [];
48
- for (const line of lines) {
49
- const word = line.split(' ')[0];
50
- const match = word.startsWith(searchWord);
51
- if (!foundSomething && match) {
52
- foundSomething = true;
53
- }
54
- // we are done scanning if we are lexicographically greater than the
55
- // search string
56
- if (word.slice(0, searchWord.length) > searchWord) {
57
- done = true;
58
- }
59
- if (match) {
60
- hits2.push(line);
61
- }
62
- }
63
- const hits = hits2.flatMap(line => {
64
- const [term, ...parts] = line.split(' ');
65
- return parts.map(elt => [term, elt.split(',')[0]]);
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
- buffer = (0, util_ts_1.concatUint8Array)([buffer, res2]);
77
- end += CHUNK_SIZE;
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
- // if we have filled up the hits, or we are detected to be done via the
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
- const file = yield this.ixxFile.readFile(Object.assign({ encoding: 'utf8' }, opts));
93
- return file
94
- .split('\n')
95
- .filter(f => !!f)
96
- .map(line => {
97
- const p = line.length - ADDRESS_SIZE;
98
- const prefix = line.slice(0, p);
99
- const posStr = line.slice(p);
100
- const pos = Number.parseInt(posStr, 16);
101
- return [prefix, pos];
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
- _getBuffer(searchWord, opts) {
106
- return __awaiter(this, void 0, void 0, function* () {
107
- let start = 0;
108
- let end = 65536;
109
- const indexes = yield this.getIndex(opts);
110
- for (const [key, value] of indexes) {
111
- const trimmedKey = key.slice(0, searchWord.length);
112
- if (trimmedKey < searchWord) {
113
- start = value;
114
- end = value + 65536;
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":";;;;;;;;;;;AAAA,2CAAoC;AACpC,uCAA4C;AAI5C,MAAM,UAAU,GAAG,KAAK,CAAA;AAExB,4EAA4E;AAC5E,iEAAiE;AACjE,MAAM,YAAY,GAAG,EAAE,CAAA;AAEvB,MAAqB,IAAI;IACvB,YACS,OAA0B,EAC1B,MAAyB,EACzB,aAAa,EAAE;QAFf,YAAO,GAAP,OAAO,CAAmB;QAC1B,WAAM,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,oCAAoC;YACpC,MAAM,UAAU,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,CAAA;YAC/C,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,UAAU,EAAE,IAAI,CAAC,CAAA;YACnD,IAAI,CAAC,GAAG,EAAE,CAAC;gBACT,OAAO,EAAE,CAAA;YACX,CAAC;YAED,IAAI,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,GAAG,CAAA;YACzB,IAAI,IAAI,GAAG,KAAK,CAAA;YAChB,MAAM,OAAO,GAAG,IAAI,WAAW,CAAC,MAAM,CAAC,CAAA;YACvC,uEAAuE;YACvE,OAAO,CAAC,IAAI,EAAE,CAAC;gBACb,IAAI,cAAc,GAAG,KAAK,CAAA;gBAC1B,MAAM,GAAG,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,CAAA;gBAElC,kEAAkE;gBAClE,yDAAyD;gBACzD,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O,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
- let sum = 0;
7
- for (const entry of array) {
8
- sum += entry.length;
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 sum;
11
+ return total;
11
12
  }
12
13
  function concatUint8Array(args) {
13
- const mergedArray = new Uint8Array(sum(args));
14
- let offset = 0;
15
- for (const entry of 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];
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":";;AA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AAI,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
- export function dedupe(list, hasher = JSON.stringify) {
3
- const clone = [];
4
- const lookup = new Set();
5
- for (const entry of list) {
6
- const hashed = hasher(entry);
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":"AAEA,mEAAmE;AACnE,MAAM,UAAU,MAAM,CAAI,IAAS,EAAE,SAAoB,IAAI,CAAC,SAAS;IACrE,MAAM,KAAK,GAAQ,EAAE,CAAA;IACrB,MAAM,MAAM,GAAG,IAAI,GAAG,EAAU,CAAA;IAEhC,KAAK,MAAM,KAAK,IAAI,IAAI,EAAE,CAAC;QACzB,MAAM,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,CAAA;QAE5B,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC;YACxB,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;YACjB,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,CAAA;QACpB,CAAC;IACH,CAAC;IAED,OAAO,KAAK,CAAA;AACd,CAAC"}
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 _getBuffer;
13
+ private getBuffer;
12
14
  }
package/esm/index.js CHANGED
@@ -1,119 +1,186 @@
1
- import { dedupe } from "./dedupe.js";
2
- import { concatUint8Array } from "./util.js";
3
- const CHUNK_SIZE = 65536;
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
- const ADDRESS_SIZE = 10;
7
- export default class Trix {
8
- ixxFile;
9
- ixFile;
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
- async search(searchString, opts) {
17
- let resultArr = [];
18
- const searchWords = searchString.split(' ');
19
- // we only search one word at a time
20
- const searchWord = searchWords[0].toLowerCase();
21
- const res = await this._getBuffer(searchWord, opts);
22
- if (!res) {
23
- return [];
24
- }
25
- let { end, buffer } = res;
26
- let done = false;
27
- const decoder = new TextDecoder('utf8');
28
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
29
- while (!done) {
30
- let foundSomething = false;
31
- const str = decoder.decode(buffer);
32
- // slice to lastIndexOf('\n') to make sure we get complete records
33
- // since the buffer fetch could get halfway into a record
34
- const lines = str
35
- .slice(0, str.lastIndexOf('\n'))
36
- .split('\n')
37
- .filter(f => !!f);
38
- const hits2 = [];
39
- for (const line of lines) {
40
- const word = line.split(' ')[0];
41
- const match = word.startsWith(searchWord);
42
- if (!foundSomething && match) {
43
- foundSomething = true;
44
- }
45
- // we are done scanning if we are lexicographically greater than the
46
- // search string
47
- if (word.slice(0, searchWord.length) > searchWord) {
48
- done = true;
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
- // if we are not done, and we haven't filled up maxResults with hits yet,
59
- // then refetch
60
- if (resultArr.length + hits.length < this.maxResults && !done) {
61
- const res2 = await this.ixFile.read(CHUNK_SIZE, end, opts);
62
- // early break if empty response
63
- if (res2.length === 0) {
64
- resultArr = resultArr.concat(hits);
65
- break;
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
- buffer = concatUint8Array([buffer, res2]);
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
- return file
86
- .split('\n')
87
- .filter(f => !!f)
88
- .map(line => {
89
- const p = line.length - ADDRESS_SIZE;
90
- const prefix = line.slice(0, p);
91
- const posStr = line.slice(p);
92
- const pos = Number.parseInt(posStr, 16);
93
- return [prefix, pos];
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
- async _getBuffer(searchWord, opts) {
97
- let start = 0;
98
- let end = 65536;
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,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACpC,OAAO,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAA;AAI5C,MAAM,UAAU,GAAG,KAAK,CAAA;AAExB,4EAA4E;AAC5E,iEAAiE;AACjE,MAAM,YAAY,GAAG,EAAE,CAAA;AAEvB,MAAM,CAAC,OAAO,OAAO,IAAI;IAEd;IACA;IACA;IAHT,YACS,OAA0B,EAC1B,MAAyB,EACzB,aAAa,EAAE;QAFf,YAAO,GAAP,OAAO,CAAmB;QAC1B,WAAM,GAAN,MAAM,CAAmB;QACzB,eAAU,GAAV,UAAU,CAAK;IACrB,CAAC;IAEJ,KAAK,CAAC,MAAM,CAAC,YAAoB,EAAE,IAA+B;QAChE,IAAI,SAAS,GAAG,EAAwB,CAAA;QACxC,MAAM,WAAW,GAAG,YAAY,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;QAE3C,oCAAoC;QACpC,MAAM,UAAU,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,CAAA;QAC/C,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,UAAU,EAAE,IAAI,CAAC,CAAA;QACnD,IAAI,CAAC,GAAG,EAAE,CAAC;YACT,OAAO,EAAE,CAAA;QACX,CAAC;QAED,IAAI,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,GAAG,CAAA;QACzB,IAAI,IAAI,GAAG,KAAK,CAAA;QAChB,MAAM,OAAO,GAAG,IAAI,WAAW,CAAC,MAAM,CAAC,CAAA;QACvC,uEAAuE;QACvE,OAAO,CAAC,IAAI,EAAE,CAAC;YACb,IAAI,cAAc,GAAG,KAAK,CAAA;YAC1B,M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;;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"}
package/esm/util.js CHANGED
@@ -1,14 +1,20 @@
1
- export function sum(array) {
2
- let sum = 0;
3
- for (const entry of array) {
4
- sum += entry.length;
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 sum;
11
+ return total;
7
12
  }
8
- export function concatUint8Array(args) {
9
- const mergedArray = new Uint8Array(sum(args));
10
- let offset = 0;
11
- for (const entry of args) {
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,MAAM,UAAU,GAAG,CAAC,KAAmB;IACrC,IAAI,GAAG,GAAG,CAAC,CAAA;IACX,KAAK,MAAM,KAAK,IAAI,KAAK,EAAE,CAAC;QAC1B,GAAG,IAAI,KAAK,CAAC,MAAM,CAAA;IACrB,CAAC;IACD,OAAO,GAAG,CAAA;AACZ,CAAC;AACD,MAAM,UAAU,gBAAgB,CAAC,IAAkB;IACjD,MAAM,WAAW,GAAG,IAAI,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAA;IAC7C,IAAI,MAAM,GAAG,CAAC,CAAA;IACd,KAAK,MAAM,KAAK,IAAI,IAAI,EAAE,CAAC;QACzB,WAAW,CAAC,GAAG,CAAC,KAAK,EAAE,MAAM,CAAC,CAAA;QAC9B,MAAM,IAAI,KAAK,CAAC,MAAM,CAAA;IACxB,CAAC;IACD,OAAO,WAAW,CAAA;AACpB,CAAC"}
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
- "version": "3.0.4",
2
+ "name": "@gmod/trix",
3
+ "version": "3.0.6",
3
4
  "license": "Apache-2.0",
4
- "main": "dist/index.js",
5
- "module": "esm/index.js",
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
- "prebuild": "rimraf dist esm",
17
- "build:esm": "tsc --target esnext --outDir esm",
18
- "build:es5": "tsc --target es2015 --outDir dist --module commonjs",
19
- "build": "npm run build:esm && npm run build:es5",
20
- "preversion": "npm run lint && npm test run && npm run build",
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
- "postversion": "git push --follow-tags",
23
- "test": "vitest"
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": "^22.15.21",
30
- "@typescript-eslint/eslint-plugin": "^8.4.0",
31
- "@typescript-eslint/parser": "^8.4.0",
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.5",
36
- "prettier": "^3.3.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.4.0",
40
- "vitest": "^4.0.6"
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
- // we only search one word at a time
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
- let { end, buffer } = res
31
- let done = false
32
- const decoder = new TextDecoder('utf8')
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
- // we are done scanning if we are lexicographically greater than the
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
- return file
93
+ const result = file
99
94
  .split('\n')
100
- .filter(f => !!f)
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 _getBuffer(
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 = 65536
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 + 65536
115
+ end = value + CHUNK_SIZE
122
116
  }
123
117
  }
124
118
 
125
- // Return the buffer and its end position in the file.
126
- const len = end - start
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 sum = 0
2
+ let total = 0
3
3
  for (const entry of array) {
4
- sum += entry.length
4
+ total += entry.length
5
5
  }
6
- return sum
6
+ return total
7
7
  }
8
8
  export function concatUint8Array(args: Uint8Array[]) {
9
9
  const mergedArray = new Uint8Array(sum(args))