Skip to content

Commit 6e5e41e

Browse files
gagdiezfew-sw
andauthored
Add: Typedocs (#1208)
* feat: add typedoc + change tsconfig.base * feat: add typedoc action * feat: temporary disable release action * feat: update typedoc generator action * feat: update typedoc generator action to support pnpm * feat: update action logic for testing purposes * feat: configure pnpm back to version 7 * feat: update action configuration * feat: change action configuration * feat: update build documentation action * feat: minor changes * feat: update tsconfig.base.json * feat: update typedoc action * feat: add readme option * feat: update entryPoints * feat: update entryPoints * feat: change entryPoints to near-api-js * feat: add package entrypointstrategy * feat: fix adding modules content on typedoc generated documentation * feat: update tsconfig.base.json * feat: update tsconfig * feat: update tsconfig files for each package * feat: add custom-theme * feat: add custom-theme * feat: testing configuration * feat: add externalSymbolLinkMappings * feat: add typedoc-theme * feat: update readme files links * feat: update typedoc options * feat: update tsconfig * feat: update out folder * feat: update typedoc-generator * feat: add target-folder option to typedoc-generator action * feat: update typedoc docs generator to allow linking README files to packages files * feat: minor changes * feat: update typedoc action * feat: elete tsconfig.json * feat: make changes to the step Update gh-pages Branch * feat: update typedoc-generator steps * feat: update action * feat: add user/email * feat: add tsconfig.json.local * feat: add write permissions * feat: github action small change * feat: fix divergent changes on action * feat: small changes * feat: add action that syncs branches * feat: fix permission issues * feat: created generated-documentation folder * feat: add folder * feat: clean code * feat: change action configuration * feat: change out folder to build * feat: enable target-folder * feat: update build destination folder * feat: change action logic * feat: update action * feat: disable pull-request action * feat: clean docs folder * feat: remove lfs: true * feat: update action * feat: add concurrency handler * feat: remove clean option * feat: revert to gh-pages root * feat: enable pull-request.action * feat: add near-api-js package to docs job * feat: disable jekyll * feat: update links on README_TYPEDOC.md * feat: migrate typedoc.json to javascript to handle github full path * feat: delete typedoc.json * feat: fix @link on account.ts * feat: update near-api-js tsconfig * feat: tsconfig test for near-api-js * feat: add lib and text to exclude option * feat: remove @link tag on unresolved link RequestSignTransactionsOptions * feat: add typedoc-plugin-merge-modules * feat: update tsconfig.base * feat: update pnpm-lock * feat: delete tsconfig.json * feat: remove plugin typedoc-plugin-merge-modules * feat: disable old docs-generator action * feat: update near-api-js tsconfig * feat: updtae tsconfig.base * feat: update action * feat: update action * feat: fix failed to resolve link warning * feat: fix not included in the documentation warning * feat: delete typedoc.json file * feat: typedoc update * feat: test @link tag * feat: @link wip * feat: @link change * feat: fix @link near.ts * feat: near.ts @link * feat: change near.ts * feat: update @link * feat: update @link tag * feat: readme.md file update * feat: enable release action * feat: update githubpages option * refactor: update typedoc-generator * fix: fixed all links in docs * fix: updated action * fix: docs * feat: added near-api-js to typedocs * fix: output dir for typedocs * fix: non-overlapping name for action --------- Co-authored-by: few-sw <149263800+few-sw@users.noreply.github.com>
1 parent 0be6c42 commit 6e5e41e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+451
-218
lines changed

.github/workflows/docs-generator-trigger.yml

Lines changed: 0 additions & 31 deletions
This file was deleted.
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: Deploy TypeDoc on GitHub pages
2+
3+
on:
4+
push:
5+
branches:
6+
master
7+
8+
env:
9+
NODE_VERSION: 18.x
10+
ENTRY_FILE: 'packages'
11+
CONFIG_PATH: 'tsconfig.base.json'
12+
USES_PNPM: 'true'
13+
DESTINATION_FOLDER: "docs"
14+
15+
jobs:
16+
deploy:
17+
concurrency: ci-${{ github.ref }}
18+
runs-on: ubuntu-latest
19+
steps:
20+
- uses: actions/checkout@v4
21+
22+
- uses: actions/setup-node@v3
23+
with:
24+
node-version: ${{ env.NODE_VERSION }}
25+
26+
- name: Setup pnpm
27+
uses: pnpm/action-setup@v2.2.2
28+
with:
29+
version: 7
30+
31+
- name: Install dependencies
32+
run: pnpm install
33+
34+
- name: Build project
35+
run: pnpm build
36+
37+
- name: Build documentation
38+
run: pnpm docs:generate
39+
40+
- name: Deploy to GitHub pages
41+
uses: JamesIves/github-pages-deploy-action@v4
42+
with:
43+
token: ${{ secrets.GITHUB_TOKEN }}
44+
branch: gh-pages
45+
folder: ${{ env.DESTINATION_FOLDER }}
46+
clean: true

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,5 @@ lib/
2323
test-keys/
2424

2525
.turbo
26+
27+
typedoc-docs/

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# NEAR JavaScript API
22

3-
[![Build Status](https://travis-ci.com/near/near-api-js.svg?branch=master)](https://travis-ci.com/near/near-api-js)
3+
[![Build Status](https://img.shields.io/endpoint.svg?url=https%3A%2F%2Factions-badge.atrox.dev%2Fnear%2Fnear-api-js%2Fbadge&style=flat&label=Build)](https://actions-badge.atrox.dev/near/near-api-js/goto)
44
[![Gitpod Ready-to-Code](https://img.shields.io/badge/Gitpod-Ready--to--Code-blue?logo=gitpod)](https://gitpod.io/#https://github.com/near/near-api-js)
55

66
NEAR JavaScript API is a complete library to interact with the NEAR blockchain. You can use it in the browser, or in Node.js runtime.

docs/README.md

Lines changed: 0 additions & 10 deletions
This file was deleted.

docs/README_TYPEDOC.md

Lines changed: 12 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
"autoclave": "rimraf packages/**/dist && rimraf packages/**/lib && rimraf packages/**/node_modules && rimraf packages/**/coverage && rimraf packages/**/.turbo && rm -rf node_modules",
1515
"test": "turbo run test",
1616
"release": "changeset publish",
17-
"prepare": "husky install"
17+
"prepare": "husky install",
18+
"docs:generate": "typedoc"
1819
},
1920
"devDependencies": {
2021
"@changesets/changelog-github": "^0.4.6",
@@ -28,6 +29,7 @@
2829
"husky": "^7.0.4",
2930
"rimraf": "^3.0.2",
3031
"turbo": "^1.4.5",
32+
"typedoc": "^0.25.3",
3133
"typescript": "^4.9.4"
3234
}
3335
}

packages/accounts/README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ A collection of classes, functions, and types for interacting with accounts and
44

55
## Modules
66

7-
- [Account](src/account.ts) a class with methods to transfer NEAR, manage account keys, sign transactions, etc.
8-
- [AccountMultisig](src/account_multisig.ts) a [multisig](https://github.com/near/core-contracts/tree/master/multisig) deployed `Account` requiring multiple keys to sign transactions
9-
- [Account2FA](src/account_2fa.ts) extension of `AccountMultisig` used in conjunction with 2FA provided by [near-contract-helper](https://github.com/near/near-contract-helper)
10-
- [AccountCreator](src/account_creator.ts) classes for creating NEAR accounts
11-
- [Contract](src/contract.ts) represents a deployed smart contract with view and/or change methods
12-
- [Connection](src/connection.ts) a record containing the information required to connect to NEAR RPC
13-
- [Constants](src/constants.ts) account-specific constants
14-
- [Types](src/types.ts) account-specific types
7+
- [Account](https://github.com/near/near-api-js/blob/master/packages/accounts/src/account.ts) a class with methods to transfer NEAR, manage account keys, sign transactions, etc.
8+
- [AccountMultisig](https://github.com/near/near-api-js/blob/master/packages/accounts/src/account_multisig.ts) a [multisig](https://github.com/near/core-contracts/tree/master/multisig) deployed `Account` requiring multiple keys to sign transactions
9+
- [Account2FA](https://github.com/near/near-api-js/blob/master/packages/accounts/src/account_2fa.ts) extension of `AccountMultisig` used in conjunction with 2FA provided by [near-contract-helper](https://github.com/near/near-contract-helper)
10+
- [AccountCreator](https://github.com/near/near-api-js/blob/master/packages/accounts/src/account_creator.ts) classes for creating NEAR accounts
11+
- [Contract](https://github.com/near/near-api-js/blob/master/packages/accounts/src/contract.ts) represents a deployed smart contract with view and/or change methods
12+
- [Connection](https://github.com/near/near-api-js/blob/master/packages/accounts/src/connection.ts) a record containing the information required to connect to NEAR RPC
13+
- [Constants](https://github.com/near/near-api-js/blob/master/packages/accounts/src/constants.ts) account-specific constants
14+
- [Types](https://github.com/near/near-api-js/blob/master/packages/accounts/src/types.ts) account-specific types
1515

1616
# License
1717

packages/accounts/src/account.ts

Lines changed: 29 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -81,20 +81,20 @@ export interface SignAndSendTransactionOptions {
8181
actions: Action[];
8282
/**
8383
* Metadata to send the NEAR Wallet if using it to sign transactions.
84-
* @see {@link RequestSignTransactionsOptions}
84+
* @see RequestSignTransactionsOptions
8585
*/
8686
walletMeta?: string;
8787
/**
8888
* Callback url to send the NEAR Wallet if using it to sign transactions.
89-
* @see {@link RequestSignTransactionsOptions}
89+
* @see RequestSignTransactionsOptions
9090
*/
9191
walletCallbackUrl?: string;
9292
returnError?: boolean;
9393
}
9494

9595
/**
9696
* Options used to initiate a function call (especially a change function call)
97-
* @see {@link account!Account#viewFunction} to initiate a view function call
97+
* @see {@link Account#viewFunction | viewFunction} to initiate a view function call
9898
*/
9999
export interface FunctionCallOptions {
100100
/** The NEAR account id where the contract is deployed */
@@ -122,18 +122,18 @@ export interface FunctionCallOptions {
122122
export interface ChangeFunctionCallOptions extends FunctionCallOptions {
123123
/**
124124
* Metadata to send the NEAR Wallet if using it to sign transactions.
125-
* @see {@link RequestSignTransactionsOptions}
125+
* @see RequestSignTransactionsOptions
126126
*/
127127
walletMeta?: string;
128128
/**
129129
* Callback url to send the NEAR Wallet if using it to sign transactions.
130-
* @see {@link RequestSignTransactionsOptions}
130+
* @see RequestSignTransactionsOptions
131131
*/
132132
walletCallbackUrl?: string;
133133
}
134-
export interface ViewFunctionCallOptions extends FunctionCallOptions {
135-
parse?: (response: Uint8Array) => any;
136-
blockQuery?: BlockReference;
134+
export interface ViewFunctionCallOptions extends FunctionCallOptions {
135+
parse?: (response: Uint8Array) => any;
136+
blockQuery?: BlockReference;
137137
}
138138

139139
interface StakedBalance {
@@ -163,11 +163,7 @@ function bytesJsonStringify(input: any): Buffer {
163163
}
164164

165165
/**
166-
* This class provides common account related RPC calls including signing transactions with a {@link utils/key_pair!KeyPair}.
167-
*
168-
* @hint Use {@link walletAccount!WalletConnection} in the browser to redirect to [NEAR Wallet](https://wallet.near.org/) for Account/key management using the {@link key_stores/browser_local_storage_key_store!BrowserLocalStorageKeyStore}.
169-
* @see [https://docs.near.org/docs/develop/front-end/naj-quick-reference#account](https://docs.near.org/tools/near-api-js/quick-reference#account)
170-
* @see [Account Spec](https://nomicon.io/DataStructures/Account.html)
166+
* This class provides common account related RPC calls including signing transactions with a {@link "@near-js/crypto".key_pair.KeyPair | KeyPair}.
171167
*/
172168
export class Account {
173169
readonly connection: Connection;
@@ -194,7 +190,7 @@ export class Account {
194190
* Create a signed transaction which can be broadcast to the network
195191
* @param receiverId NEAR account receiving the transaction
196192
* @param actions list of actions to perform as part of the transaction
197-
* @see {@link providers/json-rpc-provider!JsonRpcProvider#sendTransaction | JsonRpcProvider.sendTransaction}
193+
* @see {@link "@near-js/providers".json-rpc-provider.JsonRpcProvider.sendTransaction | JsonRpcProvider.sendTransaction}
198194
*/
199195
protected async signTransaction(receiverId: string, actions: Action[]): Promise<[Uint8Array, SignedTransaction]> {
200196
const accessKeyInfo = await this.findAccessKey(receiverId, actions);
@@ -214,7 +210,7 @@ export class Account {
214210

215211
/**
216212
* Sign a transaction to preform a list of actions and broadcast it using the RPC API.
217-
* @see {@link providers/json-rpc-provider!JsonRpcProvider#sendTransaction | JsonRpcProvider.sendTransaction}
213+
* @see {@link "@near-js/providers".json-rpc-provider.JsonRpcProvider | JsonRpcProvider }
218214
*/
219215
async signAndSendTransaction({ receiverId, actions, returnError }: SignAndSendTransactionOptions): Promise<FinalExecutionOutcome> {
220216
let txHash, signedTx;
@@ -248,7 +244,7 @@ export class Account {
248244
printTxOutcomeLogsAndFailures({ contractId: signedTx.transaction.receiverId, outcome: result });
249245

250246
// Should be falsy if result.status.Failure is null
251-
if (!returnError && typeof result.status === 'object' && typeof result.status.Failure === 'object' && result.status.Failure !== null) {
247+
if (!returnError && typeof result.status === 'object' && typeof result.status.Failure === 'object' && result.status.Failure !== null) {
252248
// if error data has error_message and error_type properties, we consider that node returned an error in the old format
253249
if (result.status.Failure.error_message && result.status.Failure.error_type) {
254250
throw new TypedError(
@@ -266,7 +262,7 @@ export class Account {
266262
accessKeyByPublicKeyCache: { [key: string]: AccessKeyView } = {};
267263

268264
/**
269-
* Finds the {@link providers/provider!AccessKeyView} associated with the accounts {@link utils/key_pair!PublicKey} stored in the {@link key_stores/keystore!KeyStore}.
265+
* Finds the {@link AccessKeyView} associated with the accounts {@link PublicKey} stored in the {@link "@near-js/keystores".keystore.KeyStore | Keystore}.
270266
*
271267
* @todo Find matching access key based on transaction (i.e. receiverId and actions)
272268
*
@@ -396,16 +392,16 @@ export class Account {
396392
this.validateArgs(args);
397393
let functionCallArgs;
398394

399-
if(jsContract){
400-
const encodedArgs = this.encodeJSContractArgs( contractId, methodName, JSON.stringify(args) );
401-
functionCallArgs = ['call_js_contract', encodedArgs, gas, attachedDeposit, null, true ];
402-
} else{
395+
if (jsContract) {
396+
const encodedArgs = this.encodeJSContractArgs(contractId, methodName, JSON.stringify(args));
397+
functionCallArgs = ['call_js_contract', encodedArgs, gas, attachedDeposit, null, true];
398+
} else {
403399
const stringifyArg = stringify === undefined ? stringifyJsonOrBytes : stringify;
404400
functionCallArgs = [methodName, args, gas, attachedDeposit, stringifyArg, false];
405401
}
406402

407403
return this.signAndSendTransaction({
408-
receiverId: jsContract ? this.connection.jsvmAccountId: contractId,
404+
receiverId: jsContract ? this.connection.jsvmAccountId : contractId,
409405
// eslint-disable-next-line prefer-spread
410406
actions: [functionCall.apply(void 0, functionCallArgs)],
411407
walletMeta,
@@ -543,20 +539,20 @@ export class Account {
543539
blockQuery = { finality: 'optimistic' }
544540
}: ViewFunctionCallOptions): Promise<any> {
545541
let encodedArgs;
546-
542+
547543
this.validateArgs(args);
548-
549-
if(jsContract){
550-
encodedArgs = this.encodeJSContractArgs(contractId, methodName, Object.keys(args).length > 0 ? JSON.stringify(args): '');
551-
} else{
552-
encodedArgs = stringify(args);
544+
545+
if (jsContract) {
546+
encodedArgs = this.encodeJSContractArgs(contractId, methodName, Object.keys(args).length > 0 ? JSON.stringify(args) : '');
547+
} else {
548+
encodedArgs = stringify(args);
553549
}
554550

555551
const result = await this.connection.provider.query<CodeResult>({
556552
request_type: 'call_function',
557553
...blockQuery,
558554
account_id: jsContract ? this.connection.jsvmAccountId : contractId,
559-
method_name: jsContract ? 'view_js_contract' : methodName,
555+
method_name: jsContract ? 'view_js_contract' : methodName,
560556
args_base64: encodedArgs.toString('base64')
561557
});
562558

@@ -575,7 +571,7 @@ export class Account {
575571
* @param prefix allows to filter which keys should be returned. Empty prefix means all keys. String prefix is utf-8 encoded.
576572
* @param blockQuery specifies which block to query state at. By default returns last "optimistic" block (i.e. not necessarily finalized).
577573
*/
578-
async viewState(prefix: string | Uint8Array, blockQuery: BlockReference = { finality: 'optimistic' } ): Promise<Array<{ key: Buffer; value: Buffer}>> {
574+
async viewState(prefix: string | Uint8Array, blockQuery: BlockReference = { finality: 'optimistic' }): Promise<Array<{ key: Buffer; value: Buffer }>> {
579575
const { values } = await this.connection.provider.query<ViewStateResult>({
580576
request_type: 'view_state',
581577
...blockQuery,
@@ -651,12 +647,12 @@ export class Account {
651647
* NOTE: If the tokens are delegated to a staking pool that is currently on pause or does not have enough tokens to participate in validation, they won't be accounted for.
652648
* @returns {Promise<ActiveDelegatedStakeBalance>}
653649
*/
654-
async getActiveDelegatedStakeBalance(): Promise<ActiveDelegatedStakeBalance> {
650+
async getActiveDelegatedStakeBalance(): Promise<ActiveDelegatedStakeBalance> {
655651
const block = await this.connection.provider.block({ finality: 'final' });
656652
const blockHash = block.header.hash;
657653
const epochId = block.header.epoch_id;
658654
const { current_validators, next_validators, current_proposals } = await this.connection.provider.validators(epochId);
659-
const pools:Set<string> = new Set();
655+
const pools: Set<string> = new Set();
660656
[...current_validators, ...next_validators, ...current_proposals]
661657
.forEach((validator) => pools.add(validator.account_id));
662658

@@ -704,7 +700,7 @@ export class Account {
704700
}
705701
return result;
706702
},
707-
{ stakedValidators: [], failedValidators: [], total: new BN(0) });
703+
{ stakedValidators: [], failedValidators: [], total: new BN(0) });
708704

709705
return {
710706
...summary,

packages/accounts/src/account_2fa.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export class Account2FA extends AccountMultisig {
4646

4747
/**
4848
* Sign a transaction to preform a list of actions and broadcast it using the RPC API.
49-
* @see {@link providers/json-rpc-provider!JsonRpcProvider#sendTransaction | JsonRpcProvider.sendTransaction}
49+
* @see {@link "@near-js/providers".json-rpc-provider.JsonRpcProvider.sendTransaction | JsonRpcProvider.sendTransaction}
5050
*/
5151
async signAndSendTransaction({ receiverId, actions }: SignAndSendTransactionOptions): Promise<FinalExecutionOutcome> {
5252
await super.signAndSendTransaction({ receiverId, actions });

packages/accounts/src/contract.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,14 @@ export interface ContractMethods {
8585
/**
8686
* Methods that change state. These methods cost gas and require a signed transaction.
8787
*
88-
* @see {@link account!Account.functionCall}
88+
* @see {@link Account#functionCall}
8989
*/
9090
changeMethods: string[];
9191

9292
/**
9393
* View methods do not require a signed transaction.
9494
*
95-
* @see {@link account!Account#viewFunction}
95+
* @see {@link Account#viewFunction}
9696
*/
9797
viewMethods: string[];
9898

0 commit comments

Comments
 (0)