{"version":3,"file":"call-composer-types.mjs","sources":["../../src/client/call-composer-types.ts"],"sourcesContent":["import { DecIndentAndCloseBlock, DocumentParts, IncIndent, jsDoc, NewLine } from '../output/writer'\nimport { GeneratorContext } from './generator-context'\n\nimport { BARE_CALL, MethodList } from './helpers/get-call-config-summary'\nimport { getCreateOnCompleteOptions } from './deploy-types'\nimport { ABIMethod } from 'algosdk'\n\nexport function* callComposerType(ctx: GeneratorContext): DocumentParts {\n  const { name, callConfig, app } = ctx\n  yield `export type ${name}Composer<TReturns extends [...any[]] = []> = {`\n  yield IncIndent\n\n  yield* callComposerTypeNoops(ctx)\n  if (ctx.mode === 'full') {\n    yield* callComposerOperationMethodType(\n      ctx,\n      `Updates an existing instance of the ${app.name} smart contract`,\n      callConfig.updateMethods,\n      'update',\n    )\n    yield* callComposerOperationMethodType(\n      ctx,\n      `Deletes an existing instance of the ${app.name} smart contract`,\n      callConfig.deleteMethods,\n      'delete',\n    )\n  }\n  yield* callComposerOperationMethodType(\n    ctx,\n    `Opts the user into an existing instance of the ${app.name} smart contract`,\n    callConfig.optInMethods,\n    'optIn',\n  )\n  yield* callComposerOperationMethodType(\n    ctx,\n    `Makes a close out call to an existing instance of the ${app.name} smart contract`,\n    callConfig.closeOutMethods,\n    'closeOut',\n  )\n\n  yield* callComposerTypeClearState(ctx)\n\n  yield* jsDoc({\n    description: 'Adds a transaction to the composer',\n    params: {\n      txn: 'A transaction to add to the transaction group',\n      signer: 'The optional signer to use when signing this transaction.',\n    },\n  })\n  yield `addTransaction(txn: Transaction, signer?: TransactionSigner): ${name}Composer<TReturns>`\n\n  yield* jsDoc({\n    description: 'Returns the underlying AtomicTransactionComposer instance',\n  })\n  yield `composer(): Promise<TransactionComposer>`\n\n  yield* jsDoc({\n    description: 'Simulates the transaction group and returns the result',\n  })\n  yield `simulate(): Promise<${name}ComposerResults<TReturns> & { simulateResponse: modelsv2.SimulateResponse }>`\n  yield `simulate(options: SkipSignaturesSimulateOptions): Promise<${name}ComposerResults<TReturns> & { simulateResponse: modelsv2.SimulateResponse }>`\n  yield `simulate(options: RawSimulateOptions): Promise<${name}ComposerResults<TReturns> & { simulateResponse: modelsv2.SimulateResponse }>`\n\n  yield* jsDoc({\n    description: 'Sends the transaction group to the network and returns the results',\n  })\n  yield `send(params?: SendParams): Promise<${name}ComposerResults<TReturns>>`\n\n  yield DecIndentAndCloseBlock\n\n  yield `\n  export type ${name}ComposerResults<TReturns extends [...any[]]> = Expand<SendAtomicTransactionComposerResults & {\n    returns: TReturns\n  }>\n  `\n}\n\nfunction* callComposerTypeClearState({ app, name }: GeneratorContext): DocumentParts {\n  yield* jsDoc({\n    description: `Makes a clear_state call to an existing instance of the ${app.name} smart contract.`,\n    params: {\n      args: `The arguments for the bare call`,\n    },\n    returns: `The typed transaction composer so you can fluently chain multiple calls or call execute to execute all queued up transactions`,\n  })\n  yield `clearState(params?: AppClientBareCallParams): ${name}Composer<[...TReturns, undefined]>`\n  yield NewLine\n}\n\nfunction* callComposerTypeNoops({ app, name, callConfig, methodSignatureToUniqueName, sanitizer }: GeneratorContext): DocumentParts {\n  for (const method of app.methods) {\n    const methodSig = new ABIMethod(method).getSignature()\n    const methodSigSafe = sanitizer.makeSafeStringTypeLiteral(methodSig)\n    const methodName = sanitizer.makeSafeMethodIdentifier(methodSignatureToUniqueName[methodSig])\n    // Skip methods which don't support a no_op call config\n    if (!callConfig.callMethods.includes(methodSig)) continue\n\n    yield* jsDoc({\n      description: `Calls the ${new ABIMethod(method).getSignature()} ABI method.`,\n      abiDescription: method.desc,\n      params: {\n        args: `The arguments for the contract call`,\n        params: `Any additional parameters for the call`,\n      },\n      returns: `The typed transaction composer so you can fluently chain multiple calls or call execute to execute all queued up transactions`,\n    })\n    yield `${methodName}(params?: CallParams<${name}Args['obj']['${methodSigSafe}'] | ${name}Args['tuple']['${methodSigSafe}']>): ${name}Composer<[...TReturns, ${name}Returns['${methodSigSafe}'] | undefined]>`\n    yield NewLine\n  }\n}\n\nfunction* callComposerOperationMethodType(\n  { app, methodSignatureToUniqueName, name, sanitizer }: GeneratorContext,\n  description: string,\n  methods: MethodList,\n  verb: 'create' | 'update' | 'optIn' | 'closeOut' | 'delete',\n  includeCompilation?: boolean,\n): DocumentParts {\n  if (methods.length) {\n    yield* jsDoc(`Gets available ${verb} methods`)\n    yield `readonly ${verb}: {`\n    yield IncIndent\n    for (const methodSig of methods) {\n      const onComplete = verb === 'create' ? getCreateOnCompleteOptions(methodSig, app) : undefined\n      if (methodSig === BARE_CALL) {\n        yield* jsDoc({\n          description: `${description} using a bare call.`,\n          params: {\n            args: `The arguments for the bare call`,\n          },\n          returns: `The typed transaction composer so you can fluently chain multiple calls or call execute to execute all queued up transactions`,\n        })\n        yield `bare(params${onComplete?.isOptional !== false ? '?' : ''}: AppClientBareCallParams ${\n          includeCompilation ? '& AppClientCompilationParams' : ''\n        }): ${name}Composer<[...TReturns, undefined]>`\n      } else {\n        const uniqueName = methodSignatureToUniqueName[methodSig]\n        yield* jsDoc({\n          description: `${description} using the ${methodSig} ABI method.`,\n          params: {\n            args: `The arguments for the smart contract call`,\n            params: `Any additional parameters for the call`,\n          },\n          returns: `The typed transaction composer so you can fluently chain multiple calls or call execute to execute all queued up transactions`,\n        })\n        const methodSigSafe = sanitizer.makeSafeStringTypeLiteral(methodSig)\n        yield `${sanitizer.makeSafeMethodIdentifier(uniqueName)}(params${\n          onComplete?.isOptional !== false ? '?' : ''\n        }: CallParams<${name}Args['obj']['${methodSigSafe}'] | ${name}Args['tuple']['${methodSigSafe}']>${includeCompilation ? ' & AppClientCompilationParams' : ''}${\n          onComplete?.type ? ` & ${onComplete.type}` : ''\n        }): ${name}Composer<[...TReturns, ${name}Returns['${methodSigSafe}'] | undefined]>`\n      }\n    }\n    yield DecIndentAndCloseBlock\n    yield NewLine\n  }\n}\n"],"names":[],"mappings":";;;;;AAOM,UAAW,gBAAgB,CAAC,GAAqB,EAAA;IACrD,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,GAAG,EAAE,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