···11+import * as v from 'valibot';
22+13import { FetchError, InvalidSpecifierError, PackageNotFoundError } from './errors';
22-import type { Packument, Registry } from './types';
44+import { abbreviatedPackumentSchema, type AbbreviatedPackument, type Registry } from './types';
3546const NPM_REGISTRY = 'https://registry.npmjs.org';
57const JSR_REGISTRY = 'https://npm.jsr.io';
···810 * cache for packuments to avoid refetching during resolution.
911 * key format: "registry:name" (e.g., "npm:react" or "jsr:@luca/flag")
1012 */
1111-const packumentCache = new Map<string, Packument>();
1313+const packumentCache = new Map<string, AbbreviatedPackument>();
12141315/**
1416 * transforms a JSR package name to the npm-compatible format.
···4547}
46484749/**
4848- * fetches the packument (full package metadata) from a registry.
4949- * uses the abbreviated format when possible for smaller payloads.
5050+ * fetches the abbreviated packument from a registry.
5151+ * the abbreviated format contains only installation-relevant metadata.
5052 *
5153 * @param name the package name (can be scoped like @scope/pkg)
5254 * @param registry which registry to fetch from (defaults to 'npm')
5353- * @returns the packument with all versions
5454- * @throws if the package doesn't exist or network fails
5555+ * @returns the abbreviated packument with all versions
5656+ * @throws if the package doesn't exist, network fails, or response is invalid
5557 */
5656-export async function fetchPackument(name: string, registry: Registry = 'npm'): Promise<Packument> {
5858+export async function fetchPackument(
5959+ name: string,
6060+ registry: Registry = 'npm',
6161+): Promise<AbbreviatedPackument> {
5762 const cacheKey = `${registry}:${name}`;
5863 const cached = packumentCache.get(cacheKey);
5964 if (cached) {
···9196 throw new FetchError(url, response.status, response.statusText);
9297 }
93989494- const packument = (await response.json()) as Packument;
9999+ const json = await response.json();
100100+ const packument = v.parse(abbreviatedPackumentSchema, json);
95101 packumentCache.set(cacheKey, packument);
96102 return packument;
97103}