{
  "version": 3,
  "sources": ["../../../../src/packages/store.cafs/getFilePathInCafs.ts"],
  "sourcesContent": ["import path from 'node:path';\nimport ssri, { type IntegrityLike } from 'ssri';\n\nexport const modeIsExecutable = (mode: number): boolean => {\n  return (mode & 0o1_1_1) !== 0;\n};\n\nexport type FileType = 'exec' | 'nonexec' | 'index';\n\nexport function getFilePathByModeInCafs(\n  storeDir: string,\n  integrity: string | IntegrityLike,\n  mode: number\n): string {\n  return path.join(\n    storeDir,\n    contentPathFromIntegrity(\n      integrity,\n      modeIsExecutable(mode) ? 'exec' : 'nonexec'\n    )\n  );\n}\n\nexport function getIndexFilePathInCafs(\n  storeDir: string,\n  integrity: string | IntegrityLike,\n  pkgId: string\n): string {\n  const hex = ssri\n    .parse(integrity, { single: true })\n    .hexDigest()\n    .substring(0, 64);\n\n  // Some registries allow identical content to be published under different package names or versions.\n  // To accommodate this, index files are stored using both the content hash and package identifier.\n  // This approach ensures that we can:\n  // 1. Validate that the integrity in the lockfile corresponds to the correct package,\n  //    which might not be the case after a poorly resolved Git conflict.\n  // 2. Allow the same content to be referenced by different packages or different versions of the same package.\n  return path.join(\n    storeDir,\n    `index/${path.join(hex.slice(0, 2), hex.slice(2))}-${pkgId.replace(/[\"*/:<>?\\\\|]/g, '+')}.json`\n  );\n}\n\nfunction contentPathFromIntegrity(\n  integrity: string | IntegrityLike,\n  fileType: FileType\n): string {\n  const sri = ssri.parse(integrity, { single: true });\n\n  return contentPathFromHex(fileType, sri.hexDigest());\n}\n\nexport function contentPathFromHex(fileType: FileType, hex: string): string {\n  const p = path.join('files', hex.slice(0, 2), hex.slice(2));\n  switch (fileType) {\n    case 'exec':\n      return `${p}-exec`;\n    case 'nonexec':\n      return p;\n    case 'index':\n      return `${p}-index.json`;\n  }\n}\n"],
  "mappings": "AAAA,OAAO,UAAU;AACjB,OAAO,cAAkC;AAElC,MAAM,mBAAmB,CAAC,SAA0B;AACzD,UAAQ,OAAO,QAAa;AAC9B;AAIO,SAAS,wBACd,UACA,WACA,MACQ;AACR,SAAO,KAAK;AAAA,IACV;AAAA,IACA;AAAA,MACE;AAAA,MACA,iBAAiB,IAAI,IAAI,SAAS;AAAA,IACpC;AAAA,EACF;AACF;AAEO,SAAS,uBACd,UACA,WACA,OACQ;AACR,QAAM,MAAM,KACT,MAAM,WAAW,EAAE,QAAQ,KAAK,CAAC,EACjC,UAAU,EACV,UAAU,GAAG,EAAE;AAQlB,SAAO,KAAK;AAAA,IACV;AAAA,IACA,SAAS,KAAK,KAAK,IAAI,MAAM,GAAG,CAAC,GAAG,IAAI,MAAM,CAAC,CAAC,CAAC,IAAI,MAAM,QAAQ,iBAAiB,GAAG,CAAC;AAAA,EAC1F;AACF;AAEA,SAAS,yBACP,WACA,UACQ;AACR,QAAM,MAAM,KAAK,MAAM,WAAW,EAAE,QAAQ,KAAK,CAAC;AAElD,SAAO,mBAAmB,UAAU,IAAI,UAAU,CAAC;AACrD;AAEO,SAAS,mBAAmB,UAAoB,KAAqB;AAC1E,QAAM,IAAI,KAAK,KAAK,SAAS,IAAI,MAAM,GAAG,CAAC,GAAG,IAAI,MAAM,CAAC,CAAC;AAC1D,UAAQ,UAAU;AAAA,IAChB,KAAK;AACH,aAAO,GAAG,CAAC;AAAA,IACb,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO,GAAG,CAAC;AAAA,EACf;AACF;",
  "names": []
}
