dsh-locator 0.8.2 → 0.10.0
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 +47 -0
- package/README-es.md +30 -5
- package/README-hi.md +31 -5
- package/README-pt.md +31 -5
- package/README.en.md +31 -5
- package/README.md +31 -5
- package/bin/darwin-arm64/indexd +0 -0
- package/bin/darwin-x64/indexd +0 -0
- package/bin/linux-arm64/indexd +0 -0
- package/bin/linux-x64/indexd +0 -0
- package/bin/win32-arm64/indexd.exe +0 -0
- package/bin/win32-x64/indexd.exe +0 -0
- package/client.js +1198 -117
- package/lib/combined.d.ts +20 -3
- package/lib/combined.d.ts.map +1 -1
- package/lib/combined.js +85 -15
- package/lib/combined.js.map +1 -1
- package/lib/content-search-worker.d.ts +8 -3
- package/lib/content-search-worker.d.ts.map +1 -1
- package/lib/content-search-worker.js +54 -27
- package/lib/content-search-worker.js.map +1 -1
- package/lib/content-search.d.ts +127 -7
- package/lib/content-search.d.ts.map +1 -1
- package/lib/content-search.js +571 -36
- package/lib/content-search.js.map +1 -1
- package/lib/content.d.ts +83 -5
- package/lib/content.d.ts.map +1 -1
- package/lib/content.js +351 -87
- package/lib/content.js.map +1 -1
- package/lib/export.d.ts +61 -0
- package/lib/export.d.ts.map +1 -1
- package/lib/export.js +217 -52
- package/lib/export.js.map +1 -1
- package/lib/find.d.ts.map +1 -1
- package/lib/find.js +73 -16
- package/lib/find.js.map +1 -1
- package/lib/http.d.ts +38 -2
- package/lib/http.d.ts.map +1 -1
- package/lib/http.js +279 -82
- package/lib/http.js.map +1 -1
- package/lib/reveal.d.ts +69 -3
- package/lib/reveal.d.ts.map +1 -1
- package/lib/reveal.js +140 -11
- package/lib/reveal.js.map +1 -1
- package/lib/tools.d.ts +30 -0
- package/lib/tools.d.ts.map +1 -1
- package/lib/tools.js +65 -3
- package/lib/tools.js.map +1 -1
- package/package.json +1 -1
- package/src/combined.ts +107 -17
- package/src/content-search-worker.ts +52 -24
- package/src/content-search.ts +710 -36
- package/src/content.ts +349 -73
- package/src/export.ts +240 -50
- package/src/find.ts +83 -16
- package/src/http.ts +271 -83
- package/src/reveal.ts +148 -10
- package/src/tools.ts +83 -6
package/lib/content.d.ts
CHANGED
|
@@ -15,6 +15,8 @@
|
|
|
15
15
|
* alone unless `includeArchived` is set.
|
|
16
16
|
* @module dsh-locator/content
|
|
17
17
|
*/
|
|
18
|
+
import { Worker } from 'node:worker_threads';
|
|
19
|
+
import { type ContentSearchOptions, type ContentSearchResult } from './content-search.ts';
|
|
18
20
|
import type { LocatorRuntime } from './runtime.ts';
|
|
19
21
|
export interface ContentHit {
|
|
20
22
|
kind: 'file' | 'session';
|
|
@@ -25,6 +27,8 @@ export interface ContentHit {
|
|
|
25
27
|
messageId?: string;
|
|
26
28
|
/** Exact `data-chat-node-key` of the rendered row, when the host has one. */
|
|
27
29
|
nodeKey?: string;
|
|
30
|
+
/** 1-based line of the first match inside the stored body, for file hits. */
|
|
31
|
+
line?: number;
|
|
28
32
|
score: number;
|
|
29
33
|
}
|
|
30
34
|
export interface ContentState {
|
|
@@ -34,6 +38,11 @@ export interface ContentState {
|
|
|
34
38
|
messages: number;
|
|
35
39
|
truncated: boolean;
|
|
36
40
|
error: string;
|
|
41
|
+
/**
|
|
42
|
+
* Non-fatal problems from the last build/refresh: unreadable session logs,
|
|
43
|
+
* a quarantined database, and so on. Empty when everything was read.
|
|
44
|
+
*/
|
|
45
|
+
warnings: string[];
|
|
37
46
|
updatedAt: number;
|
|
38
47
|
}
|
|
39
48
|
export interface ContentOptions {
|
|
@@ -58,6 +67,16 @@ export interface ContentOptions {
|
|
|
58
67
|
* single-threaded.
|
|
59
68
|
*/
|
|
60
69
|
searchWorker?: boolean;
|
|
70
|
+
/**
|
|
71
|
+
* How long one worker query may run before it is reported as
|
|
72
|
+
* `content-search-timeout`. The query is never re-run on the host thread.
|
|
73
|
+
*/
|
|
74
|
+
searchWorkerTimeoutMs?: number;
|
|
75
|
+
/**
|
|
76
|
+
* Test seam: build the search worker instead of spawning the compiled one.
|
|
77
|
+
* Production never sets it.
|
|
78
|
+
*/
|
|
79
|
+
searchWorkerFactory?: (workerPath: string) => Worker;
|
|
61
80
|
}
|
|
62
81
|
export declare class ContentIndex {
|
|
63
82
|
private readonly rt;
|
|
@@ -73,6 +92,8 @@ export declare class ContentIndex {
|
|
|
73
92
|
private workerSeq;
|
|
74
93
|
private pendingStart;
|
|
75
94
|
private dbIdentity;
|
|
95
|
+
/** Session id → indexed session log path, for session-scoped content search. */
|
|
96
|
+
private readonly sessionPaths;
|
|
76
97
|
private readonly pending;
|
|
77
98
|
constructor(rt: LocatorRuntime, options: ContentOptions);
|
|
78
99
|
status(): ContentState;
|
|
@@ -111,9 +132,36 @@ export declare class ContentIndex {
|
|
|
111
132
|
private full;
|
|
112
133
|
private incremental;
|
|
113
134
|
private open;
|
|
135
|
+
/**
|
|
136
|
+
* Decide what an existing `content.db` is before touching it:
|
|
137
|
+
* - `foreign`: no dsh-locator table at all — refuse to modify it.
|
|
138
|
+
* - `corrupt`: zero bytes, unreadable, or not a SQLite database.
|
|
139
|
+
* - `incompatible`: has our tables but a different schema version/shape.
|
|
140
|
+
* - `ok`: safe to reuse.
|
|
141
|
+
*/
|
|
142
|
+
private classifyDatabase;
|
|
143
|
+
/**
|
|
144
|
+
* Move a broken/outdated database aside instead of destroying it. The
|
|
145
|
+
* timestamped name keeps the bytes around for inspection; if the rename
|
|
146
|
+
* fails (another process still holds it on Windows) a fresh file is still
|
|
147
|
+
* created so content search recovers.
|
|
148
|
+
*/
|
|
149
|
+
private quarantineDatabase;
|
|
150
|
+
/** Record one non-fatal build warning (deduplicated, bounded). */
|
|
151
|
+
private addWarning;
|
|
114
152
|
private reopenWorker;
|
|
115
153
|
private stopWorker;
|
|
154
|
+
/**
|
|
155
|
+
* Whether a usable search worker exists, creating one when needed.
|
|
156
|
+
* @returns false when the worker cannot be created at all; that is the only
|
|
157
|
+
* case in which an in-process (sync) query is allowed.
|
|
158
|
+
*/
|
|
116
159
|
private ensureWorker;
|
|
160
|
+
/**
|
|
161
|
+
* Resolve one worker reply. A malformed reply is reported as a protocol
|
|
162
|
+
* error; the query is never retried on the host thread.
|
|
163
|
+
*/
|
|
164
|
+
private onWorkerMessage;
|
|
117
165
|
private identityOf;
|
|
118
166
|
/**
|
|
119
167
|
* Whether the open handle still points at the file on disk. Another DSH
|
|
@@ -127,8 +175,6 @@ export declare class ContentIndex {
|
|
|
127
175
|
private recoverExternal;
|
|
128
176
|
/** Whether the engine is re-scanning, which can move its dump cursor. */
|
|
129
177
|
private engineRescanning;
|
|
130
|
-
/** Whether `path` is a SQLite database this plugin created (has docs_meta). */
|
|
131
|
-
private ownedDatabase;
|
|
132
178
|
private readFlag;
|
|
133
179
|
private writeFlag;
|
|
134
180
|
/**
|
|
@@ -143,7 +189,15 @@ export declare class ContentIndex {
|
|
|
143
189
|
/** True when a session log has been quiet long enough to be read safely. */
|
|
144
190
|
private settled;
|
|
145
191
|
private finish;
|
|
192
|
+
/**
|
|
193
|
+
* Rebuild the session id → session log path map from the persisted sources.
|
|
194
|
+
* Runs after `open()` and after every build/refresh, so session-scoped
|
|
195
|
+
* searches work against an existing database before the first refresh ends.
|
|
196
|
+
*/
|
|
197
|
+
private refreshSessionPaths;
|
|
146
198
|
private addDoc;
|
|
199
|
+
/** Body bytes stored for one document key (0 when it is not indexed). */
|
|
200
|
+
private storedBytes;
|
|
147
201
|
private deleteDoc;
|
|
148
202
|
private deletePath;
|
|
149
203
|
private indexFiles;
|
|
@@ -153,19 +207,43 @@ export declare class ContentIndex {
|
|
|
153
207
|
private readFileDoc;
|
|
154
208
|
private indexSessions;
|
|
155
209
|
private refreshSessions;
|
|
156
|
-
|
|
210
|
+
/** Read and decompress one session log completely; no side effects on rows. */
|
|
211
|
+
private readSessionText;
|
|
212
|
+
/** Index one already-decoded session log; the caller owns row replacement. */
|
|
213
|
+
private indexSessionText;
|
|
157
214
|
/** Session logs to consider, newest first, minus archived ones by default. */
|
|
158
215
|
private sessionCandidates;
|
|
159
216
|
sessionRoots(): string[];
|
|
160
217
|
/**
|
|
161
218
|
* Search file bodies and session messages. With `searchWorker` enabled the
|
|
162
|
-
* query itself runs off the host thread
|
|
163
|
-
*
|
|
219
|
+
* query itself runs off the host thread.
|
|
220
|
+
*
|
|
221
|
+
* A worker timeout, crash or malformed reply is a hard error result: the
|
|
222
|
+
* same query is never re-run on the host thread, where a heavy query (for
|
|
223
|
+
* example a whole-word scan) would stall the DSH event loop. Only when the
|
|
224
|
+
* worker cannot be created at all does the query run in-process, and that
|
|
225
|
+
* fallback is budgeted (bounded counts).
|
|
226
|
+
*
|
|
227
|
+
* The two-argument form returns the hit array (legacy callers). The
|
|
228
|
+
* three-argument form returns hits plus count, warnings and an error code,
|
|
229
|
+
* and understands the advanced match options.
|
|
164
230
|
* @param query - words or a phrase to find.
|
|
165
231
|
* @param limit - maximum hits.
|
|
232
|
+
* @param options - match mode, case/whole-word flags, session scope, count mode.
|
|
166
233
|
* @returns matching documents ordered by relevance.
|
|
167
234
|
*/
|
|
168
235
|
search(query: string, limit: number): Promise<ContentHit[]>;
|
|
236
|
+
search(query: string, limit: number, options: ContentSearchOptions): Promise<ContentSearchResult>;
|
|
237
|
+
private searchDetailed;
|
|
238
|
+
/** Run one query on the worker; timeout/protocol errors are final results. */
|
|
239
|
+
private searchInWorker;
|
|
240
|
+
/** Map a request's sessionId onto the indexed session log path. */
|
|
241
|
+
private resolveSession;
|
|
242
|
+
/**
|
|
243
|
+
* In-process query path. When `degraded` is set (worker creation failed) the
|
|
244
|
+
* options are tightened so this rare path cannot spend an unbounded amount of
|
|
245
|
+
* host-thread time counting matches.
|
|
246
|
+
*/
|
|
169
247
|
private searchSync;
|
|
170
248
|
}
|
|
171
249
|
//# sourceMappingURL=content.d.ts.map
|
package/lib/content.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"content.d.ts","sourceRoot":"","sources":["../src/content.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