Skip to content

Commit

Permalink
feat: implement TypeDoc in Script (#1165)
Browse files Browse the repository at this point in the history
* feat: add typedoc and tsdoc to wallet package

* fix: resolve end tag error in vitepress

* feat: improve typedoc blocks in account

* feat: generate vitepress links for account

* feat: add typedoc documentation to BaseWalletUnlocked

* feat: add typedoc documentation to BaseWalletUnlocked

* feat: add typedoc documentation to WalletLocked and WalletUnlocked

* feat: add typedoc documentation to the wallet

* chore: changeset

* chore: linting

* chore: force-rebuild

* feat: make fuels a dependecy of the docs app

* feat: add typedoc to script package

* feat: generate script typedoc links

* feat: add typedoc blocks to script package

* chore: changeset

* chore: linting

---------

Co-authored-by: danielbate <--global>
  • Loading branch information
danielbate committed Aug 9, 2023
1 parent 4a64634 commit f1a4936
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .changeset/empty-insects-march.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
---
3 changes: 3 additions & 0 deletions apps/docs/scripts/typedoc-postbuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ const recreateInternalLinks = () => {
{ regex: 'fuel_ts_address.md', replacement: '/api/Address/index.md' },
{ regex: 'fuel_ts_interfaces.md', replacement: '/api/Interfaces/index.md' },
{ regex: 'fuel_ts_wallet.md', replacement: '/api/Wallet/index.md' },
{ regex: 'fuel_ts_script.md', replacement: '/api/Script/index.md' },
// Address replacements
{ regex: 'address-Address.md', replacement: '/api/Address/Address.md' },
// Interfaces replacements
Expand All @@ -116,6 +117,8 @@ const recreateInternalLinks = () => {
{ regex: 'wallet-WalletUnlocked.md', replacement: '/api/Wallet/WalletUnlocked.md' },
{ regex: 'wallet-WalletLocked.md', replacement: '/api/Wallet/WalletLocked.md' },
{ regex: 'wallet-Wallet.md', replacement: '/api/Wallet/Wallet.md' },
// Script replacements
{ regex: 'script-Script.md', replacement: '/api/Script/Script.md' },
// Prefix cleanups
{ regex: '../modules/', replacement: '/api/' },
{ regex: '../classes/', replacement: '/api/' },
Expand Down
3 changes: 2 additions & 1 deletion apps/docs/typedoc.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"entryPoints": [
"../../packages/address",
"../../packages/interfaces",
"../../packages/wallet"
"../../packages/wallet",
"../../packages/script",
],
"out": "src/api",
"githubPages": false,
Expand Down
46 changes: 46 additions & 0 deletions packages/script/src/script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,62 @@ import type { Account } from '@fuel-ts/wallet';

import { ScriptInvocationScope } from './script-invocation-scope';

/**
* Represents the result of a script execution.
*/
type Result<T> = {
value: T | BN | undefined;
logs: unknown[];
};

/**
* Represents a function that can be invoked within a script.
*/
type InvokeMain<TArgs extends Array<any> = Array<any>, TReturn = any> = (
...args: TArgs
) => ScriptInvocationScope<TArgs, TReturn>;

/**
* `Script` provides a typed interface for interacting with the script program type.
*/
export class Script<TInput extends Array<any>, TOutput> extends AbstractScript {
/**
* The compiled bytecode of the script.
*/
bytes: Uint8Array;

/**
* The ABI interface for the script.
*/
interface: Interface;

/**
* The account associated with the script.
*/
account: Account;

/**
* The script request object.
*/
script!: ScriptRequest<InputValue<void>[], Result<TOutput>>;

/**
* The provider used for interacting with the network.
*/
provider: Provider;

/**
* Functions that can be invoked within the script.
*/
functions: { main: InvokeMain<TInput, TOutput> };

/**
* Create a new instance of the Script class.
*
* @param bytecode - The compiled bytecode of the script.
* @param abi - The ABI interface for the script.
* @param account - The account associated with the script.
*/
constructor(bytecode: BytesLike, abi: JsonAbi, account: Account) {
super();
this.bytes = arrayify(bytecode);
Expand All @@ -42,6 +81,13 @@ export class Script<TInput extends Array<any>, TOutput> extends AbstractScript {
};
}

/**
* Set the configurable constants of the script.
*
* @param configurables - An object containing the configurable constants and their values.
* @throws Will throw an error if the script has no configurable constants to be set or if an invalid constant is provided.
* @returns This instance of the `Script`.
*/
setConfigurableConstants(configurables: { [name: string]: unknown }) {
try {
if (!Object.keys(this.interface.configurables).length) {
Expand Down
2 changes: 2 additions & 0 deletions packages/script/src/scripts.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { ScriptRequest } from '@fuel-ts/program';

/**
* @hidden
*
* A script that just returns zero
*
* Accepts nothing
Expand Down
4 changes: 4 additions & 0 deletions packages/script/tsdoc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"$schema": "https://developer.microsoft.com/json-schemas/tsdoc/v0/tsdoc.schema.json",
"extends": ["../../tsdoc.base.json"]
}
5 changes: 5 additions & 0 deletions packages/script/typedoc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"$schema": "https://typedoc.org/schema.json",
"extends": ["../../typedoc.base.json"],
"entryPoints": ["src/index.ts"]
}

0 comments on commit f1a4936

Please sign in to comment.