{"version":3,"file":"latest.mjs","names":[],"sources":["../../src/account-bindings/latest.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\n// Account calls target the latest `account` package, while `accountPackageId` stays the\n// original id everywhere: the derived wrapper and account addresses and every type tag are\n// built from it, because Move types keep their defining package across upgrades. A PTB can't\n// call a package at an older version than another package in it links, and Predict's Version 5\n// links account v2, so an account call at the original id beside it aborts `InvalidLinkage`.\n// The generated bindings resolve their package from `config.accountPackageId`, so every one is\n// wrapped here to resolve `package`, then `config.accountPackageIdLatest`, then that.\n\nexport interface AccountCallOptions {\n\tpackage?: string;\n\tconfig?: { accountPackageId?: string; accountPackageIdLatest?: string };\n}\n\n/** An options type whose `config` also accepts the latest account package. */\nexport type WithLatestConfig<Options> = Options extends { config?: infer Config }\n\t? Omit<Options, 'config'> & { config?: Config & { accountPackageIdLatest?: string } }\n\t: Options;\n\n/** A generated call whose options' `config` also accepts `accountPackageIdLatest`. */\nexport type LatestAccountCall<Call> = Call extends (...args: infer Args) => infer Result\n\t? (...args: { [K in keyof Args]: WithLatestConfig<Args[K]> }) => Result\n\t: never;\n\n/**\n * The generated call with its package resolved to the latest account package. Options stay\n * optional where the generated call's are; `config` also accepts `accountPackageIdLatest`.\n */\nexport function latestAccountPackage<Call extends (options: never) => unknown>(\n\tcall: Call,\n): LatestAccountCall<Call> {\n\tconst wrapped = (options?: AccountCallOptions) => {\n\t\tconst target = options?.package ?? options?.config?.accountPackageIdLatest;\n\t\treturn (call as unknown as (options?: AccountCallOptions) => unknown)(\n\t\t\ttarget ? { ...options, package: target } : options,\n\t\t);\n\t};\n\treturn wrapped as unknown as LatestAccountCall<Call>;\n}\n"],"mappings":";;;;;AA8BA,SAAgB,qBACf,MAC0B;CAC1B,MAAM,WAAW,YAAiC;EACjD,MAAM,SAAS,SAAS,WAAW,SAAS,QAAQ;AACpD,SAAQ,KACP,SAAS;GAAE,GAAG;GAAS,SAAS;GAAQ,GAAG,QAC3C;;AAEF,QAAO"}