{"version":3,"file":"Operation.cjs","sources":["../../../src/types/Operation.ts"],"sourcesContent":["import { Commitment, ConfirmOptions } from '@solana/web3.js';\nimport { Signer } from './Signer';\nimport { Program } from './Program';\nimport { Convergence } from '@/Convergence';\nimport { DisposableScope, RequiredKeys } from '@/utils';\n\nexport type KeyOfOperation<T> = T extends Operation<infer N, unknown, unknown>\n  ? N\n  : never;\nexport type InputOfOperation<T> = T extends Operation<string, infer I, unknown>\n  ? I\n  : never;\nexport type OutputOfOperation<T> = T extends Operation<string, unknown, infer O>\n  ? O\n  : never;\n\nexport type Operation<K extends string, I, O> = {\n  key: K;\n  input: I;\n\n  // This is necessary for type inference.\n  __output?: O;\n};\n\nexport type OperationConstructor<\n  T extends Operation<K, I, O>,\n  K extends string = KeyOfOperation<T>,\n  I = InputOfOperation<T>,\n  O = OutputOfOperation<T>\n> = {\n  key: string;\n  (input: I): T;\n};\n\nexport type OperationOptions = {\n  /**\n   * The wallet that should pay for transaction fees and,\n   * potentially, rent-exempt fees to create accounts.\n   *\n   * Defaults to the default fee payer of the RPC module which,\n   * itself, defaults to the current identity.\n   *\n   * You may set this option globally by calling\n   * `convergence.rpc.setDefaultFeePayer(payer)`.\n   *\n   * @defaultValue `convergence.rpc().getDefaultFeePayer()`\n   */\n  payer?: Signer;\n\n  /**\n   * The level of commitment desired when querying\n   * the state of the blockchain.\n   *\n   * @defaultValue Defaults to `undefined` which will use\n   * the commitment level set on the `Connection` object.\n   */\n  commitment?: Commitment;\n\n  /**\n   * Options for confirming transactions as defined by\n   * the Solana web3.js library.\n   *\n   * @defaultValue { commitment: options.commitment }`\n   * if the `commitment` option is set, otherwise `{}`.\n   */\n  confirmOptions?: ConfirmOptions;\n\n  /**\n   * An optional set of programs that override the registered ones.\n   *\n   * You may set this option globally by calling\n   * `convergence.programs().register(programs)`.\n   *\n   * @defaultValue `[]`\n   */\n  programs?: Program[];\n\n  /**\n   * An abort signal that can be used to cancel the operation\n   * should that operation support it.\n   *\n   * @example\n   * ```ts\n   * // Creates an AbortController that aborts in one second.\n   * const abortController = new AbortController();\n   * setTimeout(() => abortController.abort(), 1000);\n   *\n   * // Use the AbortController's signal to cancel the operation after one second.\n   * await convergence.rfqs().findByMint(input, { signal: abortController.signal });\n   * ```\n   *\n   * @defaultValue Defaults to not using an abort signal.\n   */\n  signal?: AbortSignal;\n};\n\nexport type OperationScope = DisposableScope &\n  RequiredKeys<OperationOptions, 'payer'>;\n\nexport type OperationHandler<\n  T extends Operation<K, I, O>,\n  K extends string = KeyOfOperation<T>,\n  I = InputOfOperation<T>,\n  O = OutputOfOperation<T>\n> = {\n  handle: (\n    operation: T,\n    convergence: Convergence,\n    scope: OperationScope\n  ) => O | Promise<O> | AsyncGenerator<O, void, void>;\n};\n\nexport type SyncOperationHandler<\n  T extends Operation<K, I, O>,\n  K extends string = KeyOfOperation<T>,\n  I = InputOfOperation<T>,\n  O = OutputOfOperation<T>\n> = {\n  handle: (operation: T, convergence: Convergence) => O;\n};\n\n/**\n * @group Operations\n * @category Constructors\n */\nexport const useOperation = <\n  T extends Operation<K, I, O>,\n  K extends string = KeyOfOperation<T>,\n  I = InputOfOperation<T>,\n  O = OutputOfOperation<T>\n>(\n  key: K\n): OperationConstructor<T, K, I, O> => {\n  const constructor = (input: I) => {\n    return {\n      key,\n      input,\n    } as T;\n  };\n  constructor.key = key;\n\n  return constructor;\n};\n\nexport const makeConfirmOptionsFinalizedOnMainnet = (\n  convergence: Convergence,\n  options?: ConfirmOptions\n): ConfirmOptions | undefined => {\n  return convergence.cluster === 'mainnet-beta'\n    ? { ...options, commitment: 'finalized' }\n    : options;\n};\n"],"names":["useOperation","key","constructor","input","makeConfirmOptionsFinalizedOnMainnet","convergence","options","cluster","_objectSpread","commitment"],"mappings":";;;;;;AAyHA;AACA;AACA;AACA;IACaA,YAAY,GAAG,SAAfA,YAAYA,CAMvBC,GAAM,EAC+B;AACrC,EAAA,IAAMC,WAAW,GAAG,SAAdA,WAAWA,CAAIC,KAAQ,EAAK;IAChC,OAAO;AACLF,MAAAA,GAAG,EAAHA,GAAG;AACHE,MAAAA,KAAK,EAALA,KAAAA;KACD,CAAA;GACF,CAAA;EACDD,WAAW,CAACD,GAAG,GAAGA,GAAG,CAAA;AAErB,EAAA,OAAOC,WAAW,CAAA;AACpB,EAAC;AAEM,IAAME,oCAAoC,GAAG,SAAvCA,oCAAoCA,CAC/CC,WAAwB,EACxBC,OAAwB,EACO;EAC/B,OAAOD,WAAW,CAACE,OAAO,KAAK,cAAc,GAAAC,uCAAA,CAAAA,uCAAA,CAAA,EAAA,EACpCF,OAAO,CAAA,EAAA,EAAA,EAAA;AAAEG,IAAAA,UAAU,EAAE,WAAA;AAAW,GAAA,CAAA,GACrCH,OAAO,CAAA;AACb;;;;;"}