{"version":3,"file":"cache2.mjs","names":[],"sources":["../../src/commands/cache.ts"],"sourcesContent":["import { defineCommand } from \"citty\";\nimport consola from \"consola\";\nimport { getCacheDir } from \"../cache/paths.ts\";\nimport { clearStorage } from \"../cache/storage.ts\";\nimport { readLockfile, writeLockfile, pruneStale } from \"../cache/lockfile.ts\";\n\nexport default defineCommand({\n  meta: {\n    name: \"cache\",\n    description: \"Manage the registries cache\",\n  },\n  subCommands: {\n    clear: defineCommand({\n      meta: {\n        name: \"clear\",\n        description: \"Remove all cached data\",\n      },\n      async run() {\n        await clearStorage();\n        await writeLockfile({ version: 1, entries: {} });\n        consola.success(\"Cache cleared\");\n      },\n    }),\n    path: defineCommand({\n      meta: {\n        name: \"path\",\n        description: \"Show cache directory path\",\n      },\n      run() {\n        console.log(getCacheDir());\n      },\n    }),\n    status: defineCommand({\n      meta: {\n        name: \"status\",\n        description: \"Show cache status and entry count\",\n      },\n      async run() {\n        const lockfile = await readLockfile();\n        const entries = Object.values(lockfile.entries);\n        const fresh = entries.filter((e) => {\n          const expiresAt = e.fetchedAt + e.ttl * 1000;\n          return Date.now() < expiresAt;\n        });\n        const stale = entries.length - fresh.length;\n\n        consola.log(\"\");\n        consola.log(`  \\x1B[1mCache status\\x1B[0m`);\n        consola.log(`  \\x1B[90mDirectory:\\x1B[0m  ${getCacheDir()}`);\n        consola.log(\n          `  \\x1B[90mEntries:\\x1B[0m    ${entries.length} total, ${fresh.length} fresh, ${stale} stale`,\n        );\n        consola.log(\"\");\n\n        if (fresh.length > 0) {\n          // Group by ecosystem\n          const byEco = new Map<string, number>();\n          for (const e of fresh) {\n            const eco = e.key.split(\":\")[0]!;\n            byEco.set(eco, (byEco.get(eco) ?? 0) + 1);\n          }\n          for (const [eco, count] of byEco) {\n            consola.log(`  \\x1B[36m${eco}\\x1B[0m: ${count} cached`);\n          }\n          consola.log(\"\");\n        }\n      },\n    }),\n    prune: defineCommand({\n      meta: {\n        name: \"prune\",\n        description: \"Remove stale cache entries\",\n      },\n      async run() {\n        const lockfile = await readLockfile();\n        const removed = pruneStale(lockfile);\n        await writeLockfile(lockfile);\n        consola.success(`Pruned ${removed} stale entries`);\n      },\n    }),\n  },\n});\n"],"mappings":";;;AAMA,IAAA,gBAAe,cAAc;CAC3B,MAAM;EACJ,MAAM;EACN,aAAa;EACd;CACD,aAAa;EACX,OAAO,cAAc;GACnB,MAAM;IACJ,MAAM;IACN,aAAa;IACd;GACD,MAAM,MAAM;AACV,UAAM,cAAc;AACpB,UAAM,cAAc;KAAE,SAAS;KAAG,SAAS,EAAA;KAAI,CAAC;AAChD,YAAQ,QAAQ,gBAAgB;;GAEnC,CAAC;EACF,MAAM,cAAc;GAClB,MAAM;IACJ,MAAM;IACN,aAAa;IACd;GACD,MAAM;AACJ,YAAQ,IAAI,aAAa,CAAC;;GAE7B,CAAC;EACF,QAAQ,cAAc;GACpB,MAAM;IACJ,MAAM;IACN,aAAa;IACd;GACD,MAAM,MAAM;IACV,MAAM,WAAW,MAAM,cAAc;IACrC,MAAM,UAAU,OAAO,OAAO,SAAS,QAAQ;IAC/C,MAAM,QAAQ,QAAQ,QAAQ,MAAM;KAClC,MAAM,YAAY,EAAE,YAAY,EAAE,MAAM;AACxC,YAAO,KAAK,KAAK,GAAG;MACpB;IACF,MAAM,QAAQ,QAAQ,SAAS,MAAM;AAErC,YAAQ,IAAI,GAAG;AACf,YAAQ,IAAI,+BAA+B;AAC3C,YAAQ,IAAI,gCAAgC,aAAa,GAAG;AAC5D,YAAQ,IACN,gCAAgC,QAAQ,OAAO,UAAU,MAAM,OAAO,UAAU,MAAM,QACvF;AACD,YAAQ,IAAI,GAAG;AAEf,QAAI,MAAM,SAAS,GAAG;KAEpB,MAAM,wBAAQ,IAAI,KAAqB;AACvC,UAAK,MAAM,KAAK,OAAO;MACrB,MAAM,MAAM,EAAE,IAAI,MAAM,IAAI,CAAC;AAC7B,YAAM,IAAI,MAAM,MAAM,IAAI,IAAI,IAAI,KAAK,EAAE;;AAE3C,UAAK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