diff --git a/.changeset/brown-dingos-taste.md b/.changeset/brown-dingos-taste.md new file mode 100644 index 000000000..3aea43be6 --- /dev/null +++ b/.changeset/brown-dingos-taste.md @@ -0,0 +1,9 @@ +--- +"@onflow/transport-http": minor +"@onflow/typedefs": minor +"@onflow/types": minor +"@onflow/fcl": minor +"@onflow/sdk": minor +--- + +TS conversion diff --git a/package-lock.json b/package-lock.json index 71963fc99..35eef3738 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14,11 +14,15 @@ "@changesets/cli": "^2.21.1", "@types/jest": "^29.5.3", "@types/node": "^18.11.18", + "@typescript-eslint/eslint-plugin": "^6.3.0", + "@typescript-eslint/parser": "^6.3.0", + "eslint": "^8.46.0", "jest": "^29.5.0", "jest-environment-jsdom": "^29.5.0", "lerna": "^6.6.2", "prettier": "^2.6.2", - "ts-jest": "^29.1.1" + "ts-jest": "^29.1.1", + "typescript": "^5.1.6" } }, "node_modules/@aashutoshrathi/word-wrap": { @@ -175,8 +179,7 @@ }, "node_modules/@babel/helper-create-class-features-plugin": { "version": "7.22.15", - "resolved": "https://registry.npmjs.org/@babel/helper-create-class-features-plugin/-/helper-create-class-features-plugin-7.22.15.tgz", - "integrity": "sha512-jKkwA59IXcvSaiK2UN45kKwSC9o+KuoXsBDvHvU/7BecYIp8GQ2UwrVvFgJASUT+hBnwJx6MhvMCuMzwZZ7jlg==", + "license": "MIT", "dependencies": { "@babel/helper-annotate-as-pure": "^7.22.5", "@babel/helper-environment-visitor": "^7.22.5", @@ -240,8 +243,7 @@ }, "node_modules/@babel/helper-environment-visitor": { "version": "7.22.20", - "resolved": "https://registry.npmjs.org/@babel/helper-environment-visitor/-/helper-environment-visitor-7.22.20.tgz", - "integrity": "sha512-zfedSIzFhat/gFhWfHtgWvlec0nqB9YEIVrpuwjruLlXfUSnA8cJB0miHKwqDnQ7d32aKo2xt88/xZptwxbfhA==", + "license": "MIT", "engines": { "node": ">=6.9.0" } @@ -279,8 +281,7 @@ }, "node_modules/@babel/helper-member-expression-to-functions": { "version": "7.23.0", - "resolved": "https://registry.npmjs.org/@babel/helper-member-expression-to-functions/-/helper-member-expression-to-functions-7.23.0.tgz", - "integrity": "sha512-6gfrPwh7OuT6gZyJZvd6WbTfrqAo7vm4xCzAXOusKqq/vWdKXphTpj5klHKNmRUU6/QRGlBsyU9mAIPaWHlqJA==", + "license": "MIT", "dependencies": { "@babel/types": "^7.23.0" }, @@ -290,8 +291,7 @@ }, "node_modules/@babel/helper-module-imports": { "version": "7.22.15", - "resolved": "https://registry.npmjs.org/@babel/helper-module-imports/-/helper-module-imports-7.22.15.tgz", - "integrity": "sha512-0pYVBnDKZO2fnSPCrgM/6WMc7eS20Fbok+0r88fp+YtWVLZrp4CkafFGIp+W0VKw4a22sgebPT99y+FDNMdP4w==", + "license": "MIT", "dependencies": { "@babel/types": "^7.22.15" }, @@ -301,8 +301,7 @@ }, "node_modules/@babel/helper-module-transforms": { "version": "7.23.0", - "resolved": "https://registry.npmjs.org/@babel/helper-module-transforms/-/helper-module-transforms-7.23.0.tgz", - "integrity": "sha512-WhDWw1tdrlT0gMgUJSlX0IQvoO1eN279zrAUbVB+KpV2c3Tylz8+GnKOLllCS6Z/iZQEyVYxhZVUdPTqs2YYPw==", + "license": "MIT", "dependencies": { "@babel/helper-environment-visitor": "^7.22.20", "@babel/helper-module-imports": "^7.22.15", @@ -404,16 +403,14 @@ }, "node_modules/@babel/helper-validator-identifier": { "version": "7.22.20", - "resolved": "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-7.22.20.tgz", - "integrity": "sha512-Y4OZ+ytlatR8AI+8KZfKuL5urKp7qey08ha31L8b3BwewJAoJamTzyvxPR/5D+KkdJCGPq/+8TukHBlY10FX9A==", + "license": "MIT", "engines": { "node": ">=6.9.0" } }, "node_modules/@babel/helper-validator-option": { "version": "7.22.15", - "resolved": "https://registry.npmjs.org/@babel/helper-validator-option/-/helper-validator-option-7.22.15.tgz", - "integrity": "sha512-bMn7RmyFjY/mdECUbgn9eoSY4vqvacUnS9i9vGAGttgFWesO6B4CYWA7XlpbWgBt71iv/hfbPlynohStqnu5hA==", + "license": "MIT", "engines": { "node": ">=6.9.0" } @@ -1142,8 +1139,7 @@ }, "node_modules/@babel/plugin-transform-modules-commonjs": { "version": "7.23.0", - "resolved": "https://registry.npmjs.org/@babel/plugin-transform-modules-commonjs/-/plugin-transform-modules-commonjs-7.23.0.tgz", - "integrity": "sha512-32Xzss14/UVc7k9g775yMIvkVK8xwKE0DPdP5JTapr3+Z9w4tzeOuLNY6BXDQR6BdnzIlXnCGAzsk/ICHBLVWQ==", + "license": "MIT", "dependencies": { "@babel/helper-module-transforms": "^7.23.0", "@babel/helper-plugin-utils": "^7.22.5", @@ -1373,8 +1369,7 @@ }, "node_modules/@babel/plugin-transform-typescript": { "version": "7.22.15", - "resolved": "https://registry.npmjs.org/@babel/plugin-transform-typescript/-/plugin-transform-typescript-7.22.15.tgz", - "integrity": "sha512-1uirS0TnijxvQLnlv5wQBwOX3E1wCFX7ITv+9pBV2wKEk4K+M5tqDaoNXnTH8tjEIYHLO98MwiTWO04Ggz4XuA==", + "license": "MIT", "dependencies": { "@babel/helper-annotate-as-pure": "^7.22.5", "@babel/helper-create-class-features-plugin": "^7.22.15", @@ -1525,8 +1520,7 @@ }, "node_modules/@babel/preset-typescript": { "version": "7.23.2", - "resolved": "https://registry.npmjs.org/@babel/preset-typescript/-/preset-typescript-7.23.2.tgz", - "integrity": "sha512-u4UJc1XsS1GhIGteM8rnGiIvf9rJpiVgMEeCnwlLA7WJPC+jcXWJAGxYmeqs5hOZD8BbAfnV5ezBOxQbb4OUxA==", + "license": "MIT", "dependencies": { "@babel/helper-plugin-utils": "^7.22.5", "@babel/helper-validator-option": "^7.22.15", @@ -1595,8 +1589,7 @@ }, "node_modules/@babel/types": { "version": "7.23.0", - "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.23.0.tgz", - "integrity": "sha512-0oIyUfKoI3mSqMvsxBdclDwxXKXAUA8v/apZbc+iSyARYou1o8ZGDxbUYyLFoW2arqS2jDGqJuZvv1d/io1axg==", + "license": "MIT", "dependencies": { "@babel/helper-string-parser": "^7.22.5", "@babel/helper-validator-identifier": "^7.22.20", @@ -2049,9 +2042,8 @@ }, "node_modules/@eslint/js": { "version": "8.52.0", - "resolved": "https://registry.npmjs.org/@eslint/js/-/js-8.52.0.tgz", - "integrity": "sha512-mjZVbpaeMZludF2fsWLD0Z9gCref1Tk4i9+wddjRvpUNqqcndPkBD09N/Mapey0b3jaXbLm2kICwFv2E64QinA==", "dev": true, + "license": "MIT", "engines": { "node": "^12.22.0 || ^14.17.0 || >=16.0.0" } @@ -2063,9 +2055,8 @@ }, "node_modules/@humanwhocodes/config-array": { "version": "0.11.13", - "resolved": "https://registry.npmjs.org/@humanwhocodes/config-array/-/config-array-0.11.13.tgz", - "integrity": "sha512-JSBDMiDKSzQVngfRjOdFXgFfklaXI4K9nLF49Auh21lmBWRLIK3+xTErTWD4KU54pb6coM6ESE7Awz/FNU3zgQ==", "dev": true, + "license": "Apache-2.0", "dependencies": { "@humanwhocodes/object-schema": "^2.0.1", "debug": "^4.1.1", @@ -2089,9 +2080,8 @@ }, "node_modules/@humanwhocodes/object-schema": { "version": "2.0.1", - "resolved": "https://registry.npmjs.org/@humanwhocodes/object-schema/-/object-schema-2.0.1.tgz", - "integrity": "sha512-dvuCeX5fC9dXgJn9t+X5atfmgQAzUOWqS1254Gh0m6i8wKd10ebXkfNKiRK+1GWi/yTvvLDHpoxLr0xxxeslWw==", - "dev": true + "dev": true, + "license": "BSD-3-Clause" }, "node_modules/@hutson/parse-repository-url": { "version": "3.0.2", @@ -5223,9 +5213,8 @@ }, "node_modules/@types/jest": { "version": "29.5.7", - "resolved": "https://registry.npmjs.org/@types/jest/-/jest-29.5.7.tgz", - "integrity": "sha512-HLyetab6KVPSiF+7pFcUyMeLsx25LDNDemw9mGsJBkai/oouwrjTycocSDYopMEwFhN2Y4s9oPyOCZNofgSt2g==", "dev": true, + "license": "MIT", "dependencies": { "expect": "^29.0.0", "pretty-format": "^29.0.0" @@ -5299,6 +5288,12 @@ "version": "2.0.3", "license": "MIT" }, + "node_modules/@types/uuid": { + "version": "9.0.6", + "resolved": "https://registry.npmjs.org/@types/uuid/-/uuid-9.0.6.tgz", + "integrity": "sha512-BT2Krtx4xaO6iwzwMFUYvWBWkV2pr37zD68Vmp1CDV196MzczBRxuEpD6Pr395HAgebC/co7hOphs53r8V7jew==", + "dev": true + }, "node_modules/@types/yargs": { "version": "17.0.24", "dev": true, @@ -5570,9 +5565,8 @@ }, "node_modules/@ungap/structured-clone": { "version": "1.2.0", - "resolved": "https://registry.npmjs.org/@ungap/structured-clone/-/structured-clone-1.2.0.tgz", - "integrity": "sha512-zuVdFrMJiuCDQUMCzQaD6KL28MjnqqN8XnAqiEq9PNm/hCPTSGfrXCOfwj1ow4LFb/tNymJPwsNbVePc1xFqrQ==", - "dev": true + "dev": true, + "license": "ISC" }, "node_modules/@walletconnect/core": { "version": "2.8.1", @@ -8649,9 +8643,8 @@ }, "node_modules/eslint": { "version": "8.52.0", - "resolved": "https://registry.npmjs.org/eslint/-/eslint-8.52.0.tgz", - "integrity": "sha512-zh/JHnaixqHZsolRB/w9/02akBk9EPrOs9JwcTP2ek7yL5bVvXuRariiaAjjoJ5DvuwQ1WAE/HsMz+w17YgBCg==", "dev": true, + "license": "MIT", "dependencies": { "@eslint-community/eslint-utils": "^4.2.0", "@eslint-community/regexpp": "^4.6.1", @@ -18833,7 +18826,6 @@ "node_modules/typescript": { "version": "5.1.6", "license": "Apache-2.0", - "peer": true, "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" @@ -19600,9 +19592,8 @@ }, "packages/config/node_modules/@es-joy/jsdoccomment": { "version": "0.40.1", - "resolved": "https://registry.npmjs.org/@es-joy/jsdoccomment/-/jsdoccomment-0.40.1.tgz", - "integrity": "sha512-YORCdZSusAlBrFpZ77pJjc5r1bQs5caPWtAu+WWmiSo+8XaUzseapVrfAtiRFbQWnrBxxLLEwF6f6ZG/UgCQCg==", "dev": true, + "license": "MIT", "dependencies": { "comment-parser": "1.4.0", "esquery": "^1.5.0", @@ -19614,9 +19605,8 @@ }, "packages/config/node_modules/comment-parser": { "version": "1.4.0", - "resolved": "https://registry.npmjs.org/comment-parser/-/comment-parser-1.4.0.tgz", - "integrity": "sha512-QLyTNiZ2KDOibvFPlZ6ZngVsZ/0gYnE6uTXi5aoDg8ed3AkJAz4sEje3Y8a29hQ1s6A99MZXe47fLAXQ1rTqaw==", "dev": true, + "license": "MIT", "engines": { "node": ">= 12.0.0" } @@ -19634,9 +19624,8 @@ }, "packages/config/node_modules/eslint-plugin-jsdoc": { "version": "46.8.2", - "resolved": "https://registry.npmjs.org/eslint-plugin-jsdoc/-/eslint-plugin-jsdoc-46.8.2.tgz", - "integrity": "sha512-5TSnD018f3tUJNne4s4gDWQflbsgOycIKEUBoCLn6XtBMgNHxQFmV8vVxUtiPxAQq8lrX85OaSG/2gnctxw9uQ==", "dev": true, + "license": "BSD-3-Clause", "dependencies": { "@es-joy/jsdoccomment": "~0.40.1", "are-docs-informative": "^0.0.2", @@ -19657,18 +19646,16 @@ }, "packages/config/node_modules/jsdoc-type-pratt-parser": { "version": "4.0.0", - "resolved": "https://registry.npmjs.org/jsdoc-type-pratt-parser/-/jsdoc-type-pratt-parser-4.0.0.tgz", - "integrity": "sha512-YtOli5Cmzy3q4dP26GraSOeAhqecewG04hoO8DY56CH4KJ9Fvv5qKWUCCo3HZob7esJQHCv6/+bnTy72xZZaVQ==", "dev": true, + "license": "MIT", "engines": { "node": ">=12.0.0" } }, "packages/config/node_modules/lru-cache": { "version": "6.0.0", - "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", - "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==", "dev": true, + "license": "ISC", "dependencies": { "yallist": "^4.0.0" }, @@ -19678,9 +19665,8 @@ }, "packages/config/node_modules/semver": { "version": "7.5.4", - "resolved": "https://registry.npmjs.org/semver/-/semver-7.5.4.tgz", - "integrity": "sha512-1bCSESV6Pv+i21Hvpxp3Dx+pSD8lIPt8uVjRrxAUt/nbswYc+tK6Y2btiULjd4+fnq15PX+nqQDC7Oft7WkwcA==", "dev": true, + "license": "ISC", "dependencies": { "lru-cache": "^6.0.0" }, @@ -20473,6 +20459,7 @@ "devDependencies": { "@onflow/fcl-bundle": "^1.4.1", "@onflow/typedefs": "^1.2.1", + "@types/uuid": "^9.0.6", "eslint": "^8.35.0", "eslint-plugin-jsdoc": "^40.0.1", "jest": "^29.5.0", diff --git a/package.json b/package.json index 1e457e04c..20d3acdcd 100644 --- a/package.json +++ b/package.json @@ -16,10 +16,14 @@ "@changesets/cli": "^2.21.1", "@types/jest": "^29.5.3", "@types/node": "^18.11.18", + "@typescript-eslint/eslint-plugin": "^6.3.0", + "@typescript-eslint/parser": "^6.3.0", + "eslint": "^8.46.0", "jest": "^29.5.0", "jest-environment-jsdom": "^29.5.0", "lerna": "^6.6.2", "prettier": "^2.6.2", - "ts-jest": "^29.1.1" + "ts-jest": "^29.1.1", + "typescript": "^5.1.6" } } diff --git a/packages/sdk/TRANSITIONS.md b/packages/sdk/TRANSITIONS.md index 7d200aae0..ae9621c2e 100644 --- a/packages/sdk/TRANSITIONS.md +++ b/packages/sdk/TRANSITIONS.md @@ -1,5 +1,22 @@ # Transitions +## 0010 Deprecate interaction + +- **Date:** Sept 25th 2023 +- **Type:** Deprecation of interaction method + +The "interaction" method has been deprecated and will be removed in future versions. + +Please update your code to use the "initInteraction" method for improved functionality and compatibility. + +```javascript + // Deprecated: + const result = interaction(); + + // Recommended: + const result = initInteraction(); +``` + ## 0009 Deprecate default compute limit - **Date:** Jun 7th 2022 diff --git a/packages/sdk/package.json b/packages/sdk/package.json index c83a9734a..7f0ae7bee 100644 --- a/packages/sdk/package.json +++ b/packages/sdk/package.json @@ -20,6 +20,7 @@ "devDependencies": { "@onflow/fcl-bundle": "^1.4.1", "@onflow/typedefs": "^1.2.1", + "@types/uuid": "^9.0.6", "eslint": "^8.35.0", "eslint-plugin-jsdoc": "^40.0.1", "jest": "^29.5.0", diff --git a/packages/sdk/readme.md b/packages/sdk/readme.md index 18feeb02e..a85319f90 100644 --- a/packages/sdk/readme.md +++ b/packages/sdk/readme.md @@ -497,7 +497,7 @@ const response = await sdk.send(await sdk.build([ - [Builders](./src/build) - - [`sdk.args` & `sdk.arg`](./src/build/build-arguments.js) + - [`sdk.args` & `sdk.arg`](./src/build/build-arguments.ts) - [`sdk.atBlockHeight`](./src/build/build-at-block-height.js) - [`sdk.atBlockId`](./src/build/build-at-block-id.js) - [`sdk.authorizations` & `authorization`](./src/build/build-authorizations.js) diff --git a/packages/sdk/src/build/build-arguments.js b/packages/sdk/src/build/build-arguments.ts similarity index 69% rename from packages/sdk/src/build/build-arguments.js rename to packages/sdk/src/build/build-arguments.ts index b76e27152..7b9ba8fc5 100644 --- a/packages/sdk/src/build/build-arguments.js +++ b/packages/sdk/src/build/build-arguments.ts @@ -1,4 +1,5 @@ -import {pipe, makeArgument} from "../interaction/interaction.js" +import {pipe, makeArgument} from "../interaction/interaction" +import {TypeDescriptorInput, TypeDescriptor} from "@onflow/types" /** * @description - A utility builder to be used with other builders to pass in arguments with a value and supported type @@ -15,6 +16,9 @@ export function args(ax = []) { * @param {Function} xform - A function to transform the value * @returns {object} - An argument object */ -export function arg(value, xform) { +export function arg>(value: TypeDescriptorInput, xform: T) { return {value, xform} } diff --git a/packages/sdk/src/build/build-at-block-height.js b/packages/sdk/src/build/build-at-block-height.js index 9bc4c0f2d..1a295287e 100644 --- a/packages/sdk/src/build/build-at-block-height.js +++ b/packages/sdk/src/build/build-at-block-height.js @@ -1,4 +1,4 @@ -import {pipe} from "../interaction/interaction.js" +import {pipe} from "../interaction/interaction" import {validator} from "./build-validator.js" /** diff --git a/packages/sdk/src/build/build-at-block-height.test.js b/packages/sdk/src/build/build-at-block-height.test.js index 97d2f9fac..d30830bc1 100644 --- a/packages/sdk/src/build/build-at-block-height.test.js +++ b/packages/sdk/src/build/build-at-block-height.test.js @@ -1,11 +1,11 @@ -import {interaction} from "../interaction/interaction.js" +import {initInteraction} from "../interaction/interaction" import {atBlockHeight} from "./build-at-block-height.js" describe("Build At Block ID", () => { test("At Block ID", async () => { const blockHeight = 123 - const ix = await atBlockHeight(blockHeight)(interaction()) + const ix = await atBlockHeight(blockHeight)(initInteraction()) expect(ix.block.height).toBe(blockHeight) }) diff --git a/packages/sdk/src/build/build-at-block-id.js b/packages/sdk/src/build/build-at-block-id.js index 2553bcee9..581568d0b 100644 --- a/packages/sdk/src/build/build-at-block-id.js +++ b/packages/sdk/src/build/build-at-block-id.js @@ -1,4 +1,4 @@ -import {isGetAccount, pipe, Ok} from "../interaction/interaction.js" +import {isGetAccount, pipe, Ok} from "../interaction/interaction" import {validator} from "./build-validator.js" export function atBlockId(id) { diff --git a/packages/sdk/src/build/build-at-block-id.test.js b/packages/sdk/src/build/build-at-block-id.test.js index 2bbb99bb9..71738f04b 100644 --- a/packages/sdk/src/build/build-at-block-id.test.js +++ b/packages/sdk/src/build/build-at-block-id.test.js @@ -1,11 +1,11 @@ -import {interaction} from "../interaction/interaction.js" +import {initInteraction} from "../interaction/interaction" import {atBlockId} from "./build-at-block-id.js" describe("Build At Block ID", () => { test("At Block ID", async () => { const blockId = "abc123" - const ix = await atBlockId(blockId)(interaction()) + const ix = await atBlockId(blockId)(initInteraction()) expect(ix.block.id).toBe(blockId) }) diff --git a/packages/sdk/src/build/build-authorizations.js b/packages/sdk/src/build/build-authorizations.js index 3775c9d0b..40aeb53b0 100644 --- a/packages/sdk/src/build/build-authorizations.js +++ b/packages/sdk/src/build/build-authorizations.js @@ -1,4 +1,4 @@ -import {pipe, prepAccount, AUTHORIZER} from "../interaction/interaction.js" +import {pipe, prepAccount, AUTHORIZER} from "../interaction/interaction" export function authorizations(ax = []) { return pipe( diff --git a/packages/sdk/src/build/build-authorizations.test.js b/packages/sdk/src/build/build-authorizations.test.js index 8962f7d7f..6357f0b9b 100644 --- a/packages/sdk/src/build/build-authorizations.test.js +++ b/packages/sdk/src/build/build-authorizations.test.js @@ -1,4 +1,4 @@ -import {interaction} from "../interaction/interaction.js" +import {initInteraction} from "../interaction/interaction" import {authorizations, authorization} from "./build-authorizations.js" describe("Build Authorizations", () => { @@ -7,7 +7,7 @@ describe("Build Authorizations", () => { await authorizations([ authorization("0xabc123", () => ({signature: "123"}), 1, 123), ]) - )(interaction()) + )(initInteraction()) const authorizerAccount = ix.accounts[ix.authorizations] diff --git a/packages/sdk/src/build/build-get-account.js b/packages/sdk/src/build/build-get-account.js index 1496284f7..b25adf310 100644 --- a/packages/sdk/src/build/build-get-account.js +++ b/packages/sdk/src/build/build-get-account.js @@ -1,4 +1,4 @@ -import {pipe, makeGetAccount, Ok} from "../interaction/interaction.js" +import {pipe, makeGetAccount, Ok} from "../interaction/interaction" import {sansPrefix} from "@onflow/util-address" /** diff --git a/packages/sdk/src/build/build-get-account.test.js b/packages/sdk/src/build/build-get-account.test.js index 3e4b8e1d1..125d328df 100644 --- a/packages/sdk/src/build/build-get-account.test.js +++ b/packages/sdk/src/build/build-get-account.test.js @@ -1,4 +1,4 @@ -import {interaction} from "../interaction/interaction.js" +import {initInteraction} from "../interaction/interaction" import {sansPrefix, withPrefix} from "@onflow/util-address" import {getAccount} from "./build-get-account.js" @@ -7,14 +7,14 @@ const ADDRESS = "0xf117a8efa34ffd58" describe("address as input", () => { test("sansPrefix", async () => { const addr = sansPrefix(ADDRESS) - const result = await getAccount(addr)(interaction()) + const result = await getAccount(addr)(initInteraction()) expect(result.account.addr).toBe(sansPrefix(ADDRESS)) }) test("withPrefix", async () => { const addr = withPrefix(ADDRESS) - const result = await getAccount(addr)(interaction()) + const result = await getAccount(addr)(initInteraction()) expect(result.account.addr).toBe(sansPrefix(ADDRESS)) }) diff --git a/packages/sdk/src/build/build-get-block-header.js b/packages/sdk/src/build/build-get-block-header.js index 7dd29467f..b803793ab 100644 --- a/packages/sdk/src/build/build-get-block-header.js +++ b/packages/sdk/src/build/build-get-block-header.js @@ -1,4 +1,4 @@ -import {pipe, Ok, makeGetBlockHeader} from "../interaction/interaction.js" +import {pipe, Ok, makeGetBlockHeader} from "../interaction/interaction" /** * @description - A builder function that returns the interaction to get a block header diff --git a/packages/sdk/src/build/build-get-block-header.test.js b/packages/sdk/src/build/build-get-block-header.test.js index 583b60498..b82e09dfa 100644 --- a/packages/sdk/src/build/build-get-block-header.test.js +++ b/packages/sdk/src/build/build-get-block-header.test.js @@ -1,11 +1,11 @@ -import {interaction, isGetBlockHeader} from "../interaction/interaction.js" +import {initInteraction, isGetBlockHeader} from "../interaction/interaction" import {getBlockHeader} from "./build-get-block-header.js" describe("Build Get Block Header", () => { test("Get Block Header, isSealed = false", async () => { const isSealed = false - const ix = await getBlockHeader(isSealed)(interaction()) + const ix = await getBlockHeader(isSealed)(initInteraction()) expect(isGetBlockHeader(ix)).toBe(true) expect(ix.block.isSealed).toEqual(isSealed) @@ -14,7 +14,7 @@ describe("Build Get Block Header", () => { test("Get Block Header, isSealed = true", async () => { const isSealed = true - const ix = await getBlockHeader(isSealed)(interaction()) + const ix = await getBlockHeader(isSealed)(initInteraction()) expect(isGetBlockHeader(ix)).toBe(true) expect(ix.block.isSealed).toEqual(isSealed) diff --git a/packages/sdk/src/build/build-get-block.js b/packages/sdk/src/build/build-get-block.js index 9fb4af689..0f8604c74 100644 --- a/packages/sdk/src/build/build-get-block.js +++ b/packages/sdk/src/build/build-get-block.js @@ -1,4 +1,4 @@ -import {pipe, Ok, makeGetBlock} from "../interaction/interaction.js" +import {pipe, Ok, makeGetBlock} from "../interaction/interaction" /** * @description - A builder function that returns the interaction to get the latest block diff --git a/packages/sdk/src/build/build-get-block.test.js b/packages/sdk/src/build/build-get-block.test.js index d0d4bb3da..7d43a19f2 100644 --- a/packages/sdk/src/build/build-get-block.test.js +++ b/packages/sdk/src/build/build-get-block.test.js @@ -1,11 +1,11 @@ -import {interaction, isGetBlock} from "../interaction/interaction.js" +import {initInteraction, isGetBlock} from "../interaction/interaction" import {getBlock} from "./build-get-block.js" describe("Build Get Block", () => { test("Get Block - isSealed = false", async () => { const isSealed = false - const ix = await getBlock(isSealed)(interaction()) + const ix = await getBlock(isSealed)(initInteraction()) expect(isGetBlock(ix)).toBe(true) expect(ix.block.isSealed).toBe(false) @@ -14,7 +14,7 @@ describe("Build Get Block", () => { test("Get Block - isSealed = false", async () => { const isSealed = true - const ix = await getBlock(isSealed)(interaction()) + const ix = await getBlock(isSealed)(initInteraction()) expect(isGetBlock(ix)).toBe(true) expect(ix.block.isSealed).toBe(true) diff --git a/packages/sdk/src/build/build-get-collection.js b/packages/sdk/src/build/build-get-collection.js index 6ab976e97..96f0ca585 100644 --- a/packages/sdk/src/build/build-get-collection.js +++ b/packages/sdk/src/build/build-get-collection.js @@ -1,4 +1,4 @@ -import {pipe, makeGetCollection} from "../interaction/interaction.js" +import {pipe, makeGetCollection} from "../interaction/interaction" /** * @description - A builder function that returns all a collection containing a list of transaction ids by its collection id diff --git a/packages/sdk/src/build/build-get-collection.test.js b/packages/sdk/src/build/build-get-collection.test.js index 143c3a42b..8f227c893 100644 --- a/packages/sdk/src/build/build-get-collection.test.js +++ b/packages/sdk/src/build/build-get-collection.test.js @@ -1,11 +1,11 @@ -import {interaction, isGetCollection} from "../interaction/interaction.js" +import {initInteraction, isGetCollection} from "../interaction/interaction" import {getCollection} from "./build-get-collection.js" describe("Build Get Collection", () => { test("Get Collection", async () => { const collectionId = "my-collection-id" - const ix = await getCollection(collectionId)(interaction()) + const ix = await getCollection(collectionId)(initInteraction()) expect(isGetCollection(ix)).toBe(true) expect(ix.collection.id).toBe(collectionId) diff --git a/packages/sdk/src/build/build-get-events-at-block-height-range.js b/packages/sdk/src/build/build-get-events-at-block-height-range.js index d88e0b3e4..58c19bd93 100644 --- a/packages/sdk/src/build/build-get-events-at-block-height-range.js +++ b/packages/sdk/src/build/build-get-events-at-block-height-range.js @@ -1,4 +1,4 @@ -import {pipe, Ok, makeGetEvents} from "../interaction/interaction.js" +import {pipe, Ok, makeGetEvents} from "../interaction/interaction" /** * @description - A builder function that returns all instances of a particular event (by name) within a height range diff --git a/packages/sdk/src/build/build-get-events-at-block-height-range.test.js b/packages/sdk/src/build/build-get-events-at-block-height-range.test.js index 9889ca07a..06a9e0d08 100644 --- a/packages/sdk/src/build/build-get-events-at-block-height-range.test.js +++ b/packages/sdk/src/build/build-get-events-at-block-height-range.test.js @@ -1,4 +1,4 @@ -import {interaction, isGetEvents} from "../interaction/interaction.js" +import {initInteraction, isGetEvents} from "../interaction/interaction" import {getEventsAtBlockHeightRange} from "./build-get-events-at-block-height-range.js" describe("Build Get Events At Block Height Range", () => { @@ -11,7 +11,7 @@ describe("Build Get Events At Block Height Range", () => { eventName, start, end - )(interaction()) + )(initInteraction()) expect(isGetEvents(ix)).toBe(true) expect(ix.events.eventType).toBe(eventName) diff --git a/packages/sdk/src/build/build-get-events-at-block-ids.js b/packages/sdk/src/build/build-get-events-at-block-ids.js index 0865a1941..6fe534032 100644 --- a/packages/sdk/src/build/build-get-events-at-block-ids.js +++ b/packages/sdk/src/build/build-get-events-at-block-ids.js @@ -1,4 +1,4 @@ -import {pipe, Ok, makeGetEvents} from "../interaction/interaction.js" +import {pipe, Ok, makeGetEvents} from "../interaction/interaction" /** * @description - A builder function that returns all instances of a particular event (by name) within a set of blocks, specified by block ids diff --git a/packages/sdk/src/build/build-get-events-at-block-ids.test.js b/packages/sdk/src/build/build-get-events-at-block-ids.test.js index d4ac3cf2f..84f07a281 100644 --- a/packages/sdk/src/build/build-get-events-at-block-ids.test.js +++ b/packages/sdk/src/build/build-get-events-at-block-ids.test.js @@ -1,4 +1,4 @@ -import {interaction, isGetEvents} from "../interaction/interaction.js" +import {initInteraction, isGetEvents} from "../interaction/interaction" import {getEventsAtBlockIds} from "./build-get-events-at-block-ids.js" describe("Build Get Events At Block Ids", () => { @@ -6,7 +6,7 @@ describe("Build Get Events At Block Ids", () => { const eventName = "MyEvent" const blockIds = ["abc", "123"] - let ix = await getEventsAtBlockIds(eventName, blockIds)(interaction()) + let ix = await getEventsAtBlockIds(eventName, blockIds)(initInteraction()) expect(isGetEvents(ix)).toBe(true) expect(ix.events.eventType).toBe(eventName) diff --git a/packages/sdk/src/build/build-get-events.js b/packages/sdk/src/build/build-get-events.js index 9783860d8..f338524e3 100644 --- a/packages/sdk/src/build/build-get-events.js +++ b/packages/sdk/src/build/build-get-events.js @@ -1,4 +1,4 @@ -import {pipe, Ok, makeGetEvents} from "../interaction/interaction.js" +import {pipe, Ok, makeGetEvents} from "../interaction/interaction" import * as logger from "@onflow/util-logger" export function getEvents(eventType, start, end) { diff --git a/packages/sdk/src/build/build-get-latest-block.js b/packages/sdk/src/build/build-get-latest-block.js index 0e823a212..005a73557 100644 --- a/packages/sdk/src/build/build-get-latest-block.js +++ b/packages/sdk/src/build/build-get-latest-block.js @@ -1,5 +1,5 @@ import {log} from "@onflow/util-logger" -import {pipe, Ok, makeGetLatestBlock} from "../interaction/interaction.js" +import {pipe, Ok, makeGetLatestBlock} from "../interaction/interaction" export function getLatestBlock(isSealed = false) { log.deprecate({ diff --git a/packages/sdk/src/build/build-get-network-parameters.js b/packages/sdk/src/build/build-get-network-parameters.js index 6ea5b29f0..760ba7a91 100644 --- a/packages/sdk/src/build/build-get-network-parameters.js +++ b/packages/sdk/src/build/build-get-network-parameters.js @@ -1,4 +1,4 @@ -import {pipe, Ok, makeGetNetworkParameters} from "../interaction/interaction.js" +import {pipe, Ok, makeGetNetworkParameters} from "../interaction/interaction" export function getNetworkParameters() { return pipe([ diff --git a/packages/sdk/src/build/build-get-network-parameters.test.js b/packages/sdk/src/build/build-get-network-parameters.test.js index f8f72de77..ef46a6ce8 100644 --- a/packages/sdk/src/build/build-get-network-parameters.test.js +++ b/packages/sdk/src/build/build-get-network-parameters.test.js @@ -1,12 +1,12 @@ import { - interaction, + initInteraction, isGetNetworkParameters, -} from "../interaction/interaction.js" +} from "../interaction/interaction" import {getNetworkParameters} from "./build-get-network-parameters.js" describe("Build Get Network Parameters", () => { test("Get Network Parameters", async () => { - let ix = await getNetworkParameters()(interaction()) + let ix = await getNetworkParameters()(initInteraction()) expect(isGetNetworkParameters(ix)).toBe(true) }) diff --git a/packages/sdk/src/build/build-get-transaction-status.js b/packages/sdk/src/build/build-get-transaction-status.js index 1dec09cfa..adb4b6806 100644 --- a/packages/sdk/src/build/build-get-transaction-status.js +++ b/packages/sdk/src/build/build-get-transaction-status.js @@ -1,4 +1,4 @@ -import {pipe, Ok, makeGetTransactionStatus} from "../interaction/interaction.js" +import {pipe, Ok, makeGetTransactionStatus} from "../interaction/interaction" /** * @description - A builder function that returns the status of transaction diff --git a/packages/sdk/src/build/build-get-transaction-status.test.js b/packages/sdk/src/build/build-get-transaction-status.test.js index 4de877cc6..75496b8fe 100644 --- a/packages/sdk/src/build/build-get-transaction-status.test.js +++ b/packages/sdk/src/build/build-get-transaction-status.test.js @@ -1,14 +1,14 @@ import { - interaction, + initInteraction, isGetTransactionStatus, -} from "../interaction/interaction.js" +} from "../interaction/interaction" import {getTransactionStatus} from "./build-get-transaction-status.js" describe("Build Get Transaction Status", () => { test("Get Transaction Status", async () => { const transactionId = "abc123" - let ix = await getTransactionStatus(transactionId)(interaction()) + let ix = await getTransactionStatus(transactionId)(initInteraction()) expect(isGetTransactionStatus(ix)).toBe(true) expect(ix.transaction.id).toBe(transactionId) diff --git a/packages/sdk/src/build/build-get-transaction.js b/packages/sdk/src/build/build-get-transaction.js index 899490bff..4f559843d 100644 --- a/packages/sdk/src/build/build-get-transaction.js +++ b/packages/sdk/src/build/build-get-transaction.js @@ -1,4 +1,4 @@ -import {pipe, Ok, makeGetTransaction} from "../interaction/interaction.js" +import {pipe, Ok, makeGetTransaction} from "../interaction/interaction" /** * @description - A builder function that returns a transaction diff --git a/packages/sdk/src/build/build-get-transaction.test.js b/packages/sdk/src/build/build-get-transaction.test.js index f094028fb..da9a22e4d 100644 --- a/packages/sdk/src/build/build-get-transaction.test.js +++ b/packages/sdk/src/build/build-get-transaction.test.js @@ -1,11 +1,11 @@ -import {interaction, isGetTransaction} from "../interaction/interaction.js" +import {initInteraction, isGetTransaction} from "../interaction/interaction" import {getTransaction} from "./build-get-transaction.js" describe("Build Get Transaction", () => { test("Get Transaction", async () => { const transactionId = "abc123" - let ix = await getTransaction(transactionId)(interaction()) + let ix = await getTransaction(transactionId)(initInteraction()) expect(isGetTransaction(ix)).toBe(true) expect(ix.transaction.id).toBe(transactionId) diff --git a/packages/sdk/src/build/build-invariant.js b/packages/sdk/src/build/build-invariant.js index fddb25e45..b6a431467 100644 --- a/packages/sdk/src/build/build-invariant.js +++ b/packages/sdk/src/build/build-invariant.js @@ -1,4 +1,4 @@ -import {Ok, Bad} from "../interaction/interaction.js" +import {Ok, Bad} from "../interaction/interaction" export function invariant(...args) { if (args.length > 1) { diff --git a/packages/sdk/src/build/build-limit.test.js b/packages/sdk/src/build/build-limit.test.js index 43702b10e..31d603760 100644 --- a/packages/sdk/src/build/build-limit.test.js +++ b/packages/sdk/src/build/build-limit.test.js @@ -1,11 +1,11 @@ -import {interaction} from "../interaction/interaction.js" +import {initInteraction} from "../interaction/interaction" import {limit} from "./build-limit.js" describe("Build Limit", () => { test("Build Limit", async () => { const txLimit = 100 - let ix = await limit(txLimit)(interaction()) + let ix = await limit(txLimit)(initInteraction()) expect(ix.message.computeLimit).toEqual(txLimit) }) diff --git a/packages/sdk/src/build/build-payer.js b/packages/sdk/src/build/build-payer.js index 7e27fa817..e791af322 100644 --- a/packages/sdk/src/build/build-payer.js +++ b/packages/sdk/src/build/build-payer.js @@ -1,4 +1,4 @@ -import {pipe, prepAccount, PAYER} from "../interaction/interaction.js" +import {pipe, prepAccount, PAYER} from "../interaction/interaction" export function payer(ax = []) { if (!Array.isArray(ax)) ax = [ax] diff --git a/packages/sdk/src/build/build-payer.test.js b/packages/sdk/src/build/build-payer.test.js index 4fff58f81..a60295323 100644 --- a/packages/sdk/src/build/build-payer.test.js +++ b/packages/sdk/src/build/build-payer.test.js @@ -1,11 +1,11 @@ -import {interaction} from "../interaction/interaction.js" +import {initInteraction} from "../interaction/interaction" import {payer} from "./build-payer.js" describe("Build Payer", () => { test("Build Payer", async () => { const authz = {addr: "0xabc123"} - let ix = await (await payer(authz))(interaction()) + let ix = await (await payer(authz))(initInteraction()) const payerAccount = ix.accounts[ix.payer] diff --git a/packages/sdk/src/build/build-ping.js b/packages/sdk/src/build/build-ping.js index 6cf368de0..0379ff2cc 100644 --- a/packages/sdk/src/build/build-ping.js +++ b/packages/sdk/src/build/build-ping.js @@ -1,4 +1,4 @@ -import {makePing} from "../interaction/interaction.js" +import {makePing} from "../interaction/interaction" export function ping() { return makePing diff --git a/packages/sdk/src/build/build-ping.test.js b/packages/sdk/src/build/build-ping.test.js index 6404d5b70..97179a32a 100644 --- a/packages/sdk/src/build/build-ping.test.js +++ b/packages/sdk/src/build/build-ping.test.js @@ -1,9 +1,9 @@ -import {interaction, isPing} from "../interaction/interaction.js" +import {initInteraction, isPing} from "../interaction/interaction" import {ping} from "./build-ping.js" describe("Build Ping", () => { test("Build Ping", async () => { - let ix = await ping()(interaction()) + let ix = await ping()(initInteraction()) expect(isPing(ix)).toBe(true) }) diff --git a/packages/sdk/src/build/build-proposer.js b/packages/sdk/src/build/build-proposer.js index 1753f8089..aabbb9180 100644 --- a/packages/sdk/src/build/build-proposer.js +++ b/packages/sdk/src/build/build-proposer.js @@ -1,4 +1,4 @@ -import {prepAccount, PROPOSER} from "../interaction/interaction.js" +import {prepAccount, PROPOSER} from "../interaction/interaction" export async function proposer(authz) { return prepAccount(authz, {role: PROPOSER}) diff --git a/packages/sdk/src/build/build-proposer.test.js b/packages/sdk/src/build/build-proposer.test.js index 47370fcdf..7d1972f3b 100644 --- a/packages/sdk/src/build/build-proposer.test.js +++ b/packages/sdk/src/build/build-proposer.test.js @@ -1,11 +1,11 @@ -import {interaction} from "../interaction/interaction.js" +import {initInteraction} from "../interaction/interaction" import {proposer} from "./build-proposer.js" describe("Build Proposer", () => { test("Build Proposer", async () => { const authz = {addr: "0xabc123"} - let ix = await (await proposer(authz))(interaction()) + let ix = await (await proposer(authz))(initInteraction()) const proposerAccount = ix.accounts[ix.proposer] diff --git a/packages/sdk/src/build/build-ref.js b/packages/sdk/src/build/build-ref.js index 7d60242c3..bc1648715 100644 --- a/packages/sdk/src/build/build-ref.js +++ b/packages/sdk/src/build/build-ref.js @@ -1,4 +1,4 @@ -import {pipe, Ok} from "../interaction/interaction.js" +import {pipe, Ok} from "../interaction/interaction" export function ref(refBlock) { return pipe([ diff --git a/packages/sdk/src/build/build-ref.test.js b/packages/sdk/src/build/build-ref.test.js index 516b35893..2a6919636 100644 --- a/packages/sdk/src/build/build-ref.test.js +++ b/packages/sdk/src/build/build-ref.test.js @@ -1,11 +1,11 @@ -import {interaction} from "../interaction/interaction.js" +import {initInteraction} from "../interaction/interaction" import {ref} from "./build-ref.js" describe("Build Ref", () => { test("Build Ref", async () => { const refBlockId = "abc123" - let ix = await ref(refBlockId)(interaction()) + let ix = await ref(refBlockId)(initInteraction()) expect(ix.message.refBlock).toEqual(refBlockId) }) diff --git a/packages/sdk/src/build/build-script.js b/packages/sdk/src/build/build-script.js index 45c3ca954..9dbd8072f 100644 --- a/packages/sdk/src/build/build-script.js +++ b/packages/sdk/src/build/build-script.js @@ -1,4 +1,4 @@ -import {pipe, Ok, put, makeScript} from "../interaction/interaction.js" +import {pipe, Ok, put, makeScript} from "../interaction/interaction" import {template} from "@onflow/util-template" export function script(...args) { diff --git a/packages/sdk/src/build/build-script.test.js b/packages/sdk/src/build/build-script.test.js index 7a390198c..576e16229 100644 --- a/packages/sdk/src/build/build-script.test.js +++ b/packages/sdk/src/build/build-script.test.js @@ -1,11 +1,11 @@ -import {interaction, isScript} from "../interaction/interaction.js" +import {initInteraction, isScript} from "../interaction/interaction" import {script} from "./build-script.js" describe("Build Script", () => { test("Build Script", async () => { const cadence = "pub fun main(): Int { return 123 }" - let ix = await script(cadence)(interaction()) + let ix = await script(cadence)(initInteraction()) expect(isScript(ix)).toBe(true) expect(ix.assigns["ix.cadence"]).not.toBeUndefined() diff --git a/packages/sdk/src/build/build-transaction.js b/packages/sdk/src/build/build-transaction.js index d4570d4eb..27b003d02 100644 --- a/packages/sdk/src/build/build-transaction.js +++ b/packages/sdk/src/build/build-transaction.js @@ -1,4 +1,4 @@ -import {pipe, put, Ok, makeTransaction} from "../interaction/interaction.js" +import {pipe, put, Ok, makeTransaction} from "../interaction/interaction" import {template} from "@onflow/util-template" const DEFAULT_SCRIPT_ACCOUNTS = [] diff --git a/packages/sdk/src/build/build-transaction.test.js b/packages/sdk/src/build/build-transaction.test.js index de961571e..e64ae28c5 100644 --- a/packages/sdk/src/build/build-transaction.test.js +++ b/packages/sdk/src/build/build-transaction.test.js @@ -1,11 +1,11 @@ -import {interaction, isTransaction} from "../interaction/interaction.js" +import {initInteraction, isTransaction} from "../interaction/interaction" import {transaction} from "./build-transaction.js" describe("Build Transaction", () => { test("Build Transaction", async () => { const cadence = "transaction { increaseMyBallerStatus() }" - let ix = await transaction(cadence)(interaction()) + let ix = await transaction(cadence)(initInteraction()) expect(isTransaction(ix)).toBe(true) expect(ix.assigns["ix.cadence"]).not.toBeUndefined() diff --git a/packages/sdk/src/build/build-validator.js b/packages/sdk/src/build/build-validator.js index 708a9602e..c55a4e7f2 100644 --- a/packages/sdk/src/build/build-validator.js +++ b/packages/sdk/src/build/build-validator.js @@ -1,4 +1,4 @@ -import {update} from "../interaction/interaction.js" +import {update} from "../interaction/interaction" export function validator(cb) { return update("ix.validators", validators => diff --git a/packages/sdk/src/build/build-voucher-intercept.js b/packages/sdk/src/build/build-voucher-intercept.js index ad99ba1a0..ae9392945 100644 --- a/packages/sdk/src/build/build-voucher-intercept.js +++ b/packages/sdk/src/build/build-voucher-intercept.js @@ -1,4 +1,4 @@ -import {put} from "../interaction/interaction.js" +import {put} from "../interaction/interaction" export function voucherIntercept(fn) { return put("ix.voucher-intercept", fn) diff --git a/packages/sdk/src/build/build-voucher-intercept.test.js b/packages/sdk/src/build/build-voucher-intercept.test.js index 6e6c6cf32..91a9129ff 100644 --- a/packages/sdk/src/build/build-voucher-intercept.test.js +++ b/packages/sdk/src/build/build-voucher-intercept.test.js @@ -1,11 +1,11 @@ -import {interaction} from "../interaction/interaction.js" +import {initInteraction} from "../interaction/interaction" import {voucherIntercept} from "./build-voucher-intercept" describe("Build voucherIntercept", () => { test("Build voucherIntercept", async () => { const checkFunc = async () => "test func" - const ix = await voucherIntercept(checkFunc)(interaction()) + const ix = await voucherIntercept(checkFunc)(initInteraction()) expect(ix.assigns["ix.voucher-intercept"]).toEqual(checkFunc) }) diff --git a/packages/sdk/src/build/build.js b/packages/sdk/src/build/build.js index e0e63050a..c7c3b2725 100644 --- a/packages/sdk/src/build/build.js +++ b/packages/sdk/src/build/build.js @@ -1,5 +1,5 @@ -import {pipe, interaction} from "../interaction/interaction.js" +import {pipe, initInteraction} from "../interaction/interaction" export function build(fns = []) { - return pipe(interaction(), fns) + return pipe(initInteraction(), fns) } diff --git a/packages/sdk/src/contract.test.js b/packages/sdk/src/contract.test.js index 866d0c02f..4a9001db4 100644 --- a/packages/sdk/src/contract.test.js +++ b/packages/sdk/src/contract.test.js @@ -1,7 +1,7 @@ import * as root from "./sdk" import * as decode from "./decode/decode.js" import * as encode from "./encode/encode.js" -import * as interaction from "./interaction/interaction.js" +import * as interaction from "./interaction/interaction" import * as send from "./send/send.js" import * as template from "@onflow/util-template" @@ -43,7 +43,7 @@ describe("consume", () => { ` interfaceContract("@onflow/interaction", interaction)` - interaction + initInteraction pipe Ok isOk isBad why put get update makeGetAccount makeGetEvents diff --git a/packages/sdk/src/interaction/interaction.test.js b/packages/sdk/src/interaction/interaction.test.ts similarity index 73% rename from packages/sdk/src/interaction/interaction.test.js rename to packages/sdk/src/interaction/interaction.test.ts index 7449555da..595a3ca50 100644 --- a/packages/sdk/src/interaction/interaction.test.js +++ b/packages/sdk/src/interaction/interaction.test.ts @@ -1,10 +1,11 @@ import {resolveAccounts} from "../sdk" -import {prepAccount} from "./interaction" +import {InteractionAccount, prepAccount, initAccount, initInteraction} from "./interaction" describe("prepAccount", () => { test("prepAccount converts account object keyId to integer", async () => { const keyId = "1" - const acct = { + const acct: InteractionAccount = { + ...initAccount(), addr: "f8d6e0586b0a20c7", keyId, signingFunction: () => ({ @@ -13,13 +14,13 @@ describe("prepAccount", () => { }), } - const ix = prepAccount(acct, {role: "proposer"})({accounts: {}}) - expect(ix.accounts[ix.proposer].keyId).toBe(parseInt(keyId)) + const ix = prepAccount(acct, {role: "proposer"})({...initInteraction(), accounts: {}}) + expect(ix.accounts[ix.proposer||""].keyId).toBe(parseInt(keyId)) }) test("prepAccount converts authorization function keyId to integer", async () => { const keyId = "1" - const authz = acct => { + const authz = (acct: InteractionAccount): InteractionAccount => { return { ...acct, addr: "f8d6e0586b0a20c7", @@ -33,6 +34,7 @@ describe("prepAccount", () => { const ix = await resolveAccounts( prepAccount(authz, {role: "proposer"})({ + ...initInteraction(), accounts: {}, }) ) @@ -41,7 +43,7 @@ describe("prepAccount", () => { }) test("prepAccount does not affect keyId if undefined/does not exist", async () => { - const authz = acct => { + const authz = (acct: InteractionAccount): InteractionAccount => { return { ...acct, addr: "f8d6e0586b0a20c7", @@ -54,6 +56,7 @@ describe("prepAccount", () => { const ix = await resolveAccounts( prepAccount(authz, {role: "proposer"})({ + ...initInteraction(), accounts: {}, }) ) diff --git a/packages/sdk/src/interaction/interaction.js b/packages/sdk/src/interaction/interaction.ts similarity index 59% rename from packages/sdk/src/interaction/interaction.js rename to packages/sdk/src/interaction/interaction.ts index 703ba18f6..24c2c6ee4 100644 --- a/packages/sdk/src/interaction/interaction.js +++ b/packages/sdk/src/interaction/interaction.ts @@ -1,29 +1,11 @@ import {invariant} from "@onflow/util-invariant" import {v4 as uuidv4} from "uuid" +import {log, LEVELS} from "@onflow/util-logger" -export const UNKNOWN /* */ = "UNKNOWN" -export const SCRIPT /* */ = "SCRIPT" -export const TRANSACTION /* */ = "TRANSACTION" -export const GET_TRANSACTION_STATUS /* */ = "GET_TRANSACTION_STATUS" -export const GET_ACCOUNT /* */ = "GET_ACCOUNT" -export const GET_EVENTS /* */ = "GET_EVENTS" -export const PING /* */ = "PING" -export const GET_TRANSACTION /* */ = "GET_TRANSACTION" -export const GET_BLOCK /* */ = "GET_BLOCK" -export const GET_BLOCK_HEADER /* */ = "GET_BLOCK_HEADER" -export const GET_COLLECTION /* */ = "GET_COLLECTION" -export const GET_NETWORK_PARAMETERS /* */ = "GET_NETWORK_PARAMETERS" - -export const BAD /* */ = "BAD" -export const OK /* */ = "OK" - -export const ACCOUNT /* */ = "ACCOUNT" -export const PARAM /* */ = "PARAM" -export const ARGUMENT /* */ = "ARGUMENT" - -export const AUTHORIZER /* */ = "authorizer" -export const PAYER /* */ = "payer" -export const PROPOSER /* */ = "proposer" +import { InteractionAccount, ACCOUNT, PARAM, ARGUMENT, UNKNOWN, OK, Interaction, AUTHORIZER, PAYER, SCRIPT, TRANSACTION, GET_TRANSACTION_STATUS, GET_TRANSACTION, GET_ACCOUNT, GET_EVENTS, PING, GET_BLOCK, GET_BLOCK_HEADER, GET_COLLECTION, GET_NETWORK_PARAMETERS, BAD, PROPOSER } from "@onflow/typedefs"; + +type AcctFn = (acct: InteractionAccount) => InteractionAccount; +type AccountFn = AcctFn & Partial; const ACCT = `{ "kind":"${ACCOUNT}", @@ -105,80 +87,103 @@ const IX = `{ } }` -const KEYS = new Set(Object.keys(JSON.parse(IX))) - -export const interaction = () => JSON.parse(IX) +const KEYS = new Set(Object.keys(JSON.parse(IX) as Interaction)) + + +export const initInteraction = (): Interaction => JSON.parse(IX) +/** + * @deprecated + */ +export const interaction = () => { + log.deprecate({ + pkg: "FCL/SDK", + message: `The interaction been deprecated from the Flow JS-SDK/FCL. use initInteraction instead`, + transition: + "https://github.com/onflow/flow-js-sdk/blob/master/packages/sdk/TRANSITIONS.md#0010-deprecate-interaction", + level: LEVELS.warn, + }) + return initInteraction() +} -export const isNumber = d => typeof d === "number" -export const isArray = d => Array.isArray(d) -export const isObj = d => d !== null && typeof d === "object" -export const isNull = d => d == null -export const isFn = d => typeof d === "function" +export const isNumber = (d: any): d is number => typeof d === "number" +export const isArray = (d: any): d is any[] => Array.isArray(d) +export const isObj = (d: any): d is Record => d !== null && typeof d === "object" +export const isNull = (d: any): d is null => d == null +export const isFn = (d: any): d is Function => typeof d === "function" -export const isInteraction = ix => { +export const isInteraction = (ix: Interaction) => { if (!isObj(ix) || isNull(ix) || isNumber(ix)) return false for (let key of KEYS) if (!ix.hasOwnProperty(key)) return false return true } -export const Ok = ix => { +export const Ok = (ix: Interaction) => { ix.status = OK return ix } -export const Bad = (ix, reason) => { +export const Bad = (ix: Interaction, reason: string) => { ix.status = BAD ix.reason = reason return ix } -const makeIx = wat => ix => { +const makeIx = (wat: string) => (ix: Interaction) => { ix.tag = wat return Ok(ix) } -const prepAccountKeyId = acct => { +const prepAccountKeyId = (acct: Partial | AccountFn): Partial | AccountFn => { if (acct.keyId == null) return acct - invariant(!isNaN(parseInt(acct.keyId)), "account.keyId must be an integer") + invariant(!isNaN(parseInt(acct.keyId.toString())), "account.keyId must be an integer") + return { ...acct, - keyId: parseInt(acct.keyId), - } + keyId: parseInt(acct.keyId.toString()), + } as InteractionAccount | AccountFn } -export const prepAccount = (acct, opts = {}) => ix => { +interface IPrepAccountOpts { + role?: typeof AUTHORIZER | typeof PAYER | typeof PROPOSER | null +} + +export const initAccount = (): InteractionAccount => JSON.parse(ACCT) + +export const prepAccount = (acct: InteractionAccount | AccountFn, opts: IPrepAccountOpts = {}) => (ix: Interaction) => { invariant( typeof acct === "function" || typeof acct === "object", "prepAccount must be passed an authorization function or an account object" ) invariant(opts.role != null, "Account must have a role") - const ACCOUNT = JSON.parse(ACCT) + const ACCOUNT = initAccount() const role = opts.role const tempId = uuidv4() + let account: Partial = {...acct} if (acct.authorization && isFn(acct.authorization)) - acct = {resolve: acct.authorization} - if (!acct.authorization && isFn(acct)) acct = {resolve: acct} + account = {resolve: acct.authorization} + if (!acct.authorization && isFn(acct)) account = {resolve: acct} - const resolve = acct.resolve - if (resolve) - acct.resolve = (acct, ...rest) => + const resolve = account.resolve + if (resolve) { + account.resolve = (acct: InteractionAccount, ...rest: any[]) => [resolve, prepAccountKeyId].reduce( async (d, fn) => fn(await d, ...rest), acct ) - acct = prepAccountKeyId(acct) + } + account = prepAccountKeyId(account) ix.accounts[tempId] = { ...ACCOUNT, tempId, - ...acct, + ...account, role: { ...ACCOUNT.role, ...(typeof acct.role === "object" ? acct.role : {}), - [role]: true, + ...(role ? {[role]: true} : {}), }, } @@ -186,14 +191,14 @@ export const prepAccount = (acct, opts = {}) => ix => { ix.authorizations.push(tempId) } else if (role === PAYER) { ix.payer.push(tempId) - } else { + } else if (role) { ix[role] = tempId } return ix } -export const makeArgument = arg => ix => { +export const makeArgument = (arg: Record) => (ix: Interaction) => { let tempId = uuidv4() ix.message.arguments.push(tempId) @@ -223,7 +228,7 @@ export const makeGetBlockHeader /* */ = makeIx(GET_BLOCK_HEADER) export const makeGetCollection /* */ = makeIx(GET_COLLECTION) export const makeGetNetworkParameters /* */ = makeIx(GET_NETWORK_PARAMETERS) -const is = wat => ix => ix.tag === wat +const is = (wat: string) => (ix: Interaction) => ix.tag === wat export const isUnknown /* */ = is(UNKNOWN) export const isScript /* */ = is(SCRIPT) @@ -238,15 +243,15 @@ export const isGetBlockHeader /* */ = is(GET_BLOCK_HEADER) export const isGetCollection /* */ = is(GET_COLLECTION) export const isGetNetworkParameters /* */ = is(GET_NETWORK_PARAMETERS) -export const isOk /* */ = ix => ix.status === OK -export const isBad /* */ = ix => ix.status === BAD -export const why /* */ = ix => ix.reason +export const isOk /* */ = (ix: Interaction) => ix.status === OK +export const isBad /* */ = (ix: Interaction) => ix.status === BAD +export const why /* */ = (ix: Interaction) => ix.reason -export const isAccount /* */ = account => account.kind === ACCOUNT -export const isParam /* */ = param => param.kind === PARAM -export const isArgument /* */ = argument => argument.kind === ARGUMENT +export const isAccount /* */ = (account: Record) => account.kind === ACCOUNT +export const isParam /* */ = (param: Record) => param.kind === PARAM +export const isArgument /* */ = (argument: Record) => argument.kind === ARGUMENT -const hardMode = ix => { +const hardMode = (ix: Interaction) => { for (let key of Object.keys(ix)) { if (!KEYS.has(key)) throw new Error(`"${key}" is an invalid root level Interaction property.`) @@ -254,7 +259,7 @@ const hardMode = ix => { return ix } -const recPipe = async (ix, fns = []) => { +const recPipe = async (ix: Interaction, fns: (Function | Interaction)[] = []): Promise => { try { ix = hardMode(await ix) if (isBad(ix)) throw new Error(`Interaction Error: ${ix.reason}`) @@ -270,29 +275,31 @@ const recPipe = async (ix, fns = []) => { } } -export const pipe = (...args) => { +export const pipe = (...args: any[]) => { const [arg1, arg2] = args - if (isArray(arg1) && arg2 == null) return d => pipe(d, arg1) + if (isArray(arg1) && arg2 == null) return (d: any) => pipe(d, arg1) return recPipe(arg1, arg2) } -const identity = v => v +const identity = (v: T, ..._: any[]) => v -export const get = (ix, key, fallback) => { +export const get = (ix: Interaction, key: string, fallback: any) => { return ix.assigns[key] == null ? fallback : ix.assigns[key] } -export const put = (key, value) => ix => { +export const put = (key: string, value: any) => (ix: Interaction) => { ix.assigns[key] = value return Ok(ix) } -export const update = (key, fn = identity) => ix => { +export const update = (key: string, fn = identity) => (ix: Interaction) => { ix.assigns[key] = fn(ix.assigns[key], ix) return Ok(ix) } -export const destroy = key => ix => { +export const destroy = (key: string) => (ix: Interaction) => { delete ix.assigns[key] return Ok(ix) } + +export * from "@onflow/typedefs" diff --git a/packages/sdk/src/resolve/resolve-accounts.js b/packages/sdk/src/resolve/resolve-accounts.js index 8376d8e55..15deaa7ec 100644 --- a/packages/sdk/src/resolve/resolve-accounts.js +++ b/packages/sdk/src/resolve/resolve-accounts.js @@ -1,7 +1,7 @@ import {sansPrefix, withPrefix} from "@onflow/util-address" import {invariant} from "@onflow/util-invariant" import {log} from "@onflow/util-logger" -import {isTransaction} from "../interaction/interaction.js" +import {isTransaction} from "../interaction/interaction" import {createSignableVoucher} from "./voucher.js" import {v4 as uuidv4} from "uuid" diff --git a/packages/sdk/src/resolve/resolve-arguments.js b/packages/sdk/src/resolve/resolve-arguments.js index 04db4a7d1..eb1ad392c 100644 --- a/packages/sdk/src/resolve/resolve-arguments.js +++ b/packages/sdk/src/resolve/resolve-arguments.js @@ -1,5 +1,5 @@ import {invariant} from "@onflow/util-invariant" -import {isTransaction, isScript} from "../interaction/interaction.js" +import {isTransaction, isScript} from "../interaction/interaction" const isFn = v => typeof v === "function" diff --git a/packages/sdk/src/resolve/resolve-cadence.js b/packages/sdk/src/resolve/resolve-cadence.js index 2e73baeaa..3da21cbb4 100644 --- a/packages/sdk/src/resolve/resolve-cadence.js +++ b/packages/sdk/src/resolve/resolve-cadence.js @@ -1,4 +1,4 @@ -import {isTransaction, isScript, get} from "../interaction/interaction.js" +import {isTransaction, isScript, get} from "../interaction/interaction" import {invariant} from "@onflow/util-invariant" import {config} from "@onflow/config" import * as logger from "@onflow/util-logger" diff --git a/packages/sdk/src/resolve/resolve-cadence.test.js b/packages/sdk/src/resolve/resolve-cadence.test.js index a2dc77aa9..086449d61 100644 --- a/packages/sdk/src/resolve/resolve-cadence.test.js +++ b/packages/sdk/src/resolve/resolve-cadence.test.js @@ -1,4 +1,4 @@ -import {interaction, pipe, put, makeScript} from "../interaction/interaction.js" +import {initInteraction, pipe, put, makeScript} from "../interaction/interaction" import {resolveCadence} from "./resolve-cadence.js" import {config} from "@onflow/config" @@ -13,7 +13,7 @@ describe("resolveCadence", () => { makeScript, put("ix.cadence", CADENCE), resolveCadence, - ])(interaction()) + ])(initInteraction()) expect(ix.message.cadence).toBe(CADENCE) }) @@ -27,7 +27,7 @@ describe("resolveCadence", () => { makeScript, put("ix.cadence", CADENCE), resolveCadence, - ])(interaction()) + ])(initInteraction()) expect(ix.message.cadence).toBe(await CADENCE()) }) @@ -59,7 +59,7 @@ describe("resolveCadence", () => { makeScript, put("ix.cadence", CADENCE), resolveCadence, - ])(interaction()) + ])(initInteraction()) expect(ix.message.cadence).toEqual(await RESULT()) }) @@ -111,7 +111,7 @@ describe("resolveCadence", () => { makeScript, put("ix.cadence", CADENCE), resolveCadence, - ])(interaction()) + ])(initInteraction()) expect(ix.message.cadence).toEqual(await RESULT()) }) @@ -138,7 +138,7 @@ pub fun main(): Address { makeScript, put("ix.cadence", CADENCE), resolveCadence, - ])(interaction()) + ])(initInteraction()) expect(ix.message.cadence).toEqual(expected) }) @@ -165,7 +165,7 @@ pub fun main(): Address { makeScript, put("ix.cadence", CADENCE), resolveCadence, - ])(interaction()) + ])(initInteraction()) expect(ix.message.cadence).toEqual(expected) }) @@ -193,7 +193,7 @@ pub fun main(): Address { makeScript, put("ix.cadence", CADENCE), resolveCadence, - ])(interaction()) + ])(initInteraction()) expect(ix.message.cadence).toEqual(expected) }) @@ -218,7 +218,7 @@ pub fun main(): Address { makeScript, put("ix.cadence", CADENCE), resolveCadence, - ])(interaction()) + ])(initInteraction()) expect(ix.message.cadence).toEqual(expected) }) diff --git a/packages/sdk/src/resolve/resolve-compute-limit.js b/packages/sdk/src/resolve/resolve-compute-limit.js index 1bd5479b6..a93cd58cf 100644 --- a/packages/sdk/src/resolve/resolve-compute-limit.js +++ b/packages/sdk/src/resolve/resolve-compute-limit.js @@ -1,4 +1,4 @@ -import {isTransaction} from "../interaction/interaction.js" +import {isTransaction} from "../interaction/interaction" import {config} from "@onflow/config" import * as logger from "@onflow/util-logger" diff --git a/packages/sdk/src/resolve/resolve-compute-limit.test.js b/packages/sdk/src/resolve/resolve-compute-limit.test.js index 2b2e05c9e..286116132 100644 --- a/packages/sdk/src/resolve/resolve-compute-limit.test.js +++ b/packages/sdk/src/resolve/resolve-compute-limit.test.js @@ -1,4 +1,4 @@ -import {interaction, pipe, makeTransaction} from "../interaction/interaction.js" +import {initInteraction, pipe, makeTransaction} from "../interaction/interaction" import {config} from "@onflow/config" import {resolveComputeLimit} from "./resolve-compute-limit.js" @@ -21,7 +21,7 @@ describe("resolveComputeLimit", () => { }, }), resolveComputeLimit, - ])(interaction()) + ])(initInteraction()) expect(ix.message.computeLimit).toBe(TRANSACTION_COMPUTE_LIMIT) } @@ -36,7 +36,7 @@ describe("resolveComputeLimit", () => { }, async () => { const ix = await pipe([makeTransaction, resolveComputeLimit])( - interaction() + initInteraction() ) expect(ix.message.computeLimit).toBe(CONFIG_COMPUTE_LIMIT) } diff --git a/packages/sdk/src/resolve/resolve-proposer-sequence-number.js b/packages/sdk/src/resolve/resolve-proposer-sequence-number.js index f66bc0adb..4ec55db77 100644 --- a/packages/sdk/src/resolve/resolve-proposer-sequence-number.js +++ b/packages/sdk/src/resolve/resolve-proposer-sequence-number.js @@ -1,6 +1,6 @@ -import {isTransaction, Ok} from "../interaction/interaction.js" -import * as ixModule from "../interaction/interaction.js" -import {response as responseModule} from "../response/response.js" +import {isTransaction, Ok} from "../interaction/interaction" +import * as ixModule from "../interaction/interaction" +import {response as responseModule} from "../response/response" import {config} from "@onflow/config" import {decodeResponse} from "../decode/decode.js" import {getAccount} from "../build/build-get-account.js" diff --git a/packages/sdk/src/resolve/resolve-ref-block-id.js b/packages/sdk/src/resolve/resolve-ref-block-id.js index 5e7af37c8..0a11e1c86 100644 --- a/packages/sdk/src/resolve/resolve-ref-block-id.js +++ b/packages/sdk/src/resolve/resolve-ref-block-id.js @@ -1,11 +1,11 @@ import { isTransaction, Ok, - interaction, + initInteraction, pipe, -} from "../interaction/interaction.js" -import * as ixModule from "../interaction/interaction.js" -import {response} from "../response/response.js" +} from "../interaction/interaction" +import * as ixModule from "../interaction/interaction" +import {response} from "../response/response" import {config} from "@onflow/config" import {decodeResponse} from "../decode/decode.js" import {getBlock} from "../build/build-get-block.js" @@ -23,7 +23,7 @@ async function getRefId(opts) { ) var ix - ix = await pipe(interaction(), [getBlock()]) + ix = await pipe(initInteraction(), [getBlock()]) ix = await sendFn(ix, {config, response, Buffer, ix: ixModule}, {node}) ix = await decodeResponse(ix) return ix.id diff --git a/packages/sdk/src/resolve/resolve-signatures.js b/packages/sdk/src/resolve/resolve-signatures.js index 83bf7f117..9254bb9a2 100644 --- a/packages/sdk/src/resolve/resolve-signatures.js +++ b/packages/sdk/src/resolve/resolve-signatures.js @@ -1,4 +1,4 @@ -import {isTransaction} from "../interaction/interaction.js" +import {isTransaction} from "../interaction/interaction" import {sansPrefix} from "@onflow/util-address" import { encodeTransactionPayload as encodeInsideMessage, diff --git a/packages/sdk/src/resolve/resolve-validators.js b/packages/sdk/src/resolve/resolve-validators.js index 1974aff54..f86ebd02b 100644 --- a/packages/sdk/src/resolve/resolve-validators.js +++ b/packages/sdk/src/resolve/resolve-validators.js @@ -1,4 +1,4 @@ -import {get, pipe, Ok, Bad} from "../interaction/interaction.js" +import {get, pipe, Ok, Bad} from "../interaction/interaction" export async function resolveValidators(ix) { const validators = get(ix, "ix.validators", []) diff --git a/packages/sdk/src/resolve/resolve-voucher-intercept.js b/packages/sdk/src/resolve/resolve-voucher-intercept.js index 7a6067005..45ede7224 100644 --- a/packages/sdk/src/resolve/resolve-voucher-intercept.js +++ b/packages/sdk/src/resolve/resolve-voucher-intercept.js @@ -1,4 +1,4 @@ -import {get, isFn} from "../interaction/interaction.js" +import {get, isFn} from "../interaction/interaction" import {createSignableVoucher} from "./voucher.js" export async function resolveVoucherIntercept(ix) { diff --git a/packages/sdk/src/resolve/resolve.js b/packages/sdk/src/resolve/resolve.js index c17030dd8..4fa5fd526 100644 --- a/packages/sdk/src/resolve/resolve.js +++ b/packages/sdk/src/resolve/resolve.js @@ -1,10 +1,10 @@ -import {pipe, isTransaction} from "../interaction/interaction.js" +import {pipe, isTransaction} from "../interaction/interaction" import {config} from "@onflow/config" import {invariant} from "@onflow/util-invariant" import {Buffer} from "@onflow/rlp" import {send as defaultSend} from "@onflow/transport-http" -import * as ixModule from "../interaction/interaction.js" -import {response} from "../response/response.js" +import * as ixModule from "../interaction/interaction" +import {response} from "../response/response" import {build} from "../build/build.js" import {getBlock} from "../build/build-get-block.js" import {getAccount} from "../build/build-get-account.js" diff --git a/packages/sdk/src/response/__snapshots__/response.test.js.snap b/packages/sdk/src/response/__snapshots__/response.test.ts.snap similarity index 100% rename from packages/sdk/src/response/__snapshots__/response.test.js.snap rename to packages/sdk/src/response/__snapshots__/response.test.ts.snap diff --git a/packages/sdk/src/response/response.test.js b/packages/sdk/src/response/response.test.ts similarity index 73% rename from packages/sdk/src/response/response.test.js rename to packages/sdk/src/response/response.test.ts index 226ca304c..48b843431 100644 --- a/packages/sdk/src/response/response.test.js +++ b/packages/sdk/src/response/response.test.ts @@ -1,4 +1,4 @@ -import {response} from "./response.js" +import {response} from "./response" test("Response - Snapshot", async () => { const resp = response() diff --git a/packages/sdk/src/response/response.js b/packages/sdk/src/response/response.ts similarity index 75% rename from packages/sdk/src/response/response.js rename to packages/sdk/src/response/response.ts index e5e19e385..9c9adf121 100644 --- a/packages/sdk/src/response/response.js +++ b/packages/sdk/src/response/response.ts @@ -1,4 +1,4 @@ -const DEFAULT_RESPONSE = `{ +const DEFAULT_RESPONSE = { "tag":null, "transaction":null, "transactionStatus":null, @@ -11,6 +11,6 @@ const DEFAULT_RESPONSE = `{ "latestBlock":null, "collection":null, "networkParameters":null -}` +} -export const response = () => JSON.parse(DEFAULT_RESPONSE) +export const response = () => ({...DEFAULT_RESPONSE}) diff --git a/packages/sdk/src/sdk.ts b/packages/sdk/src/sdk.ts index 9a4decc99..769188d47 100644 --- a/packages/sdk/src/sdk.ts +++ b/packages/sdk/src/sdk.ts @@ -11,7 +11,8 @@ export { } from "./encode/encode" // Utils export { - interaction, + interaction, // deprecated + initInteraction, isOk, isBad, why, @@ -32,7 +33,7 @@ export { isGetBlockHeader, isGetCollection, isGetNetworkParameters, -} from "./interaction/interaction.js" +} from "./interaction/interaction" export {createSignableVoucher, voucherToTxId} from "./resolve/voucher.js" export {encodeMessageFromSignable} from "./wallet-utils/encode-signable.js" export {template as cadence} from "@onflow/util-template" @@ -57,7 +58,7 @@ export {getTransactionStatus} from "./build/build-get-transaction-status.js" export {getTransaction} from "./build/build-get-transaction.js" export {getNetworkParameters} from "./build/build-get-network-parameters.js" export {limit} from "./build/build-limit.js" -export {args, arg} from "./build/build-arguments.js" +export {args, arg} from "./build/build-arguments" export {proposer} from "./build/build-proposer.js" export {payer} from "./build/build-payer.js" export {ping} from "./build/build-ping.js" @@ -74,7 +75,7 @@ export {resolveFinalNormalization} from "./resolve/resolve-final-normalization" export {resolveProposerSequenceNumber} from "./resolve/resolve-proposer-sequence-number" export {resolveArguments} from "./resolve/resolve-arguments.js" export {resolveAccounts} from "./resolve/resolve-accounts.js" -export {response} from "./response/response.js" +export {response} from "./response/response" export {resolveSignatures} from "./resolve/resolve-signatures.js" export {resolveValidators} from "./resolve/resolve-validators.js" export {resolveRefBlockId} from "./resolve/resolve-ref-block-id.js" diff --git a/packages/sdk/src/send/send.js b/packages/sdk/src/send/send.js index 31254e5a3..e2baf17c6 100644 --- a/packages/sdk/src/send/send.js +++ b/packages/sdk/src/send/send.js @@ -1,9 +1,9 @@ import {Buffer} from "@onflow/rlp" import {send as defaultSend} from "@onflow/transport-http" -import {interaction, pipe} from "../interaction/interaction.js" -import * as ixModule from "../interaction/interaction.js" +import {initInteraction, pipe} from "../interaction/interaction" +import * as ixModule from "../interaction/interaction" import {invariant} from "../build/build-invariant.js" -import {response} from "../response/response.js" +import {response} from "../response/response" import {config} from "@onflow/config" import {resolve as defaultResolve} from "../resolve/resolve.js" @@ -31,7 +31,7 @@ export const send = async (args = [], opts = {}) => { opts.node = opts.node || (await config().get("accessNode.api")) - if (Array.isArray(args)) args = pipe(interaction(), args) + if (Array.isArray(args)) args = pipe(initInteraction(), args) return sendFn( await resolveFn(args), {config, response, ix: ixModule, Buffer}, diff --git a/packages/sdk/src/test-utils/authz-fn.js b/packages/sdk/src/test-utils/authz-fn.ts similarity index 56% rename from packages/sdk/src/test-utils/authz-fn.js rename to packages/sdk/src/test-utils/authz-fn.ts index 7085e4a89..dce507949 100644 --- a/packages/sdk/src/test-utils/authz-fn.js +++ b/packages/sdk/src/test-utils/authz-fn.ts @@ -1,14 +1,19 @@ +import { InteractionAccount } from "@onflow/typedefs" import {withPrefix} from "@onflow/util-address" -export const idof = acct => `${withPrefix(acct.addr)}-${acct.keyId}` +export const idof = (acct: InteractionAccount) => `${withPrefix(acct.addr)}-${acct.keyId}` -export function sig(opts) { +export function sig(opts: Partial) { return ["SIGNATURE", opts.addr, opts.keyId].join(".") } -export function authzFn(opts = {}) { - return function (account) { - const acct = { +interface IAuthzOpts { + signingFunction?: (signable: any) => any +} + +export function authzFn(opts: IAuthzOpts = {}) { + return function (account: Partial) { + const acct: Partial = { ...account, ...opts, resolve: null, @@ -20,7 +25,7 @@ export function authzFn(opts = {}) { return acct - function fallbackSigningFunction(signable) { + function fallbackSigningFunction(_signable: any) { return { addr: acct.addr, keyId: acct.keyId, @@ -30,8 +35,12 @@ export function authzFn(opts = {}) { } } -export function authzResolve(opts = {}) { - return function (account) { +interface IAuthzResolveOpts { + tempId?: string +} + +export function authzResolve(opts: IAuthzResolveOpts = {}) { + return function (account: InteractionAccount) { const {tempId, ...rest} = opts return { ...account, @@ -44,8 +53,15 @@ export function authzResolve(opts = {}) { const ROLE = {proposer: false, authorizer: false, payer: false} const noop = () => {} -export function authzResolveMany(opts = {}) { - return function (account) { +interface IAuthzResolveMany { + tempId?: string + authorizations: any[] + proposer?: any + payer?: any +} + +export function authzResolveMany(opts: IAuthzResolveMany = {authorizations: []}) { + return function (account: InteractionAccount): InteractionAccount { const tempId = opts.tempId || "AUTHZ_RESOLVE_MANY" return { ...account, @@ -63,8 +79,8 @@ export function authzResolveMany(opts = {}) { } } -export function authzDeepResolveMany(opts = {}, depth = 1) { - return function (account) { +export function authzDeepResolveMany(opts: IAuthzResolveMany = {authorizations: []}, depth = 1) { + return function (account: InteractionAccount): InteractionAccount { const tempId = opts.tempId || "AUTHZ_DEEP_RESOLVE_MANY" return { ...account, diff --git a/packages/transport-http/.babelrc b/packages/transport-http/.babelrc index 67fc2886b..1e3225d50 100644 --- a/packages/transport-http/.babelrc +++ b/packages/transport-http/.babelrc @@ -1,7 +1,11 @@ { "presets": [ [ - "@babel/preset-env" - ] + "@babel/preset-env", + { + "useBuiltIns": false + } + ], + "@babel/preset-typescript" ] } diff --git a/packages/transport-http/package.json b/packages/transport-http/package.json index fdf0bab3b..a4bfd030d 100644 --- a/packages/transport-http/package.json +++ b/packages/transport-http/package.json @@ -19,10 +19,11 @@ "@onflow/types": "^1.2.1", "jest": "^29.5.0" }, - "source": "src/sdk-send-http.js", + "source": "src/sdk-send-http.ts", "main": "dist/sdk-send-http.js", "module": "dist/sdk-send-http.module.js", "unpkg": "dist/sdk-send-http.umd.js", + "types": "dist/sdk-send-http.d.ts", "scripts": { "alpha": "npm publish --tag alpha", "prepublishOnly": "npm test && npm run build", diff --git a/packages/transport-http/src/sdk-send-http.js b/packages/transport-http/src/sdk-send-http.ts similarity index 89% rename from packages/transport-http/src/sdk-send-http.js rename to packages/transport-http/src/sdk-send-http.ts index 02386b403..3b0db1486 100644 --- a/packages/transport-http/src/sdk-send-http.js +++ b/packages/transport-http/src/sdk-send-http.ts @@ -6,8 +6,8 @@ export {sendGetCollection} from "./send-get-collection.js" export {sendGetEvents} from "./send-get-events.js" export {sendGetTransaction} from "./send-get-transaction.js" export {sendGetTransactionStatus} from "./send-get-transaction-status.js" -export {sendPing} from "./send-ping.js" +export {sendPing} from "./send-ping" export {sendTransaction} from "./send-transaction.js" export {sendGetNetworkParameters} from "./send-get-network-parameters.js" -export {send} from "./send-http.js" +export {send} from "./send-http" export {HTTPRequestError} from "./http-request.js" diff --git a/packages/transport-http/src/send-http.js b/packages/transport-http/src/send-http.ts similarity index 56% rename from packages/transport-http/src/send-http.js rename to packages/transport-http/src/send-http.ts index ce26a5acf..b6d9a93fe 100644 --- a/packages/transport-http/src/send-http.js +++ b/packages/transport-http/src/send-http.ts @@ -8,15 +8,51 @@ import {sendGetEvents} from "./send-get-events.js" import {sendGetBlock} from "./send-get-block.js" import {sendGetBlockHeader} from "./send-get-block-header.js" import {sendGetCollection} from "./send-get-collection.js" -import {sendPing} from "./send-ping.js" +import {sendPing, ISendPingContext} from "./send-ping" import {sendGetNetworkParameters} from "./send-get-network-parameters.js" +import { Interaction } from "@onflow/typedefs" -export const send = async (ix, context = {}, opts = {}) => { +interface InteractionModule { + isTransaction: (ix: Interaction) => boolean; + isGetTransactionStatus: (ix: Interaction) => boolean; + isGetTransaction: (ix: Interaction) => boolean; + isScript: (ix: Interaction) => boolean; + isGetAccount: (ix: Interaction) => boolean; + isGetEvents: (ix: Interaction) => boolean; + isGetBlock: (ix: Interaction) => boolean; + isGetBlockHeader: (ix: Interaction) => boolean; + isGetCollection: (ix: Interaction) => boolean; + isPing: (ix: Interaction) => boolean; + isGetNetworkParameters: (ix: Interaction) => boolean; +} +interface IContext extends ISendPingContext{ + ix: InteractionModule; +} + +interface IOptsCommon { + node?: string +} + +interface IOpts extends IOptsCommon { + sendTransaction?: (ix: Interaction, context: IContext, opts: IOptsCommon) => void + sendGetTransactionStatus?: (ix: Interaction, context: IContext, opts: IOptsCommon) => void + sendGetTransaction?: (ix: Interaction, context: IContext, opts: IOptsCommon) => void + sendExecuteScript?: (ix: Interaction, context: IContext, opts: IOptsCommon) => void + sendGetAccount?: (ix: Interaction, context: IContext, opts: IOptsCommon) => void + sendGetEvents?: (ix: Interaction, context: IContext, opts: IOptsCommon) => void + sendGetBlockHeader?: (ix: Interaction, context: IContext, opts: IOptsCommon) => void + sendGetCollection?: (ix: Interaction, context: IContext, opts: IOptsCommon) => void + sendPing?: (ix: Interaction, context: IContext, opts: IOptsCommon) => void + sendGetBlock?: (ix: Interaction, context: IContext, opts: IOptsCommon) => void + sendGetNetworkParameters?: (ix: Interaction, context: IContext, opts: IOptsCommon) => void +} + +export const send = async (ix: Interaction, context: IContext, opts: IOpts = {}) => { invariant( - opts.node, + Boolean(opts?.node), `SDK Send Error: Either opts.node or "accessNode.api" in config must be defined.` ) - invariant(context.ix, `SDK Send Error: context.ix must be defined.`) + invariant(Boolean(context.ix), `SDK Send Error: context.ix must be defined.`) ix = await ix diff --git a/packages/transport-http/src/send-ping.js b/packages/transport-http/src/send-ping.js deleted file mode 100644 index 67fc80de3..000000000 --- a/packages/transport-http/src/send-ping.js +++ /dev/null @@ -1,24 +0,0 @@ -import {invariant} from "@onflow/util-invariant" -import {httpRequest as defaultHttpRequest} from "./http-request.js" - -export async function sendPing(ix, context = {}, opts = {}) { - invariant(opts.node, `SDK Send Ping Error: opts.node must be defined.`) - invariant( - context.response, - `SDK Send Ping Error: context.response must be defined.` - ) - - const httpRequest = opts.httpRequest || defaultHttpRequest - - await httpRequest({ - hostname: opts.node, - path: "/v1/blocks?height=sealed", - method: "GET", - body: null, - }) - - let ret = context.response() - ret.tag = ix.tag - - return ret -} diff --git a/packages/transport-http/src/send-ping.test.js b/packages/transport-http/src/send-ping.test.ts similarity index 95% rename from packages/transport-http/src/send-ping.test.js rename to packages/transport-http/src/send-ping.test.ts index bfef942fa..de4fa3181 100644 --- a/packages/transport-http/src/send-ping.test.js +++ b/packages/transport-http/src/send-ping.test.ts @@ -1,4 +1,4 @@ -import {sendPing} from "./send-ping.js" +import {sendPing} from "./send-ping" import {Buffer} from "@onflow/rlp" import {build, ping, resolve, response as responseADT} from "@onflow/sdk" diff --git a/packages/transport-http/src/send-ping.ts b/packages/transport-http/src/send-ping.ts new file mode 100644 index 000000000..378e1c8eb --- /dev/null +++ b/packages/transport-http/src/send-ping.ts @@ -0,0 +1,35 @@ +import {invariant} from "@onflow/util-invariant" +import {httpRequest as defaultHttpRequest} from "./http-request.js" +import { Interaction } from "@onflow/typedefs"; + +export interface ISendPingContext { + response?: Function; +} + +interface ISendPingOpts { + node?: string + httpRequest?: any, + +} + +export async function sendPing(ix: Interaction, context: ISendPingContext = {}, opts: ISendPingOpts = {}) { + invariant(Boolean(opts.node), `SDK Send Ping Error: opts.node must be defined.`) + invariant( + Boolean(context.response), + `SDK Send Ping Error: context.response must be defined.` + ) + + const httpRequest = opts.httpRequest || defaultHttpRequest + + await httpRequest({ + hostname: opts.node, + path: "/v1/blocks?height=sealed", + method: "GET", + body: null, + }) + + let ret = typeof context?.response === 'function' ? context.response() : {} + ret.tag = ix.tag + + return ret +} diff --git a/packages/typedefs/src/index.ts b/packages/typedefs/src/index.ts index 5971369c2..0b10e8ba6 100644 --- a/packages/typedefs/src/index.ts +++ b/packages/typedefs/src/index.ts @@ -288,3 +288,5 @@ export type Provider = { */ name: string } + +export * from "./interaction" diff --git a/packages/typedefs/src/interaction.ts b/packages/typedefs/src/interaction.ts new file mode 100644 index 000000000..df01c5d6f --- /dev/null +++ b/packages/typedefs/src/interaction.ts @@ -0,0 +1,85 @@ + +export const UNKNOWN /* */ = "UNKNOWN" +export const SCRIPT /* */ = "SCRIPT" +export const TRANSACTION /* */ = "TRANSACTION" +export const GET_TRANSACTION_STATUS /* */ = "GET_TRANSACTION_STATUS" +export const GET_ACCOUNT /* */ = "GET_ACCOUNT" +export const GET_EVENTS /* */ = "GET_EVENTS" +export const PING /* */ = "PING" +export const GET_TRANSACTION /* */ = "GET_TRANSACTION" +export const GET_BLOCK /* */ = "GET_BLOCK" +export const GET_BLOCK_HEADER /* */ = "GET_BLOCK_HEADER" +export const GET_COLLECTION /* */ = "GET_COLLECTION" +export const GET_NETWORK_PARAMETERS /* */ = "GET_NETWORK_PARAMETERS" + +export const BAD /* */ = "BAD" +export const OK /* */ = "OK" + +export const ACCOUNT /* */ = "ACCOUNT" +export const PARAM /* */ = "PARAM" +export const ARGUMENT /* */ = "ARGUMENT" + +export const AUTHORIZER /* */ = "authorizer" +export const PAYER /* */ = "payer" +export const PROPOSER /* */ = "proposer" + +export interface InteractionAccount { + "kind": typeof ACCOUNT, + "tempId": string | null, + "addr": string | null, + "keyId": number | string | null, + "sequenceNum": number | null, + "signature": any | null, + "signingFunction": any | null, + "resolve": any | null, + "role": { + "proposer": boolean, + "authorizer": boolean, + "payer": boolean, + "param"?: boolean, + }, + authorization: any, +} + +export interface Interaction { + "tag": string, + "assigns": Record, + "status": string, + "reason": string | null, + "accounts": Record, + "params": Record, + "arguments": Record, + "message": { + "cadence": string | null, + "refBlock": string | null, + "computeLimit": string | null, + "proposer": string | null, + "payer": string | null, + "authorizations": string[], + "params": Record[], + "arguments": string[] + }, + "proposer": string | null, + "authorizations": string[], + "payer": string[], + "events": { + "eventType": string | null, + "start": string | null, + "end": string | null, + "blockIds": string[] + }, + "transaction": { + "id": string | null + }, + "block": { + "id": string | null, + "height": string | null, + "isSealed": boolean | null + }, + "account": { + "addr": string | null + }, + "collection": { + "id": string | null + } +} \ No newline at end of file diff --git a/packages/types/src/types.ts b/packages/types/src/types.ts index cc392f607..9617d6993 100644 --- a/packages/types/src/types.ts +++ b/packages/types/src/types.ts @@ -18,7 +18,7 @@ export interface TypeDescriptor> { asInjection: (x: T) => T } -type TypeDescriptorInput< +export type TypeDescriptorInput< X extends TypeDescriptor> > = X extends TypeDescriptor> ? T : never