@appland/search 1.2.1 → 1.2.3
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 +16 -0
- package/LICENSE.txt +25 -0
- package/built/cli.js +3 -3
- package/built/file-index.d.ts +1 -2
- package/built/file-index.js +30 -38
- package/built/file-type.d.ts +2 -1
- package/built/file-type.js +135 -66
- package/built/git.js +3 -3
- package/built/snippet-index.d.ts +1 -1
- package/built/snippet-index.js +5 -5
- package/package.json +3 -2
package/CHANGELOG.md
CHANGED
@@ -1,3 +1,19 @@
|
|
1
|
+
# [@appland/search-v1.2.3](https://github.com/getappmap/appmap-js/compare/@appland/search-v1.2.2...@appland/search-v1.2.3) (2025-07-07)
|
2
|
+
|
3
|
+
|
4
|
+
### Bug Fixes
|
5
|
+
|
6
|
+
* Improve worst case performance of file indexing ([3a8baa1](https://github.com/getappmap/appmap-js/commit/3a8baa18f7fdb7b4ecf8df91ce2f4ff27ea13d18))
|
7
|
+
* Optimize file indexing by caching binary content by file extension ([e402f68](https://github.com/getappmap/appmap-js/commit/e402f6872ce041bab0e5b4124ff9fa059bc5b321))
|
8
|
+
* Prevent file index from being re-created ([d59717f](https://github.com/getappmap/appmap-js/commit/d59717fd7b09d60608625d0b3ecd14cbe82b975f))
|
9
|
+
|
10
|
+
# [@appland/search-v1.2.2](https://github.com/getappmap/appmap-js/compare/@appland/search-v1.2.1...@appland/search-v1.2.2) (2025-05-01)
|
11
|
+
|
12
|
+
|
13
|
+
### Bug Fixes
|
14
|
+
|
15
|
+
* Migrate from node-sqlite3-wasm to better-sqlite3 ([47b7698](https://github.com/getappmap/appmap-js/commit/47b769860ce7a55dc3806981da2a78a408bc0648))
|
16
|
+
|
1
17
|
# [@appland/search-v1.2.1](https://github.com/getappmap/appmap-js/compare/@appland/search-v1.2.0...@appland/search-v1.2.1) (2025-03-11)
|
2
18
|
|
3
19
|
|
package/LICENSE.txt
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
The Software is provided to you by the Licensor under the License, as defined below, subject to the following condition.
|
2
|
+
|
3
|
+
Without limiting other conditions in the License, the grant of rights under the License will not include,
|
4
|
+
and the License does not grant to you, the right to Sell the Software.
|
5
|
+
|
6
|
+
For purposes of the foregoing, “Sell” means practicing any or all of the rights granted to you under the License to provide to third parties,
|
7
|
+
for a fee or other consideration (including without limitation fees for hosting or consulting/ support services related to the Software),
|
8
|
+
a product or service whose value derives, entirely or substantially, from the functionality of the Software.
|
9
|
+
Any license notice or attribution required by the License must also include this Commons Clause License Condition notice.
|
10
|
+
|
11
|
+
Software: @appland/search
|
12
|
+
|
13
|
+
License: MIT License
|
14
|
+
|
15
|
+
Copyright 2025, AppLand Inc
|
16
|
+
|
17
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
|
18
|
+
to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
19
|
+
and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
20
|
+
|
21
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
22
|
+
|
23
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
24
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
25
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/built/cli.js
CHANGED
@@ -4,10 +4,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
4
|
};
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
6
6
|
const node_perf_hooks_1 = require("node:perf_hooks");
|
7
|
+
const better_sqlite3_1 = __importDefault(require("better-sqlite3"));
|
7
8
|
const yargs_1 = __importDefault(require("yargs"));
|
8
9
|
const helpers_1 = require("yargs/helpers");
|
9
10
|
const debug_1 = __importDefault(require("debug"));
|
10
|
-
const node_sqlite3_wasm_1 = __importDefault(require("node-sqlite3-wasm"));
|
11
11
|
const tokenize_1 = require("./tokenize");
|
12
12
|
const file_index_1 = __importDefault(require("./file-index"));
|
13
13
|
const build_file_index_1 = __importDefault(require("./build-file-index"));
|
@@ -48,7 +48,7 @@ const cli = (0, yargs_1.default)((0, helpers_1.hideBin)(process.argv))
|
|
48
48
|
filterRE = new RegExp(argv.fileFilter);
|
49
49
|
const fileFilter = async (path) => {
|
50
50
|
debug('Filtering: %s', path);
|
51
|
-
if ((0, file_type_1.isBinaryFile)(path)) {
|
51
|
+
if (await (0, file_type_1.isBinaryFile)(path)) {
|
52
52
|
debug('Skipping binary file: %s', path);
|
53
53
|
return false;
|
54
54
|
}
|
@@ -81,7 +81,7 @@ const cli = (0, yargs_1.default)((0, helpers_1.hideBin)(process.argv))
|
|
81
81
|
printResult('file', filePath, score);
|
82
82
|
}
|
83
83
|
const splitter = splitter_1.langchainSplitter;
|
84
|
-
const snippetIndex = new snippet_index_1.default(new
|
84
|
+
const snippetIndex = new snippet_index_1.default(new better_sqlite3_1.default());
|
85
85
|
await (0, build_snippet_index_1.default)(snippetIndex, fileSearchResults, ioutil_1.readFileSafe, splitter, tokenize_1.fileTokens);
|
86
86
|
console.log('');
|
87
87
|
console.log('Snippet search results');
|
package/built/file-index.d.ts
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import sqlite3 from '
|
1
|
+
import sqlite3 from 'better-sqlite3';
|
2
2
|
export type FileSearchResult = {
|
3
3
|
directory: string;
|
4
4
|
filePath: string;
|
@@ -17,7 +17,6 @@ export type FileSearchResult = {
|
|
17
17
|
* - `file_content`: A virtual table that holds the file content and allows for full-text search using BM25 ranking.
|
18
18
|
*/
|
19
19
|
export default class FileIndex {
|
20
|
-
#private;
|
21
20
|
database: sqlite3.Database;
|
22
21
|
constructor(database: sqlite3.Database);
|
23
22
|
get schemaVersion(): string | undefined;
|
package/built/file-index.js
CHANGED
@@ -1,29 +1,19 @@
|
|
1
1
|
"use strict";
|
2
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
3
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
4
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
5
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
6
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
7
|
-
};
|
8
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
9
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
10
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
11
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
12
|
-
};
|
13
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
14
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
15
4
|
};
|
16
|
-
var _FileIndex_search;
|
17
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
18
6
|
const node_assert_1 = __importDefault(require("node:assert"));
|
19
7
|
const node_console_1 = require("node:console");
|
20
8
|
const promises_1 = require("node:fs/promises");
|
21
9
|
const node_path_1 = require("node:path");
|
10
|
+
const better_sqlite3_1 = __importDefault(require("better-sqlite3"));
|
22
11
|
const cachedir_1 = __importDefault(require("cachedir"));
|
23
12
|
const debug_1 = __importDefault(require("debug"));
|
24
|
-
const node_sqlite3_wasm_1 = __importDefault(require("node-sqlite3-wasm"));
|
25
13
|
const debug = (0, debug_1.default)('appmap:search:file-index');
|
14
|
+
const SCHEMA_VERSION = '1';
|
26
15
|
const SCHEMA = `
|
16
|
+
BEGIN;
|
27
17
|
CREATE VIRTUAL TABLE IF NOT EXISTS file_content USING fts5(
|
28
18
|
directory UNINDEXED,
|
29
19
|
file_path,
|
@@ -41,7 +31,10 @@ const SCHEMA = `
|
|
41
31
|
CREATE TABLE IF NOT EXISTS metadata (
|
42
32
|
key TEXT PRIMARY KEY,
|
43
33
|
value TEXT
|
44
|
-
)
|
34
|
+
);
|
35
|
+
INSERT OR REPLACE INTO metadata (key, value) VALUES ('schema_version', ${SCHEMA_VERSION});
|
36
|
+
COMMIT;
|
37
|
+
`;
|
45
38
|
const SEARCH_SQL = `SELECT
|
46
39
|
file_content.directory,
|
47
40
|
file_content.file_path,
|
@@ -57,7 +50,6 @@ ORDER BY
|
|
57
50
|
LIMIT
|
58
51
|
?
|
59
52
|
`;
|
60
|
-
const SCHEMA_VERSION = '1';
|
61
53
|
/**
|
62
54
|
* The FileIndex class provides an interface to interact with the SQLite search index.
|
63
55
|
*
|
@@ -73,28 +65,29 @@ const SCHEMA_VERSION = '1';
|
|
73
65
|
class FileIndex {
|
74
66
|
constructor(database) {
|
75
67
|
this.database = database;
|
76
|
-
|
77
|
-
if (
|
78
|
-
debug(
|
68
|
+
const version = this.schemaVersion;
|
69
|
+
if (version !== SCHEMA_VERSION) {
|
70
|
+
debug(`Schema version mismatch (${version}), recreating schema`);
|
79
71
|
this.dropAllTables();
|
80
72
|
this.createSchema();
|
81
73
|
}
|
82
|
-
__classPrivateFieldSet(this, _FileIndex_search, this.database.prepare(SEARCH_SQL), "f");
|
83
74
|
}
|
84
75
|
get schemaVersion() {
|
85
76
|
try {
|
86
|
-
const version = this.database
|
77
|
+
const version = this.database
|
78
|
+
.prepare("SELECT value FROM metadata WHERE key = 'schema_version'")
|
79
|
+
.get();
|
87
80
|
if (!version?.value)
|
88
81
|
return undefined;
|
89
82
|
return String(version.value);
|
90
83
|
}
|
91
|
-
catch {
|
84
|
+
catch (error) {
|
85
|
+
debug('Error retrieving schema version: %s', error);
|
92
86
|
return;
|
93
87
|
}
|
94
88
|
}
|
95
89
|
createSchema() {
|
96
90
|
this.database.exec(SCHEMA);
|
97
|
-
this.database.run("INSERT OR REPLACE INTO metadata (key, value) VALUES ('schema_version', ?)", SCHEMA_VERSION);
|
98
91
|
}
|
99
92
|
dropAllTables() {
|
100
93
|
this.database.exec(`
|
@@ -109,17 +102,19 @@ class FileIndex {
|
|
109
102
|
const cacheDir = (0, cachedir_1.default)('appmap');
|
110
103
|
await (0, promises_1.mkdir)(cacheDir, { recursive: true });
|
111
104
|
const dbPath = (0, node_path_1.join)(cacheDir, name);
|
112
|
-
const db =
|
105
|
+
const db = (0, better_sqlite3_1.default)(dbPath);
|
113
106
|
debug('Using cached database: %s', dbPath);
|
114
107
|
return new FileIndex(db);
|
115
108
|
}
|
116
109
|
get length() {
|
117
|
-
const row = this.database
|
110
|
+
const row = this.database
|
111
|
+
.prepare('SELECT COUNT(*) AS count FROM file_content')
|
112
|
+
.get();
|
118
113
|
(0, node_assert_1.default)(typeof row?.count === 'number');
|
119
114
|
return row.count;
|
120
115
|
}
|
121
116
|
get path() {
|
122
|
-
const file = this.database.
|
117
|
+
const file = this.database.prepare('PRAGMA database_list').get()?.file;
|
123
118
|
(0, node_assert_1.default)(typeof file === 'string');
|
124
119
|
return file || ':memory:';
|
125
120
|
}
|
@@ -144,7 +139,7 @@ class FileIndex {
|
|
144
139
|
const { directory, filePath } = file;
|
145
140
|
const stats = await (0, promises_1.stat)(filePath).catch(() => undefined);
|
146
141
|
const metadata = getMetadata.get(filePath);
|
147
|
-
setMetadata.run(
|
142
|
+
setMetadata.run(filePath, directory, generation, stats?.mtimeMs || null);
|
148
143
|
if (metadata) {
|
149
144
|
if (stats && metadata.modified === stats.mtimeMs) {
|
150
145
|
debug('Skipping unchanged file: %s', filePath);
|
@@ -160,10 +155,10 @@ class FileIndex {
|
|
160
155
|
continue;
|
161
156
|
debug('Indexing file: %s', filePath);
|
162
157
|
if (metadata) {
|
163
|
-
update.run(
|
158
|
+
update.run(content.symbols.join(' '), content.words.join(' '), directory, filePath);
|
164
159
|
}
|
165
160
|
else {
|
166
|
-
insert.run(
|
161
|
+
insert.run(directory, filePath, content.symbols.join(' '), content.words.join(' '));
|
167
162
|
}
|
168
163
|
}
|
169
164
|
catch (error) {
|
@@ -178,14 +173,10 @@ class FileIndex {
|
|
178
173
|
this.database.exec('COMMIT');
|
179
174
|
}
|
180
175
|
catch (error) {
|
181
|
-
this.database.
|
176
|
+
if (this.database.open)
|
177
|
+
this.database.exec('ROLLBACK');
|
182
178
|
throw error;
|
183
179
|
}
|
184
|
-
finally {
|
185
|
-
insert.finalize();
|
186
|
-
update.finalize();
|
187
|
-
getMetadata.finalize();
|
188
|
-
}
|
189
180
|
}
|
190
181
|
/**
|
191
182
|
* Searches for files matching the query.
|
@@ -194,7 +185,9 @@ class FileIndex {
|
|
194
185
|
* @returns An array of search results with directory, file path, and score.
|
195
186
|
*/
|
196
187
|
search(query, limit = 10) {
|
197
|
-
const rows =
|
188
|
+
const rows = this.database
|
189
|
+
.prepare(SEARCH_SQL)
|
190
|
+
.all(query, limit);
|
198
191
|
return rows.map((row) => ({
|
199
192
|
directory: row.directory,
|
200
193
|
filePath: row.file_path,
|
@@ -202,9 +195,8 @@ class FileIndex {
|
|
202
195
|
}));
|
203
196
|
}
|
204
197
|
close() {
|
205
|
-
|
206
|
-
|
198
|
+
if (this.database.open)
|
199
|
+
this.database.close();
|
207
200
|
}
|
208
201
|
}
|
209
|
-
_FileIndex_search = new WeakMap();
|
210
202
|
exports.default = FileIndex;
|
package/built/file-type.d.ts
CHANGED
@@ -1,3 +1,4 @@
|
|
1
1
|
export declare const isLargeFile: (fileName: string) => Promise<boolean>;
|
2
|
-
export declare const
|
2
|
+
export declare const getFileExtensions: (filePath: string) => string[];
|
3
|
+
export declare const isBinaryFile: (filePath: string) => Promise<boolean>;
|
3
4
|
export declare const isDataFile: (fileName: string) => boolean;
|
package/built/file-type.js
CHANGED
@@ -3,78 +3,123 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
4
|
};
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
-
exports.isDataFile = exports.isBinaryFile = exports.isLargeFile = void 0;
|
6
|
+
exports.isDataFile = exports.isBinaryFile = exports.getFileExtensions = exports.isLargeFile = void 0;
|
7
7
|
const promises_1 = require("fs/promises");
|
8
8
|
const debug_1 = __importDefault(require("debug"));
|
9
9
|
const isbinaryfile_1 = require("isbinaryfile");
|
10
|
+
const path_1 = require("path");
|
10
11
|
const debug = (0, debug_1.default)('appmap:search:file-type');
|
11
|
-
const
|
12
|
-
|
13
|
-
'
|
14
|
-
'
|
15
|
-
'
|
16
|
-
'
|
17
|
-
'
|
18
|
-
'
|
19
|
-
'
|
20
|
-
'
|
21
|
-
'
|
22
|
-
'
|
23
|
-
'
|
24
|
-
'
|
25
|
-
'
|
26
|
-
'
|
27
|
-
'
|
28
|
-
'
|
29
|
-
'
|
30
|
-
'
|
31
|
-
'
|
32
|
-
'
|
33
|
-
'
|
34
|
-
'
|
35
|
-
'
|
36
|
-
'
|
37
|
-
'
|
38
|
-
'
|
39
|
-
'
|
40
|
-
'
|
41
|
-
'
|
42
|
-
'
|
43
|
-
'
|
44
|
-
'
|
45
|
-
'
|
46
|
-
'
|
47
|
-
'
|
48
|
-
'
|
49
|
-
'
|
50
|
-
'
|
51
|
-
'
|
52
|
-
'
|
53
|
-
'
|
54
|
-
'
|
55
|
-
'
|
56
|
-
'
|
57
|
-
'
|
58
|
-
'
|
59
|
-
'
|
60
|
-
'
|
61
|
-
'
|
62
|
-
'
|
63
|
-
'
|
64
|
-
'
|
65
|
-
'
|
66
|
-
'
|
67
|
-
'
|
68
|
-
'
|
69
|
-
'
|
70
|
-
'
|
71
|
-
|
12
|
+
const BINARY_FILE_MEMO = new Map([
|
13
|
+
// Binary files
|
14
|
+
['.7z', true],
|
15
|
+
['.aac', true],
|
16
|
+
['.avi', true],
|
17
|
+
['.bin', true],
|
18
|
+
['.bmp', true],
|
19
|
+
['.bz2', true],
|
20
|
+
['.class', true],
|
21
|
+
['.data', true],
|
22
|
+
['.dat', true],
|
23
|
+
['.dll', true],
|
24
|
+
['.doc', true],
|
25
|
+
['.docx', true],
|
26
|
+
['.dylib', true],
|
27
|
+
['.ear', true],
|
28
|
+
['.exe', true],
|
29
|
+
['.eot', true],
|
30
|
+
['.flac', true],
|
31
|
+
['.flv', true],
|
32
|
+
['.gif', true],
|
33
|
+
['.gz', true],
|
34
|
+
['.ico', true],
|
35
|
+
['.jar', true],
|
36
|
+
['.jpeg', true],
|
37
|
+
['.jpg', true],
|
38
|
+
['.js.map', true],
|
39
|
+
['.min.js', true],
|
40
|
+
['.min.css', true],
|
41
|
+
['.mkv', true],
|
42
|
+
['.mo', true],
|
43
|
+
['.mov', true],
|
44
|
+
['.mp3', true],
|
45
|
+
['.mp4', true],
|
46
|
+
['.mpg', true],
|
47
|
+
['.odt', true],
|
48
|
+
['.odp', true],
|
49
|
+
['.ods', true],
|
50
|
+
['.ogg', true],
|
51
|
+
['.otf', true],
|
52
|
+
['.pdf', true],
|
53
|
+
['.po', true],
|
54
|
+
['.png', true],
|
55
|
+
['.ppt', true],
|
56
|
+
['.pptx', true],
|
57
|
+
['.pyc', true],
|
58
|
+
['.rar', true],
|
59
|
+
['.rtf', true],
|
60
|
+
['.so', true],
|
61
|
+
['.svg', true],
|
62
|
+
['.tar', true],
|
63
|
+
['.tiff', true],
|
64
|
+
['.ttf', true],
|
65
|
+
['.wav', true],
|
66
|
+
['.webm', true],
|
67
|
+
['.webp', true],
|
68
|
+
['.woff', true],
|
69
|
+
['.woff2', true],
|
70
|
+
['.wmv', true],
|
71
|
+
['.xls', true],
|
72
|
+
['.xlsx', true],
|
73
|
+
['.xz', true],
|
74
|
+
['.yarn.lock', true],
|
75
|
+
['.zip', true],
|
76
|
+
// Source code files
|
77
|
+
['.cjs', false],
|
78
|
+
['.mjs', false],
|
79
|
+
['.coffee', false],
|
80
|
+
['.dart', false],
|
81
|
+
['.el', false],
|
82
|
+
['.elm', false],
|
83
|
+
['.js', false],
|
84
|
+
['.ts', false],
|
85
|
+
['.jsx', false],
|
86
|
+
['.tsx', false],
|
87
|
+
['.py', false],
|
88
|
+
['.java', false],
|
89
|
+
['.rb', false],
|
90
|
+
['.php', false],
|
91
|
+
['.go', false],
|
92
|
+
['.rs', false],
|
93
|
+
['.cpp', false],
|
94
|
+
['.cc', false],
|
95
|
+
['.cxx', false],
|
96
|
+
['.h', false],
|
97
|
+
['.hpp', false],
|
98
|
+
['.cs', false],
|
99
|
+
['.swift', false],
|
100
|
+
['.kt', false],
|
101
|
+
['.kts', false],
|
102
|
+
['.scala', false],
|
103
|
+
['.lua', false],
|
104
|
+
['.sh', false],
|
105
|
+
['.bat', false],
|
106
|
+
['.pl', false],
|
107
|
+
['.sql', false],
|
108
|
+
['.html', false],
|
109
|
+
['.htm', false],
|
110
|
+
['.css', false],
|
111
|
+
['.scss', false],
|
112
|
+
['.sass', false],
|
113
|
+
['.less', false],
|
114
|
+
['.vue', false],
|
115
|
+
]);
|
72
116
|
const DATA_FILE_EXTENSIONS = [
|
73
117
|
'cjs',
|
74
118
|
'csv',
|
75
119
|
'dat',
|
76
120
|
'log',
|
77
121
|
'json',
|
122
|
+
'toml',
|
78
123
|
'tsv',
|
79
124
|
'yaml',
|
80
125
|
'yml',
|
@@ -108,11 +153,35 @@ const isLargeFile = async (fileName) => {
|
|
108
153
|
return fileSize > largeFileThreshold();
|
109
154
|
};
|
110
155
|
exports.isLargeFile = isLargeFile;
|
111
|
-
|
112
|
-
|
113
|
-
|
156
|
+
/* Returns unique file extensions for the given file path.
|
157
|
+
* E.g., for 'example.tar.gz', it returns [ '.tar.gz', '.gz'].
|
158
|
+
*/
|
159
|
+
const getFileExtensions = (filePath) => {
|
160
|
+
const fileName = (0, path_1.basename)(filePath).toLowerCase();
|
161
|
+
const parts = fileName.split('.');
|
162
|
+
if (parts.length <= 1)
|
163
|
+
return [];
|
164
|
+
const extensions = [];
|
165
|
+
for (let i = 1; i < parts.length; i++) {
|
166
|
+
const ext = '.' + parts.slice(i).join('.');
|
167
|
+
extensions.push(ext);
|
168
|
+
}
|
169
|
+
return extensions;
|
170
|
+
};
|
171
|
+
exports.getFileExtensions = getFileExtensions;
|
172
|
+
const isBinaryFile = async (filePath) => {
|
173
|
+
const fileExtensions = (0, exports.getFileExtensions)(filePath);
|
174
|
+
for (const ext of fileExtensions) {
|
175
|
+
if (BINARY_FILE_MEMO.has(ext)) {
|
176
|
+
return BINARY_FILE_MEMO.get(ext) === true;
|
177
|
+
}
|
178
|
+
}
|
114
179
|
try {
|
115
|
-
|
180
|
+
const isBinary = await (0, isbinaryfile_1.isBinaryFile)(filePath);
|
181
|
+
fileExtensions.forEach((ext) => {
|
182
|
+
BINARY_FILE_MEMO.set(ext, isBinary);
|
183
|
+
});
|
184
|
+
return isBinary;
|
116
185
|
}
|
117
186
|
catch (error) {
|
118
187
|
debug(`Error reading file: %s`, filePath);
|
package/built/git.js
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.Git = exports.GitCommitEnvKeys = exports.GitBranchEnvKeys = exports.GitRepositoryEnvKeys = exports.GitState = void 0;
|
4
|
-
const
|
4
|
+
const node_child_process_1 = require("node:child_process");
|
5
5
|
const util_1 = require("util");
|
6
|
-
const exec = (0, util_1.promisify)(
|
6
|
+
const exec = (0, util_1.promisify)(node_child_process_1.exec);
|
7
7
|
var GitState;
|
8
8
|
(function (GitState) {
|
9
9
|
GitState[GitState["NotInstalled"] = 0] = "NotInstalled";
|
@@ -102,7 +102,7 @@ class GitProperties {
|
|
102
102
|
static async state(cwd) {
|
103
103
|
return new Promise((resolve) => {
|
104
104
|
try {
|
105
|
-
const commandProcess = (0,
|
105
|
+
const commandProcess = (0, node_child_process_1.spawn)('git', ['status', '--porcelain'], {
|
106
106
|
shell: true,
|
107
107
|
cwd: cwd?.toString(),
|
108
108
|
stdio: 'ignore',
|
package/built/snippet-index.d.ts
CHANGED
package/built/snippet-index.js
CHANGED
@@ -108,8 +108,8 @@ class SnippetIndex {
|
|
108
108
|
_SnippetIndex_searchSnippet.set(this, void 0);
|
109
109
|
this.database.exec(CREATE_SNIPPET_CONTENT_TABLE_SQL);
|
110
110
|
this.database.exec(CREATE_SNIPPET_BOOST_TABLE_SQL);
|
111
|
-
this.database.
|
112
|
-
this.database.
|
111
|
+
this.database.pragma('journal_mode = OFF');
|
112
|
+
this.database.pragma('synchronous = OFF');
|
113
113
|
__classPrivateFieldSet(this, _SnippetIndex_insertSnippet, this.database.prepare(INSERT_SNIPPET_SQL), "f");
|
114
114
|
__classPrivateFieldSet(this, _SnippetIndex_deleteSession, this.database.prepare(DELETE_SESSION_SQL), "f");
|
115
115
|
__classPrivateFieldSet(this, _SnippetIndex_updateSnippetBoost, this.database.prepare(UPDATE_SNIPPET_BOOST_SQL), "f");
|
@@ -131,7 +131,7 @@ class SnippetIndex {
|
|
131
131
|
* @param content - The actual content of the snippet.
|
132
132
|
*/
|
133
133
|
indexSnippet(snippetId, directory, symbols, words, content) {
|
134
|
-
__classPrivateFieldGet(this, _SnippetIndex_insertSnippet, "f").run(
|
134
|
+
__classPrivateFieldGet(this, _SnippetIndex_insertSnippet, "f").run(encodeSnippetId(snippetId), directory, symbols, words, content);
|
135
135
|
}
|
136
136
|
/**
|
137
137
|
* Boosts the relevance score of a specific snippet for a given session.
|
@@ -140,10 +140,10 @@ class SnippetIndex {
|
|
140
140
|
* @param boostFactor - The factor by which to boost the snippet's relevance.
|
141
141
|
*/
|
142
142
|
boostSnippet(sessionId, snippetId, boostFactor) {
|
143
|
-
__classPrivateFieldGet(this, _SnippetIndex_updateSnippetBoost, "f").run(
|
143
|
+
__classPrivateFieldGet(this, _SnippetIndex_updateSnippetBoost, "f").run(sessionId, encodeSnippetId(snippetId), boostFactor);
|
144
144
|
}
|
145
145
|
searchSnippets(sessionId, query, limit = 10) {
|
146
|
-
const rows = __classPrivateFieldGet(this, _SnippetIndex_searchSnippet, "f").all(
|
146
|
+
const rows = __classPrivateFieldGet(this, _SnippetIndex_searchSnippet, "f").all(sessionId, query, limit);
|
147
147
|
return rows.map((row) => ({
|
148
148
|
directory: row.directory,
|
149
149
|
snippetId: parseSnippetId(row.snippet_id),
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@appland/search",
|
3
|
-
"version": "1.2.
|
3
|
+
"version": "1.2.3",
|
4
4
|
"description": "",
|
5
5
|
"bin": "built/cli.js",
|
6
6
|
"publishConfig": {
|
@@ -21,6 +21,7 @@
|
|
21
21
|
"author": "AppLand, Inc",
|
22
22
|
"license": "Commons Clause + MIT",
|
23
23
|
"devDependencies": {
|
24
|
+
"@types/better-sqlite3": "^7.6.13",
|
24
25
|
"@types/jest": "^29.5.4",
|
25
26
|
"@types/node": "^16",
|
26
27
|
"eslint": "^9",
|
@@ -38,9 +39,9 @@
|
|
38
39
|
"typescript-eslint": "^8.11.0"
|
39
40
|
},
|
40
41
|
"dependencies": {
|
42
|
+
"better-sqlite3": "^11.9.1",
|
41
43
|
"cachedir": "^2.4.0",
|
42
44
|
"isbinaryfile": "^5.0.4",
|
43
|
-
"node-sqlite3-wasm": "^0.8.34",
|
44
45
|
"yargs": "^17.7.2"
|
45
46
|
}
|
46
47
|
}
|