-
Notifications
You must be signed in to change notification settings - Fork 128
Refactored fcl-core exec folder files to TypeScript #2473
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 7 commits
ca519d7
19cacff
103a499
19f18b9
9c91841
c4e9d99
d5151a5
33b17bf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import * as sdk from "@onflow/sdk" | ||
import type {ArgsFn} from "./args" | ||
import {normalizeArgs} from "./utils/normalize-args" | ||
import {preQuery} from "./utils/pre" | ||
import {prepTemplateOpts} from "./utils/prep-template-opts" | ||
|
||
export interface QueryOptions { | ||
cadence?: string | ||
args?: ArgsFn | any[] | ||
template?: string | any | ||
isSealed?: boolean | ||
limit?: number | ||
[key: string]: any | ||
} | ||
|
||
/** | ||
* @description Allows you to submit scripts to query the blockchain. | ||
* | ||
* @param opts Query Options and configuration | ||
* @param opts.cadence Cadence Script used to query Flow | ||
* @param opts.args Arguments passed to cadence script | ||
* @param opts.template Interaction Template for a script | ||
* @param opts.isSealed Block Finality | ||
* @param opts.limit Compute Limit for Query | ||
* @returns A promise that resolves to the query result | ||
* | ||
* @example | ||
* const cadence = ` | ||
* cadence: ` | ||
* access(all) fun main(a: Int, b: Int, c: Address): Int { | ||
* log(c) | ||
* return a + b | ||
* } | ||
* `.trim() | ||
* | ||
* const args = (arg, t) => [ | ||
* arg(5, t.Int), | ||
* arg(7, t.Int), | ||
* arg("0xb2db43ad6bc345fec9", t.Address), | ||
* ] | ||
* | ||
* await query({ cadence, args }) | ||
*/ | ||
export async function query(opts: QueryOptions = {}): Promise<any> { | ||
await preQuery(opts) | ||
opts = await prepTemplateOpts(opts) | ||
|
||
return sdk | ||
.send([ | ||
sdk.script(opts.cadence!), | ||
sdk.args(normalizeArgs(opts.args || [])), | ||
sdk.atLatestBlock(opts.isSealed ?? false), | ||
opts.limit && | ||
typeof opts.limit === "number" && | ||
(sdk.limit(opts.limit!) as any), | ||
]) | ||
.then(sdk.decode) | ||
} |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import {isFunc} from "../../utils/is" | ||
import * as sdk from "@onflow/sdk" | ||
import * as t from "@onflow/types" | ||
import type {ArgsFn} from "../args" | ||
|
||
export function normalizeArgs(ax: ArgsFn | any[] | undefined): any[] { | ||
if (isFunc(ax)) return (ax as ArgsFn)(sdk.arg, t) | ||
return [] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,13 @@ import {invariant} from "@onflow/util-invariant" | |
import * as sdk from "@onflow/sdk" | ||
import {isRequired, isObject, isString} from "../../utils/is" | ||
|
||
async function pre(type, opts) { | ||
export interface PreOptions { | ||
cadence?: string | ||
template?: any | ||
[key: string]: any | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. does the same thing apply here? Or is this different There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same, updated and improved! |
||
} | ||
|
||
async function pre(type: string, opts: PreOptions): Promise<void> { | ||
// prettier-ignore | ||
invariant(isRequired(opts), `${type}(opts) -- opts is required`) | ||
// prettier-ignore | ||
|
@@ -23,10 +29,10 @@ async function pre(type, opts) { | |
) | ||
} | ||
|
||
export async function preMutate(opts) { | ||
export async function preMutate(opts: PreOptions): Promise<void> { | ||
return pre("mutate", opts) | ||
} | ||
|
||
export async function preQuery(opts) { | ||
export async function preQuery(opts: PreOptions): Promise<void> { | ||
return pre("query", opts) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does the same thing apply here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same, updated and improved!