opencode-search 1.0.0-next.7 → 1.0.0-next.9
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/README.md +35 -20
- package/REMOVED.md +10 -0
- package/dist/package.json +14 -10
- package/dist/src/providers/rfc-search.d.ts +9 -0
- package/dist/src/providers/rfc-search.d.ts.map +1 -0
- package/dist/src/providers/rfc-search.js +35 -0
- package/dist/src/providers/rfc-search.js.map +1 -0
- package/dist/src/providers/w3c-search.d.ts +6 -0
- package/dist/src/providers/w3c-search.d.ts.map +1 -0
- package/dist/src/providers/w3c-search.js +42 -0
- package/dist/src/providers/w3c-search.js.map +1 -0
- package/dist/src/providers/whatwg-search.d.ts +8 -0
- package/dist/src/providers/whatwg-search.d.ts.map +1 -0
- package/dist/src/providers/whatwg-search.js +31 -0
- package/dist/src/providers/whatwg-search.js.map +1 -0
- package/dist/src/renderers.d.ts +6 -2
- package/dist/src/renderers.d.ts.map +1 -1
- package/dist/src/renderers.js +14 -8
- package/dist/src/renderers.js.map +1 -1
- package/dist/src/search.d.ts +3 -1
- package/dist/src/search.d.ts.map +1 -1
- package/dist/src/search.js +91 -39
- package/dist/src/search.js.map +1 -1
- package/package.json +14 -10
- package/src/providers/rfc-search.test.ts +22 -0
- package/src/providers/rfc-search.ts +57 -0
- package/src/providers/w3c-search.test.ts +22 -0
- package/src/providers/w3c-search.ts +67 -0
- package/src/providers/whatwg-search.test.ts +21 -0
- package/src/providers/whatwg-search.ts +55 -0
- package/src/renderers.test.ts +0 -64
- package/src/renderers.ts +20 -9
- package/src/search.ts +105 -46
- package/dist/src/providers/standard-search.d.ts +0 -18
- package/dist/src/providers/standard-search.d.ts.map +0 -1
- package/dist/src/providers/standard-search.js +0 -61
- package/dist/src/providers/standard-search.js.map +0 -1
- package/src/providers/standard-search.test.ts +0 -29
- package/src/providers/standard-search.ts +0 -94
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'bun:test'
|
|
2
|
-
import { safeAsync } from '../safe.ts'
|
|
3
|
-
import { standardSearch } from './standard-search.ts'
|
|
4
|
-
|
|
5
|
-
const isServiceDown = (error: Error): boolean => (
|
|
6
|
-
error.message.includes('Unable to connect') || error.message.includes('ConnectionRefused')
|
|
7
|
-
)
|
|
8
|
-
|
|
9
|
-
describe('standardSearch', () => {
|
|
10
|
-
it('returns document results', async () => {
|
|
11
|
-
const { data: results, error } = await safeAsync(() => standardSearch({ query: 'atproto' }))
|
|
12
|
-
if (error) {
|
|
13
|
-
// An unreachable appview host is a service outage, not a plugin bug
|
|
14
|
-
if (isServiceDown(error)) {
|
|
15
|
-
console.warn('standard-search appview unreachable, skipping live assertion')
|
|
16
|
-
return
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
throw error
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
expect(results.documents.length > 0).toEqual(true)
|
|
23
|
-
|
|
24
|
-
const first = results.documents[0]
|
|
25
|
-
if (!first) throw new Error('expected at least one document')
|
|
26
|
-
expect(first.title).toBeDefined()
|
|
27
|
-
expect(first.url).toBeDefined()
|
|
28
|
-
})
|
|
29
|
-
})
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
import { JSDOM, VirtualConsole } from 'jsdom'
|
|
2
|
-
import * as cache from '../cache.ts'
|
|
3
|
-
|
|
4
|
-
const SEARCH_URL = 'https://standard-search.octet-stream.net/search'
|
|
5
|
-
|
|
6
|
-
export type StandardDocument = {
|
|
7
|
-
title: string
|
|
8
|
-
url: string
|
|
9
|
-
date: string
|
|
10
|
-
snippet: string
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export type StandardSearchResult = {
|
|
14
|
-
documents: Array<StandardDocument>
|
|
15
|
-
totalResults: string
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
const parseDocument = (el: Element): StandardDocument | null => {
|
|
19
|
-
const titleEl = el.querySelector('.result-title a')
|
|
20
|
-
if (!titleEl || !titleEl.textContent) return null
|
|
21
|
-
|
|
22
|
-
const title = titleEl.textContent.trim()
|
|
23
|
-
const href = titleEl.getAttribute('href')
|
|
24
|
-
|
|
25
|
-
const urlEl = el.querySelector('.result-url')
|
|
26
|
-
const urlText = urlEl && urlEl.textContent ? urlEl.textContent : ''
|
|
27
|
-
|
|
28
|
-
const snippetEl = el.querySelector('.result-snippet')
|
|
29
|
-
const snippet = snippetEl && snippetEl.textContent ? snippetEl.textContent : ''
|
|
30
|
-
|
|
31
|
-
const parts = urlText.split(' \u00B7 ')
|
|
32
|
-
const datePart = parts.length > 1 ? parts[1] : ''
|
|
33
|
-
|
|
34
|
-
return {
|
|
35
|
-
title,
|
|
36
|
-
url: href ? href.trim() : '',
|
|
37
|
-
date: datePart ? datePart.trim() : '',
|
|
38
|
-
snippet: snippet.trim(),
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
type StandardSearchOptions = {
|
|
43
|
-
query: string
|
|
44
|
-
limit?: number
|
|
45
|
-
offset?: number
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export const standardSearch = async (options: StandardSearchOptions): Promise<StandardSearchResult> => {
|
|
49
|
-
const cacheKey = ['standard', options.query, options.limit ?? 0, options.offset ?? 0].join(':')
|
|
50
|
-
|
|
51
|
-
const cached = await cache.get<StandardSearchResult>(cacheKey)
|
|
52
|
-
if (cached && cached.documents && cached.documents.length > 0) return cached
|
|
53
|
-
|
|
54
|
-
const url = SEARCH_URL + '?q=' + encodeURIComponent(options.query)
|
|
55
|
-
const res = await fetch(url)
|
|
56
|
-
|
|
57
|
-
if (!res.ok) throw new Error('Standard Search error (' + res.status + '): ' + res.statusText)
|
|
58
|
-
|
|
59
|
-
const html = await res.text()
|
|
60
|
-
|
|
61
|
-
const virtualConsole = new VirtualConsole()
|
|
62
|
-
virtualConsole.on('jsdomError', () => {})
|
|
63
|
-
|
|
64
|
-
const dom = new JSDOM(html, { url, virtualConsole })
|
|
65
|
-
const doc = dom.window.document
|
|
66
|
-
|
|
67
|
-
const countEl = doc.querySelector('.result-count')
|
|
68
|
-
const countText = countEl ? countEl.textContent : ''
|
|
69
|
-
const totalResults = countText ? countText.trim() : '0'
|
|
70
|
-
|
|
71
|
-
const elements = doc.querySelectorAll('.result')
|
|
72
|
-
const documents: Array<StandardDocument> = []
|
|
73
|
-
|
|
74
|
-
for (let i = 0; i < elements.length; i++) {
|
|
75
|
-
const el = elements[i]
|
|
76
|
-
if (!el) continue
|
|
77
|
-
|
|
78
|
-
const parsed = parseDocument(el)
|
|
79
|
-
if (parsed) documents.push(parsed)
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
const start = options.offset ?? 0
|
|
83
|
-
const end = options.limit ? start + options.limit : documents.length
|
|
84
|
-
const sliced = documents.slice(start, end)
|
|
85
|
-
|
|
86
|
-
const result: StandardSearchResult = {
|
|
87
|
-
documents: sliced,
|
|
88
|
-
totalResults,
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
if (sliced.length > 0) await cache.set(cacheKey, result)
|
|
92
|
-
|
|
93
|
-
return result
|
|
94
|
-
}
|