From d1fc4c116271c04d9d62db0a791ddd9343b4418a Mon Sep 17 00:00:00 2001 From: Jordan Ribbink Date: Mon, 20 Jan 2025 14:28:22 -0800 Subject: [PATCH] Fix args type for `fcl.query` & `fcl.mutate` --- .changeset/chilled-wombats-reply.md | 5 +++ packages/fcl-core/src/exec/args.ts | 11 ++++++ packages/fcl-core/src/exec/mutate.js | 2 +- packages/fcl-core/src/exec/query.js | 2 +- packages/fcl-core/src/fcl-core.ts | 53 ---------------------------- 5 files changed, 18 insertions(+), 55 deletions(-) create mode 100644 .changeset/chilled-wombats-reply.md create mode 100644 packages/fcl-core/src/exec/args.ts diff --git a/.changeset/chilled-wombats-reply.md b/.changeset/chilled-wombats-reply.md new file mode 100644 index 000000000..68deeddbc --- /dev/null +++ b/.changeset/chilled-wombats-reply.md @@ -0,0 +1,5 @@ +--- +"@onflow/fcl-core": patch +--- + +Fix args type for `fcl.query` & `fcl.mutate` diff --git a/packages/fcl-core/src/exec/args.ts b/packages/fcl-core/src/exec/args.ts new file mode 100644 index 000000000..e52956616 --- /dev/null +++ b/packages/fcl-core/src/exec/args.ts @@ -0,0 +1,11 @@ +import {arg} from "@onflow/sdk" +import * as t from "@onflow/types" + +type ArgFn = typeof arg +type Types = typeof t +/** + * @param arg - Argument function to define a single argument + * @param t - Cadence Types object used to define the type + * @returns {any[]} + */ +export type ArgsFn = (arg: ArgFn, t: Types) => any[] diff --git a/packages/fcl-core/src/exec/mutate.js b/packages/fcl-core/src/exec/mutate.js index b2ad5cea1..c2744eef4 100644 --- a/packages/fcl-core/src/exec/mutate.js +++ b/packages/fcl-core/src/exec/mutate.js @@ -18,7 +18,7 @@ export const getMutate = currentUserOrConfig => { * * @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 {import("./args").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 diff --git a/packages/fcl-core/src/exec/query.js b/packages/fcl-core/src/exec/query.js index 4f3708e97..d8de0cf45 100644 --- a/packages/fcl-core/src/exec/query.js +++ b/packages/fcl-core/src/exec/query.js @@ -9,7 +9,7 @@ import {preQuery} from "./utils/pre.js" * * @param {object} opts - Query Options and configuration * @param {string} opts.cadence - Cadence Script used to query Flow - * @param {import("../fcl").ArgsFn} [opts.args] - Arguments passed to cadence script + * @param {import("./args").ArgsFn} [opts.args] - Arguments passed to cadence script * @param {object | string} [opts.template] - Interaction Template for a script * @param {number} [opts.limit] - Compute Limit for Query * @returns {Promise} diff --git a/packages/fcl-core/src/fcl-core.ts b/packages/fcl-core/src/fcl-core.ts index 2fd120fe5..6055cafd0 100644 --- a/packages/fcl-core/src/fcl-core.ts +++ b/packages/fcl-core/src/fcl-core.ts @@ -69,59 +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. - * @property {any} UInt - Represents the UInt type. - * @property {any} Int - Represents the Int type. - * @property {any} UInt8 - Represents the UInt8 type. - * @property {any} Int8 - Represents the Int8 type. - * @property {any} UInt16 - Represents the UInt16 type. - * @property {any} Int16 - Represents the Int16 type. - * @property {any} UInt32 - Represents the UInt32 type. - * @property {any} Int32 - Represents the Int32 type. - * @property {any} UInt64 - Represents the UInt64 type. - * @property {any} Int64 - Represents the Int64 type. - * @property {any} UInt128 - Represents the UInt128 type. - * @property {any} Int128 - Represents the Int128 type. - * @property {any} UInt256 - Represents the UInt256 type. - * @property {any} Int256 - Represents the Int256 type. - * @property {any} Word8 - Represents the Word8 type. - * @property {any} Word16 - Represents the Word16 type. - * @property {any} Word32 - Represents the Word32 type. - * @property {any} Word64 - Represents the Word64 type. - * @property {any} UFix64 - Represents the UFix64 type. - * @property {any} Fix64 - Represents the Fix64 type. - * @property {any} String - Represents the String type. - * @property {any} Character - Represents the Character type. - * @property {any} Bool - Represents the Bool type. - * @property {any} Address - Represents the Address type. - * @property {any} Void - Represents the Void type. - * @property {any} Optional - Represents the Optional type. - * @property {any} Reference - Represents the Reference type. - * @property {any} Array - Represents the Array type. - * @property {any} Dictionary - Represents the Dictionary type. - * @property {any} Event - Represents the Event type. - * @property {any} Resource - Represents the Resource type. - * @property {any} Struct - Represents the Struct type. - * @property {any} Enum - Represents the Enum type. - * @property {any} Path - Represents the Path type. - */ - -/** - * @callback ArgsFn - * @param {ArgFn} arg - Argument function to define a single argument - * @param {Types} t - Cadence Types object used to define the type - * @returns {any[]} - */ - -/** - * @callback ArgFn - * @param {any} value - the value of the argument - * @param {any} type - the cadence type of the value - * @returns {any} - */ - import {watchForChainIdChanges} from "./utils" // Set chain id default on access node change