Skip to content

Commit a851e1e

Browse files
authored
refactor: simplify search logic and use more minimal endpoints (#1236)
1 parent 03e43e7 commit a851e1e

File tree

14 files changed

+690
-450
lines changed

14 files changed

+690
-450
lines changed

app/components/Compare/PackageSelector.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ const maxPackages = computed(() => props.max ?? 4)
1414
const inputValue = shallowRef('')
1515
const isInputFocused = shallowRef(false)
1616
17-
// Use the shared npm search composable
18-
const { data: searchData, status } = useNpmSearch(inputValue, { size: 15 })
17+
// Use the shared search composable (supports both npm and Algolia providers)
18+
const { data: searchData, status } = useSearch(inputValue, { size: 15 })
1919
2020
const isSearching = computed(() => status.value === 'pending')
2121
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import type { NpmSearchResponse, NpmSearchResult, PackageMetaResponse } from '#shared/types'
2+
3+
/**
4+
* Convert a lightweight package-meta API response to a search result for display.
5+
*/
6+
export function metaToSearchResult(meta: PackageMetaResponse): NpmSearchResult {
7+
return {
8+
package: {
9+
name: meta.name,
10+
version: meta.version,
11+
description: meta.description,
12+
keywords: meta.keywords,
13+
license: meta.license,
14+
date: meta.date,
15+
links: meta.links,
16+
author: meta.author,
17+
maintainers: meta.maintainers,
18+
},
19+
score: { final: 0, detail: { quality: 0, popularity: 0, maintenance: 0 } },
20+
searchScore: 0,
21+
downloads: meta.weeklyDownloads !== undefined ? { weekly: meta.weeklyDownloads } : undefined,
22+
updated: meta.date,
23+
}
24+
}
25+
26+
export function emptySearchResponse(): NpmSearchResponse {
27+
return {
28+
objects: [],
29+
total: 0,
30+
isStale: false,
31+
time: new Date().toISOString(),
32+
}
33+
}

0 commit comments

Comments
 (0)