diff --git a/.changeset/fluffy-zebras-confess.md b/.changeset/fluffy-zebras-confess.md new file mode 100644 index 000000000..a1ad7f6a4 --- /dev/null +++ b/.changeset/fluffy-zebras-confess.md @@ -0,0 +1,5 @@ +--- +"@onflow/fcl": patch +--- + +Fix `fcl.mutate` typedef diff --git a/packages/fcl/onflow-fcl-1.5.0-alpha.2.tgz b/packages/fcl/onflow-fcl-1.5.0-alpha.2.tgz deleted file mode 100644 index 7c980acd7..000000000 Binary files a/packages/fcl/onflow-fcl-1.5.0-alpha.2.tgz and /dev/null differ diff --git a/packages/fcl/src/exec/mutate.js b/packages/fcl/src/exec/mutate.js index 4238194a8..c1dae1eec 100644 --- a/packages/fcl/src/exec/mutate.js +++ b/packages/fcl/src/exec/mutate.js @@ -5,63 +5,67 @@ import {prepTemplateOpts} from "./utils/prep-template-opts.js" import {preMutate} from "./utils/pre.js" import {isNumber} from "./utils/is" -/** - * @description - * Allows you to submit transactions to the blockchain to potentially mutate the state. - * - * @param {object} opts - Mutation Options and configuration - * @param {string} opts.platform - platform that runs the function - * @param {string} opts.cadence - Cadence Transaction used to mutate Flow - * @param {import("../fcl").ArgsFn} [opts.args] - Arguments passed to cadence transaction - * @param {object} [opts.template] - Interaction Template for a transaction - * @param {number} [opts.limit] - Compute Limit for transaction - * @returns {Promise} Transaction Id - * - * @example - * fcl.mutate({ - * cadence: ` - * transaction(a: Int, b: Int, c: Address) { - * prepare(acct: AuthAccount) { - * log(acct) - * log(a) - * log(b) - * log(c) - * } - * } - * `, - * args: (arg, t) => [ - * arg(6, t.Int), - * arg(7, t.Int), - * arg("0xba1132bc08f82fe2", t.Address), - * ], - * }) - * - * - * Options: - * type Options = { - * template: InteractionTemplate | String // InteractionTemplate or url to one - * cadence: String!, - * args: (arg, t) => Array, - * limit: Number, - * authz: AuthzFn, // will overload the trinity of signatory roles - * proposer: AuthzFn, // will overload the proposer signatory role - * payer: AuthzFn, // will overload the payer signatory role - * authorizations: [AuthzFn], // an array of authorization functions used as authorizations signatory roles - * } - */ -export const getMutate = ({platform}) => async (opts = {}) => { - var txid - try { - await preMutate(opts) - opts = await prepTemplateOpts(opts) - const currentUser = getCurrentUser({platform}) - // Allow for a config to overwrite the authorization function. - // prettier-ignore - const authz = await sdk.config().get("fcl.authz", currentUser().authorization) - - txid = sdk.config().overload(opts.dependencies || {}, async () => +export const getMutate = ({platform}) => { + /** + * @description + * Allows you to submit transactions to the blockchain to potentially mutate the state. + * + * @param {object} [opts] - Mutation Options and configuration + * @param {string} [opts.cadence] - Cadence Transaction used to mutate Flow + * @param {import("../shared-exports").ArgsFn} [opts.args] - Arguments passed to cadence transaction + * @param {object | string} [opts.template] - Interaction Template for a transaction + * @param {number} [opts.limit] - Compute Limit for transaction + * @param {Function} [opts.authz] - Authorization function for transaction + * @param {Function} [opts.proposer] - Proposer Authorization function for transaction + * @param {Function} [opts.payer] - Payer Authorization function for transaction + * @param {Array} [opts.authorizations] - Authorizations function for transaction + * @returns {Promise} Transaction Id + * + * @example + * fcl.mutate({ + * cadence: ` + * transaction(a: Int, b: Int, c: Address) { + * prepare(acct: AuthAccount) { + * log(acct) + * log(a) + * log(b) + * log(c) + * } + * } + * `, + * args: (arg, t) => [ + * arg(6, t.Int), + * arg(7, t.Int), + * arg("0xba1132bc08f82fe2", t.Address), + * ], + * }) + * + * + * Options: + * type Options = { + * template: InteractionTemplate | String // InteractionTemplate or url to one + * cadence: String!, + * args: (arg, t) => Array, + * limit: Number, + * authz: AuthzFn, // will overload the trinity of signatory roles + * proposer: AuthzFn, // will overload the proposer signatory role + * payer: AuthzFn, // will overload the payer signatory role + * authorizations: [AuthzFn], // an array of authorization functions used as authorizations signatory roles + * } + */ + const mutate = async (opts = {}) => { + var txid + try { + await preMutate(opts) + opts = await prepTemplateOpts(opts) + const currentUser = getCurrentUser({platform}) + // Allow for a config to overwrite the authorization function. // prettier-ignore - sdk.send([ + const authz = await sdk.config().get("fcl.authz", currentUser().authorization) + + txid = sdk.config().overload(opts.dependencies || {}, async () => + // prettier-ignore + sdk.send([ sdk.transaction(opts.cadence), sdk.args(normalizeArgs(opts.args || [])), @@ -77,10 +81,13 @@ export const getMutate = ({platform}) => async (opts = {}) => { // opts.authorizations > [opts.authz > authz] sdk.authorizations(opts.authorizations || [opts.authz || authz]), ]).then(sdk.decode) - ) + ) - return txid - } catch (error) { - throw error + return txid + } catch (error) { + throw error + } } + + return mutate } diff --git a/packages/fcl/src/shared-exports.js b/packages/fcl/src/shared-exports.js index 6af05770f..35b0e1090 100644 --- a/packages/fcl/src/shared-exports.js +++ b/packages/fcl/src/shared-exports.js @@ -69,7 +69,6 @@ export {params, param} from "@onflow/sdk" export {validator} from "@onflow/sdk" export {invariant} from "@onflow/sdk" - /** * @typedef {object} Types * @property {any} Identity - Represents the Identity type.