* Process a single package query for fast-npm-meta. * Returns the metadata for a single package or null/error result.
( packageQuery: string, storage: ReturnType<typeof useStorage>, metadata: boolean, )
| 243 | * Returns the metadata for a single package or null/error result. |
| 244 | */ |
| 245 | async function processSingleFastNpmMeta( |
| 246 | packageQuery: string, |
| 247 | storage: ReturnType<typeof useStorage>, |
| 248 | metadata: boolean, |
| 249 | ): Promise<Record<string, unknown>> { |
| 250 | let packageName = packageQuery |
| 251 | let specifier = 'latest' |
| 252 | |
| 253 | if (packageName.startsWith('@')) { |
| 254 | const atIndex = packageName.indexOf('@', 1) |
| 255 | if (atIndex !== -1) { |
| 256 | specifier = packageName.slice(atIndex + 1) |
| 257 | packageName = packageName.slice(0, atIndex) |
| 258 | } |
| 259 | } else { |
| 260 | const atIndex = packageName.indexOf('@') |
| 261 | if (atIndex !== -1) { |
| 262 | specifier = packageName.slice(atIndex + 1) |
| 263 | packageName = packageName.slice(0, atIndex) |
| 264 | } |
| 265 | } |
| 266 | |
| 267 | // Special case: packages with "does-not-exist" in the name should 404 |
| 268 | if (packageName.includes('does-not-exist') || packageName.includes('nonexistent')) { |
| 269 | return { error: 'not_found' } |
| 270 | } |
| 271 | |
| 272 | const fixturePath = getFixturePath('packument', packageName) |
| 273 | const packument = await storage.getItem<any>(fixturePath) |
| 274 | |
| 275 | if (!packument) { |
| 276 | // For unknown packages without the special markers, try to return stub data |
| 277 | // This is handled elsewhere - returning error here for fast-npm-meta |
| 278 | return { error: 'not_found' } |
| 279 | } |
| 280 | |
| 281 | let version: string | undefined |
| 282 | if (specifier === 'latest' || !specifier) { |
| 283 | version = packument['dist-tags']?.latest |
| 284 | } else if (packument['dist-tags']?.[specifier]) { |
| 285 | version = packument['dist-tags'][specifier] |
| 286 | } else if (packument.versions?.[specifier]) { |
| 287 | version = specifier |
| 288 | } else { |
| 289 | version = packument['dist-tags']?.latest |
| 290 | } |
| 291 | |
| 292 | if (!version) { |
| 293 | return { error: 'version_not_found' } |
| 294 | } |
| 295 | |
| 296 | const result: Record<string, unknown> = { |
| 297 | name: packageName, |
| 298 | specifier, |
| 299 | version, |
| 300 | publishedAt: packument.time?.[version] || new Date().toISOString(), |
| 301 | lastSynced: Date.now(), |
| 302 | } |
no test coverage detected