{"version":3,"file":"indexer.mjs","names":[],"sources":["../../src/testing/indexer.ts"],"sourcesContent":["/**\n * Runs the given indexer call until a 404 error is no longer returned.\n * Tried every 200ms up to 100 times.\n * Very rudimentary implementation designed for automated testing.\n * @example\n * ```typescript\n * const transaction = await runWhenIndexerCaughtUp(() => indexer.lookupTransactionByID(txnId).do())\n * ```\n * @param run The code to run\n * @returns The result (as a promise), or throws if the indexer didn't catch up in time\n */\nexport async function runWhenIndexerCaughtUp<T>(run: () => Promise<T>): Promise<T> {\n  let result: T | null = null\n  let ok = false\n  let tries = 0\n  while (!ok) {\n    try {\n      result = await run()\n      ok = true\n      // eslint-disable-next-line @typescript-eslint/no-explicit-any\n    } catch (e: any) {\n      if (e?.status === 404) {\n        tries++\n        if (tries > 100) {\n          throw e\n        }\n        await new Promise<void>((resolve) => setTimeout(resolve, 200))\n      } else {\n        throw e\n      }\n    }\n  }\n\n  return result as T\n}\n"],"mappings":";;;;;;;;;;;;AAWA,eAAsB,uBAA0B,KAAmC;CACjF,IAAI,SAAmB;CACvB,IAAI,KAAK;CACT,IAAI,QAAQ;CACZ,OAAO,CAAC,IACN,IAAI;EACF,SAAS,MAAM,IAAI;EACnB,KAAK;CAEP,SAAS,GAAQ;EACf,IAAI,GAAG,WAAW,KAAK;GACrB;GACA,IAAI,QAAQ,KACV,MAAM;GAER,MAAM,IAAI,SAAe,YAAY,WAAW,SAAS,GAAG,CAAC;EAC/D,OACE,MAAM;CAEV;CAGF,OAAO;AACT"}