MCPcopy
hub / github.com/npmx-dev/npmx.dev / handleFastNpmMeta

Function handleFastNpmMeta

modules/runtime/server/cache.ts:376–412  ·  view source on GitHub ↗
(
  url: string,
  storage: ReturnType<typeof useStorage>,
)

Source from the content-addressed store, hash-verified

374}
375
376async function handleFastNpmMeta(
377 url: string,
378 storage: ReturnType<typeof useStorage>,
379): Promise<MockResult | null> {
380 const urlObj = URL.parse(url)
381 if (!urlObj) return null
382
383 const { host, pathname, searchParams } = urlObj
384
385 if (host !== 'npm.antfu.dev') return null
386
387 const rawPath = decodeURIComponent(pathname.slice(1))
388 if (!rawPath) return null
389
390 const metadata = searchParams.get('metadata') === 'true'
391
392 // Determine if this is a /versions/ request
393 const isVersions = rawPath.startsWith('versions/')
394 const pathPart = isVersions ? rawPath.slice('versions/'.length) : rawPath
395 const processFn = isVersions
396 ? (pkg: string) => processSingleVersionsMeta(pkg, storage, metadata)
397 : (pkg: string) => processSingleFastNpmMeta(pkg, storage, metadata)
398
399 // Handle batch requests (package1+package2+...)
400 if (pathPart.includes('+')) {
401 const packages = pathPart.split('+')
402 const results = await Promise.all(packages.map(processFn))
403 return { data: results }
404 }
405
406 // Handle single package request
407 const result = await processFn(pathPart)
408 if ('error' in result) {
409 return { data: null }
410 }
411 return { data: result }
412}
413
414/**
415 * Handle GitHub API requests using fixtures.

Callers 1

fetchFromFixturesFunction · 0.85

Calls 3

processSingleFastNpmMetaFunction · 0.85
getMethod · 0.65

Tested by

no test coverage detected