* Process a single package for the /versions/ endpoint. * Returns PackageVersionsInfo shape: { name, distTags, versions, specifier, time, lastSynced }
( packageQuery: string, storage: ReturnType<typeof useStorage>, metadata: boolean, )
| 317 | * Returns PackageVersionsInfo shape: { name, distTags, versions, specifier, time, lastSynced } |
| 318 | */ |
| 319 | async function processSingleVersionsMeta( |
| 320 | packageQuery: string, |
| 321 | storage: ReturnType<typeof useStorage>, |
| 322 | metadata: boolean, |
| 323 | ): Promise<Record<string, unknown>> { |
| 324 | let packageName = packageQuery |
| 325 | let specifier = '*' |
| 326 | |
| 327 | if (packageName.startsWith('@')) { |
| 328 | const atIndex = packageName.indexOf('@', 1) |
| 329 | if (atIndex !== -1) { |
| 330 | specifier = packageName.slice(atIndex + 1) |
| 331 | packageName = packageName.slice(0, atIndex) |
| 332 | } |
| 333 | } else { |
| 334 | const atIndex = packageName.indexOf('@') |
| 335 | if (atIndex !== -1) { |
| 336 | specifier = packageName.slice(atIndex + 1) |
| 337 | packageName = packageName.slice(0, atIndex) |
| 338 | } |
| 339 | } |
| 340 | |
| 341 | if (packageName.includes('does-not-exist') || packageName.includes('nonexistent')) { |
| 342 | return { name: packageName, error: 'not_found' } |
| 343 | } |
| 344 | |
| 345 | const fixturePath = getFixturePath('packument', packageName) |
| 346 | const packument = await storage.getItem<any>(fixturePath) |
| 347 | |
| 348 | if (!packument) { |
| 349 | return { name: packageName, error: 'not_found' } |
| 350 | } |
| 351 | |
| 352 | const result: Record<string, unknown> = { |
| 353 | name: packageName, |
| 354 | specifier, |
| 355 | distTags: packument['dist-tags'] || {}, |
| 356 | versions: Object.keys(packument.versions || {}), |
| 357 | time: packument.time || {}, |
| 358 | lastSynced: Date.now(), |
| 359 | } |
| 360 | |
| 361 | if (metadata) { |
| 362 | const versionsMeta: Record<string, Record<string, unknown>> = {} |
| 363 | for (const [ver, data] of Object.entries(packument.versions || {})) { |
| 364 | const meta: Record<string, unknown> = { version: ver } |
| 365 | const vData = data as Record<string, unknown> |
| 366 | if (vData.deprecated) meta.deprecated = vData.deprecated |
| 367 | if (packument.time?.[ver]) meta.time = packument.time[ver] |
| 368 | versionsMeta[ver] = meta |
| 369 | } |
| 370 | result.versionsMeta = versionsMeta |
| 371 | } |
| 372 | |
| 373 | return result |
| 374 | } |
| 375 | |
| 376 | async function handleFastNpmMeta( |
no test coverage detected