{"version":3,"file":"shared.mjs","names":[],"sources":["../../src/commands/shared.ts"],"sourcesContent":["import consola from \"consola\";\nimport type { Provider, ProviderCapability } from \"../core/provider.js\";\nimport type { ChainKey } from \"../core/types.js\";\n\nexport interface SelectedProvider {\n  readonly chain: ChainKey;\n  readonly name: string;\n  readonly provider: Provider;\n}\n\nexport async function withSelectedProvider<T>(\n  chainInput: string | undefined,\n  providerInput: string | undefined,\n  capability: ProviderCapability,\n  /* oxlint-disable-next-line typescript/prefer-readonly-parameter-types */\n  run: (selected: SelectedProvider) => Promise<T>,\n): Promise<T> {\n  const [{ withProvider }, { normalizeChain }] = await Promise.all([\n    import(\"../core/resolve.js\"),\n    import(\"../core/types.js\"),\n  ]);\n  const requestedChain = chainInput === undefined ? undefined : normalizeChain(chainInput);\n  return withProvider(providerInput, requestedChain, run, capability);\n}\n\nexport function failCommand(message: string): never {\n  consola.error(message);\n  process.exit(1);\n}\n\nfunction parseInteger(value: string, message: string, minimum: number): number {\n  const text = value.trim();\n  const number = Number(text);\n  if (!/^\\d+$/.test(text) || !Number.isSafeInteger(number) || number < minimum)\n    failCommand(message);\n  return number;\n}\n\nexport function parseNonNegativeInteger(value: string, message: string): number {\n  return parseInteger(value, message, 0);\n}\n\nexport function parsePositiveInteger(value: string, message: string): number {\n  return parseInteger(value, message, 1);\n}\n\nexport function reportCommandError(error: unknown): never {\n  consola.error(`Error: ${error instanceof Error ? error.message : String(error)}`);\n  process.exit(1);\n}\n\n// oxlint-disable-next-line no-control-regex -- Terminal control bytes are precisely what this boundary removes.\nconst TERMINAL_CONTROLS = /[\\u0000-\\u0008\\u000A-\\u001F\\u007F-\\u009F\\u2028\\u2029]/gu;\n\n/**\n * Print one result line. A token symbol, a contract name or a decoded method is text a stranger\n * chose, so the control bytes a terminal would obey are dropped, and every line break with them,\n * since a field that breaks the line poses as the next result line. Only tab survives.\n *\n * @param {string} line - One line of a result, as the renderer composed it.\n */\nexport function print(line: string): void {\n  consola.log(line.replace(TERMINAL_CONTROLS, \"\"));\n}\n"],"mappings":";AAUA,eAAsB,qBACpB,YACA,eACA,YAEA,KACY;CACZ,MAAM,CAAC,EAAE,gBAAgB,EAAE,oBAAoB,MAAM,QAAQ,IAAI,CAC/D,OAAO,gBAAqB,CAAA,MAAA,MAAA,EAAA,eAAA,GAC5B,OAAO,cAAmB,CAAA,MAAA,MAAA,EAAA,aAAA,CAC5B,CAAC;CAED,OAAO,aAAa,eADG,eAAe,KAAA,IAAY,KAAA,IAAY,eAAe,UAAU,GACpC,KAAK,UAAU;AACpE;AAEA,SAAgB,YAAY,SAAwB;CAClD,QAAQ,MAAM,OAAO;CACrB,QAAQ,KAAK,CAAC;AAChB;AAEA,SAAS,aAAa,OAAe,SAAiB,SAAyB;CAC7E,MAAM,OAAO,MAAM,KAAK;CACxB,MAAM,SAAS,OAAO,IAAI;CAC1B,IAAI,CAAC,QAAQ,KAAK,IAAI,KAAK,CAAC,OAAO,cAAc,MAAM,KAAK,SAAS,SACnE,YAAY,OAAO;CACrB,OAAO;AACT;AAEA,SAAgB,wBAAwB,OAAe,SAAyB;CAC9E,OAAO,aAAa,OAAO,SAAS,CAAC;AACvC;AAEA,SAAgB,qBAAqB,OAAe,SAAyB;CAC3E,OAAO,aAAa,OAAO,SAAS,CAAC;AACvC;AAEA,SAAgB,mBAAmB,OAAuB;CACxD,QAAQ,MAAM,UAAU,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,GAAG;CAChF,QAAQ,KAAK,CAAC;AAChB;AAGA,MAAM,oBAAoB"}