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
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Search worker:
|
|
3
|
-
*
|
|
4
|
-
*
|
|
2
|
+
* Search worker: content queries run here so a slow query can never stall the
|
|
3
|
+
* DSH host's event loop. A read-only connection makes the build's writes in the
|
|
4
|
+
* main thread safe to observe concurrently (WAL).
|
|
5
|
+
*
|
|
6
|
+
* Every request is answered with a complete {@link ContentSearchResult}; the
|
|
7
|
+
* worker never throws into the channel, because the host treats a timeout or a
|
|
8
|
+
* malformed reply as a hard error rather than re-running the query on the main
|
|
9
|
+
* thread.
|
|
5
10
|
* @module dsh-locator/content-search-worker
|
|
6
11
|
*/
|
|
7
12
|
|
|
8
13
|
import { parentPort, workerData } from 'node:worker_threads'
|
|
9
14
|
import { DatabaseSync } from 'node:sqlite'
|
|
10
|
-
import { searchContent } from './content-search.ts'
|
|
11
|
-
import type { ContentHit } from './content.ts'
|
|
15
|
+
import { searchContent, type ContentSearchOptions, type ContentSearchResult } from './content-search.ts'
|
|
12
16
|
|
|
13
17
|
interface Request {
|
|
14
18
|
id: number
|
|
@@ -16,6 +20,12 @@ interface Request {
|
|
|
16
20
|
close?: boolean
|
|
17
21
|
query?: string
|
|
18
22
|
limit?: number
|
|
23
|
+
options?: ContentSearchOptions
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** A result shape every failure path can share. */
|
|
27
|
+
function failure(error: string, warnings: string[] = [error]): ContentSearchResult {
|
|
28
|
+
return { hits: [], count: { value: 0, kind: 'unknown' }, warnings, error }
|
|
19
29
|
}
|
|
20
30
|
|
|
21
31
|
let db: DatabaseSync | null = null
|
|
@@ -26,27 +36,45 @@ function open(path: string): void {
|
|
|
26
36
|
try { db = new DatabaseSync(path, { readOnly: true }) } catch { db = null }
|
|
27
37
|
}
|
|
28
38
|
|
|
39
|
+
function post(message: Record<string, unknown>): void {
|
|
40
|
+
try { parentPort?.postMessage(message) } catch { /* the host is gone; nothing to do */ }
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** Handle one request; never throws. */
|
|
44
|
+
function handle(request: Request): void {
|
|
45
|
+
try {
|
|
46
|
+
if (request.open !== undefined) {
|
|
47
|
+
open(request.open)
|
|
48
|
+
post({ id: request.id, ok: true })
|
|
49
|
+
return
|
|
50
|
+
}
|
|
51
|
+
if (request.close === true) {
|
|
52
|
+
try { db?.close() } catch { /* ignore */ }
|
|
53
|
+
db = null
|
|
54
|
+
post({ id: request.id, ok: true })
|
|
55
|
+
return
|
|
56
|
+
}
|
|
57
|
+
if (typeof request.query !== 'string') {
|
|
58
|
+
post({ id: request.id, result: failure('content-search-worker-protocol-error') })
|
|
59
|
+
return
|
|
60
|
+
}
|
|
61
|
+
if (db === null) {
|
|
62
|
+
post({ id: request.id, result: failure('content-index-unavailable') })
|
|
63
|
+
return
|
|
64
|
+
}
|
|
65
|
+
const result = searchContent(db, request.query, request.limit ?? 30, request.options ?? {})
|
|
66
|
+
post({ id: request.id, result })
|
|
67
|
+
} catch {
|
|
68
|
+
// A thrown SQLite/JS error is reported as a result so the host can show a
|
|
69
|
+
// clear error code instead of silently re-running the query in-process.
|
|
70
|
+
post({ id: request.id, result: failure('content-search-worker-error') })
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
29
74
|
const initial = (workerData as { dbPath?: string } | undefined)?.dbPath
|
|
30
75
|
if (initial !== undefined) open(initial)
|
|
31
76
|
|
|
32
77
|
parentPort?.on('message', (request: Request) => {
|
|
33
|
-
if (request.
|
|
34
|
-
|
|
35
|
-
parentPort?.postMessage({ id: request.id, ok: true })
|
|
36
|
-
return
|
|
37
|
-
}
|
|
38
|
-
if (request.close === true) {
|
|
39
|
-
try { db?.close() } catch { /* ignore */ }
|
|
40
|
-
db = null
|
|
41
|
-
parentPort?.postMessage({ id: request.id, ok: true })
|
|
42
|
-
return
|
|
43
|
-
}
|
|
44
|
-
let hits: ContentHit[] = []
|
|
45
|
-
let error = ''
|
|
46
|
-
if (db !== null) {
|
|
47
|
-
try { hits = searchContent(db, request.query ?? '', request.limit ?? 30) } catch (cause) {
|
|
48
|
-
error = cause instanceof Error ? cause.message : String(cause)
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
parentPort?.postMessage({ id: request.id, hits, error })
|
|
78
|
+
if (typeof request !== 'object' || request === null || typeof request.id !== 'number') return
|
|
79
|
+
handle(request)
|
|
52
80
|
})
|