{"version":3,"sources":["../src/runtime/getMapEntry.ts"],"names":[],"mappings":";;;AA+BO,IAAM,kBAAA,GACX,CACE,SAAA,EACA,cAAA,KAKF,OAAO,cAAc,OAAA,EAAS,MAAA,EAAQ,OAAA,GAAU,EAAC,KAAM;AACrD,EAAA,MAAM,UAAA,GAAa,SAAA,CAAU,YAAY,CAAA,CAAE,OAAO,CAAA;AAElD,EAAA,IAAI,UAAA,CAAW,SAAS,UAAA,EAAY;AAClC,IAAA,MAAM,IAAI,KAAA;AAAA,MACR,CAAA,cAAA,EAAiB,YAAY,CAAA,CAAA,EAAI,OAAO,CAAA,qBAAA;AAAA,KAC1C;AAAA,EACF;AAEA,EAAA,MAAM,aAAA,GAAgB,UAAA,CAAW,KAAA,CAAM,MAAA,CAAO,MAAM,CAAA;AAEpD,EAAA,MAAM,eAAA,GACJ,OAAA,CAAQ,eAAA,IAAmB,cAAA,CAAe,eAAA;AAC5C,EAAA,IAAI,mBAAmB,IAAA,EAAM;AAC3B,IAAA,MAAM,IAAI,MAAM,CAAA,uCAAA,CAAyC,CAAA;AAAA,EAC3D;AAEA,EAAA,MAAM,sBAAA,GACJ,OAAA,CAAQ,qBAAA,IACR,cAAA,CAAe,qBAAA,IACf,qBAAA;AAEF,EAAA,MAAM,MAAA,GAAS,MAAM,sBAAA,CAAuB;AAAA,IAC1C,YAAA;AAAA,IACA,OAAA;AAAA,IACA,MAAA,EAAQ,aAAA;AAAA,IACR,eAAA,EAAiB;AAAA,GAClB,CAAA;AAED,EAAA,OAAO,UAAA,CAAW,MAAA,CAAO,MAAA,CAAO,MAAM,CAAA;AACxC","file":"chunk-Y6WMF5UO.mjs","sourcesContent":["import { fetchContractMapEntry } from \"@stacks/transactions\";\nimport type { StringOnly } from \"../utils/helpers\";\nimport type {\n  ContractBaseType,\n  ParameterObjOfDescriptor,\n  MapEntryDescriptor,\n  ReturnTypeOfDescriptor,\n} from \"./contractBase\";\n\nexport type FetchContractMapEntryFn = typeof fetchContractMapEntry;\n\nexport type GetMapEntryFn<Contracts extends ContractBaseType> = <\n  T extends StringOnly<keyof Contracts>,\n  F extends StringOnly<keyof Contracts[T]>,\n  Descriptor extends Contracts[T][F]\n>(\n  contractName: T,\n  mapName: F,\n  mapKey: Descriptor extends MapEntryDescriptor\n    ? ParameterObjOfDescriptor<Descriptor>\n    : never,\n  options?: {\n    deployerAddress?: string;\n    fetchContractMapEntry?: FetchContractMapEntryFn;\n  }\n) => Promise<\n  Descriptor extends MapEntryDescriptor\n    ? ReturnTypeOfDescriptor<Descriptor>\n    : never\n>;\n\nexport const getMapEntryFactory =\n  <T extends ContractBaseType>(\n    contracts: T,\n    factoryOptions: {\n      deployerAddress?: string;\n      fetchContractMapEntry?: FetchContractMapEntryFn;\n    }\n  ): GetMapEntryFn<T> =>\n  async (contractName, mapName, mapKey, options = {}) => {\n    const descriptor = contracts[contractName][mapName];\n\n    if (descriptor.mode !== \"mapEntry\") {\n      throw new Error(\n        `[getMapEntry] ${contractName}.${mapName} should be a mapEntry`\n      );\n    }\n\n    const clarityMapKey = descriptor.input.encode(mapKey);\n\n    const deployerAddress =\n      options.deployerAddress ?? factoryOptions.deployerAddress;\n    if (deployerAddress == null) {\n      throw new Error(`[getMapEntry] deployer address required`);\n    }\n\n    const _fetchContractMapEntry =\n      options.fetchContractMapEntry ??\n      factoryOptions.fetchContractMapEntry ??\n      fetchContractMapEntry;\n\n    const result = await _fetchContractMapEntry({\n      contractName,\n      mapName,\n      mapKey: clarityMapKey,\n      contractAddress: deployerAddress,\n    });\n\n    return descriptor.output.decode(result);\n  };\n"]}