Skip to content
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

Fix documentation rendering #965

Open
wants to merge 65 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 40 commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
9ee3090
update README badges
ElliotFriend May 10, 2024
8317c6c
remove conflicting class tags from call builder classes
ElliotFriend May 10, 2024
96b0796
Merge branch 'master' into 920-documentation-rendering
ElliotFriend May 11, 2024
a5e188d
removing old soroban links in README.md
ElliotFriend May 13, 2024
82335be
changing old soroban link in another readme file
ElliotFriend May 13, 2024
cdfe297
changing old soroban links to new home in dev docs
ElliotFriend May 13, 2024
e7d721c
make WebAuth show up as a namespace
ElliotFriend May 13, 2024
8bc0f5a
collect methods and classes into a SorobanRpc namespace for JSDoc
ElliotFriend May 14, 2024
887f35c
create a Horizon JSDoc namespace and add the server class to it
ElliotFriend May 14, 2024
0b5b3e8
fix broken links to API dev docs
ElliotFriend May 14, 2024
1c7c9b0
add the Durability enum to the SorobanRPC JSDoc namespace
ElliotFriend May 14, 2024
f1eb36a
fix links to the SorobanRPC server methods
ElliotFriend May 14, 2024
22db24a
link call builders to the horizon.server methods
ElliotFriend May 14, 2024
9d663a1
create a util namespace and add validateTimebounds to it
ElliotFriend May 14, 2024
c1d6a11
remove unnecessary code blocks from ContractSpec examples
ElliotFriend May 14, 2024
aee50b1
group some const declarations into more relevant namespaces/classes
ElliotFriend May 14, 2024
94bd492
make a stellartoml JSDoc namespace
ElliotFriend May 14, 2024
ce3d74c
flesh out the jsdoc info for the jsonrpc postObject function
ElliotFriend May 14, 2024
d908609
some minor jsdoc fixups
ElliotFriend May 14, 2024
9f4555b
make federation a module, include the typedefs
ElliotFriend May 16, 2024
260b9c2
add throws tags to federation methods
ElliotFriend May 16, 2024
879b9b5
mark most of the "call builder" classes as private in JSDoc
ElliotFriend May 17, 2024
3da0c0b
fine-tune the JSDoc syntaxes and types in config.ts
ElliotFriend May 17, 2024
a19df6e
JSDoc fixes for the Utils class
ElliotFriend May 17, 2024
8253b25
mark the Ok and Err rust type classes as private in JSDoc
ElliotFriend May 17, 2024
db23f84
change StellarToml from a JSDoc namespace to a module
ElliotFriend May 17, 2024
bdf6dbb
change webauth from a JSDoc namespace to a module
ElliotFriend May 17, 2024
8269c16
make SorobanRpc a JSDoc module instead of a namespace
ElliotFriend May 17, 2024
d04527a
mark the AccountResponse class as private in JSDoc
ElliotFriend May 17, 2024
ae18fa4
add soroban tx timeout const to the SorobanRpc.Server module
ElliotFriend May 17, 2024
51f8016
try out a new JSDoc theme
ElliotFriend May 17, 2024
3ae5a6f
Merge branch 'master' into 920-documentation-rendering
ElliotFriend May 17, 2024
334731a
rename SorobanRpc to rpc in JSDoc comments
ElliotFriend May 17, 2024
d95209f
make contract a JSDoc module
ElliotFriend May 17, 2024
937b7b1
mark contract export as private in JSDoc
ElliotFriend May 17, 2024
a0e21ff
mark postObject as private in JSDoc
ElliotFriend May 17, 2024
b684b80
mark contract/utils functions as private in JSDoc
ElliotFriend May 17, 2024
0195708
remove unused import to fix tests (i think?)
ElliotFriend May 17, 2024
422c3a2
add some default values to JSDoc constants
ElliotFriend May 17, 2024
b0b93bb
fix error message type
ElliotFriend May 17, 2024
403d165
break the errors classes into multiple files for JSDoc rendering
ElliotFriend May 17, 2024
4efede5
add JSDoc type definition to friendbot api
ElliotFriend May 17, 2024
afd392b
add default value to max toml file size in JSDoc
ElliotFriend May 17, 2024
462e5f6
try to clarify when timebounds are attached to tx in JSDoc
ElliotFriend May 17, 2024
5b12f6b
clarify note about when the timebounds are added to client txs
ElliotFriend May 21, 2024
6f74f95
Merge remote-tracking branch 'origin/master' into 920-documentation-r…
ElliotFriend Jun 4, 2024
a42c08e
update some federation links
ElliotFriend Jun 4, 2024
e2707c4
fixes to rpc server links, types, etc.
ElliotFriend Jun 4, 2024
0ac4f7d
some fixes to links, params, etc. in WebAuth module
ElliotFriend Jun 5, 2024
afaf06e
improving docs rendering for errors
ElliotFriend Jun 18, 2024
643a330
Merge remote-tracking branch 'origin/master' into 920-documentation-r…
ElliotFriend Jun 18, 2024
4c164c4
remove unused jsdoc theme package
ElliotFriend Jun 18, 2024
ceaf127
move better-docs to dev deps, remove old jsdoc theme minami
ElliotFriend Sep 17, 2024
59ba38e
Merge branch 'master' of github.com:stellar/js-stellar-sdk into 920-d…
ElliotFriend Sep 17, 2024
38ef48a
formatting and linting
ElliotFriend Sep 18, 2024
f5665b0
ignore test output file from prettier
ElliotFriend Sep 18, 2024
dd3cee8
use correct github link in docs site header
ElliotFriend Sep 18, 2024
c5a125c
correct old rpc and horizon docs urls
ElliotFriend Sep 18, 2024
d4db2c5
tweak docs for config class and interface
ElliotFriend Sep 19, 2024
fa9f6c8
fix all Server.* modules being lumped together
ElliotFriend Sep 19, 2024
a18da01
add exceptions for unknown jsdoc tags from base repo
ElliotFriend Sep 19, 2024
f5652ed
some fine-tuning and tweaks
ElliotFriend Sep 20, 2024
0980205
fold rust result interfaces into the contract module
ElliotFriend Sep 20, 2024
139a1da
Merge branch 'master' of github.com:stellar/js-stellar-sdk into 920-d…
ElliotFriend Sep 20, 2024
841f7c9
use prettier in src directory
ElliotFriend Sep 20, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
</div>

<p align="center">
<a href="https://badge.fury.io/js/stellar-sdk"><img src="https://badge.fury.io/js/stellar-sdk.svg" alt="npm version" height="18"></a>
<a href="https://www.npmjs.com/package/stellar-sdk">
<img alt="Weekly Downloads" src="https://img.shields.io/npm/dw/stellar-sdk" />
<a href="https://badge.fury.io/js/@stellar%2Fstellar-sdk"><img src="https://badge.fury.io/js/@stellar%2Fstellar-sdk.svg" alt="npm version" height="18"></a>
<a href="https://www.npmjs.com/package/@stellar/stellar-sdk">
<img alt="Weekly Downloads" src="https://img.shields.io/npm/dw/@stellar/stellar-sdk" />
</a>
<a href="https://github.com/stellar/js-stellar-sdk/actions/workflows/tests.yml"><img alt="Test Status" src="https://github.com/stellar/js-stellar-sdk/actions/workflows/tests.yml/badge.svg" /></a>
</p>

js-stellar-sdk is a JavaScript library for communicating with a
[Stellar Horizon server](https://github.com/stellar/go/tree/master/services/horizon) and [Soroban RPC](https://soroban.stellar.org/docs/reference/rpc).
[Stellar Horizon server](https://github.com/stellar/go/tree/master/services/horizon) and [Soroban RPC](https://developers.stellar.org/network/soroban-rpc).
It is used for building Stellar apps either on Node.js or in the browser, though it can be used in other environments with some tinkering.

It provides:
Expand Down Expand Up @@ -89,14 +89,14 @@ If you don't want to use or install Bower, you can copy the packaged JS files fr

The usage documentation for this library lives in a handful of places:

* across the [Stellar Developer Docs](), which includes tutorials and examples,
* across the [Stellar Developer Docs](https://developers.stellar.org), which includes tutorials and examples,
* within [this repository itself](https://github.com/stellar/js-stellar-sdk/blob/master/docs/reference/readme.md), and
* on the generated [API doc site](https://stellar.github.io/js-stellar-sdk/).

You can also refer to:

* the [documentation](https://developers.stellar.org/network/horizon) for the Horizon REST API (if using the `Horizon` module) and
* the [documentation](https://soroban.stellar.org/docs/reference/rpc) for Soroban RPC's API (if using the `rpc` module)
* the [documentation](https://developers.stellar.org/network/soroban-rpc) for Soroban RPC's API (if using the `rpc` module)

### Usage with React-Native

Expand Down
33 changes: 30 additions & 3 deletions config/.jsdoc.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,38 @@
"include": ["lib/", "js-stellar-base/src"],
"exclude": "js-stellar-base/src/generated"
},
"plugins": ["plugins/markdown"],
"template": {
"default": {
"useLongNameInNav": true
}
},
"opts": {
"readme": "README.md",
"destination": "jsdoc/",
"recurse": true,
"template": "node_modules/minami",
"readme": "README.md"
"verbose": true,
"template": "node_modules/clean-jsdoc-theme",
"theme_opts": {
"default_theme": "fallback-light",
"title": "Home",
"menu": [
{
"title": "GitHub",
"link": "https://github.com/stellar/js-stellar-sdk",
"target": "_blank"
},
{
"title": "npm",
"link": "https://www.npmjs.com/package/@stellar/stellar-sdk",
"target": "_blank"
}
],
"prefixModuleToSidebarItems_experimental": true
}
},
"plugins": ["plugins/markdown"]
"markdown": {
"hardwrap": false,
"idInHeadings": true
}
}
2 changes: 1 addition & 1 deletion docs/reference/readme.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: Overview
---
The JavaScript Stellar SDK facilitates integration with the Stellar [Horizon API server](https://developers.stellar.org/api/), the Stellar [Soroban RPC server](https://soroban.stellar.org/docs/reference/rpc) and submission of Stellar transactions, either on Node.js or in the browser. It has three main uses: [querying Horizon](#querying-horizon), [interacting with Soroban RPC](), and [building, signing, and submitting transactions to the Stellar network](#building-transactions).
The JavaScript Stellar SDK facilitates integration with the Stellar [Horizon API server](https://developers.stellar.org/api/), the Stellar [Soroban RPC server](https://developers.stellar.org/network/soroban-rpc) and submission of Stellar transactions, either on Node.js or in the browser. It has three main uses: [querying Horizon](#querying-horizon), [interacting with Soroban RPC](), and [building, signing, and submitting transactions to the Stellar network](#building-transactions).

* [Building and installing the SDK](https://github.com/stellar/js-stellar-sdk)
* [Examples of using the SDK](./examples.md)
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"build:browser": "webpack -c config/webpack.config.browser.js",
"build:docs": "cross-env NODE_ENV=docs yarn _babel",
"clean": "rm -rf lib/ dist/ coverage/ .nyc_output/ jsdoc/ test/e2e/.soroban",
"docs": "yarn build:docs && jsdoc -c ./config/.jsdoc.json --verbose",
"docs": "yarn build:docs && jsdoc -c ./config/.jsdoc.json",
"test": "yarn build:test && yarn test:node && yarn test:integration && yarn test:browser",
"test:e2e": "./test/e2e/initialize.sh && ava",
"test:node": "yarn _nyc mocha --recursive 'test/unit/**/*.js'",
Expand Down Expand Up @@ -120,6 +120,7 @@
"chai": "^4.3.10",
"chai-as-promised": "^7.1.1",
"chai-http": "^4.3.0",
"clean-jsdoc-theme": "^4.3.0",
"cross-env": "^7.0.3",
"dotenv": "^16.4.5",
"eslint": "^8.57.0",
Expand Down
26 changes: 9 additions & 17 deletions src/config.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
/**
* @typedef {Object} Configuration
* @memberof Config
* @property {boolean} [allowHttp=false] Allow connecting to http servers, default: `false`. This must be set to false in production deployments!
* @property {number} [timeout=0] Allow a timeout, default: 0. Allows user to avoid nasty lag due to TOML resolve issue. You can also use {@link Config} class to set this globally.
*/

interface Configuration {
/**
* Allow connecting to http servers, default: `false`. This must be set to false in production deployments!
*
* @type {boolean}
*/
allowHttp: boolean;
/**
* Allow a timeout, default: 0. Allows user to avoid nasty lag due to TOML resolve issue. You can also use {@link Config} class to set this globally.
*
* @type {number}
*/
timeout: number;
}

Expand All @@ -23,18 +20,13 @@ let config = Object.assign({}, defaultConfig);
/**
* Global config class.
*
* Usage node:
* ```
* @example <caption>Usage in node</caption>
* import {Config} from 'stellar-sdk';
* Config.setAllowHttp(true);
* Config.setTimeout(5000);
* ```
*
* Usage browser:
* ```
* @example <caption>Usage in the browser</caption>
* StellarSdk.Config.setAllowHttp(true);
* StellarSdk.Config.setTimeout(5000);
* ```
* @static
*/
class Config {
Expand Down
18 changes: 14 additions & 4 deletions src/contract/assembled_transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ import {
} from "./utils";
import { SentTransaction } from "./sent_transaction";

/** @module contract */

/**
* An impossible account on the Stellar network
* @constant {string}
* @default GAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAWHF
* @memberof module:contract
*/
export const NULL_ACCOUNT =
"GAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAWHF";

Expand All @@ -47,7 +55,7 @@ export const NULL_ACCOUNT =
* Let's look at examples of how to use `AssembledTransaction` for a variety of
* use-cases:
*
* # 1. Simple read call
* #### 1. Simple read call
*
* Since these only require simulation, you can get the `result` of the call
* right after constructing your `AssembledTransaction`:
Expand Down Expand Up @@ -80,7 +88,7 @@ export const NULL_ACCOUNT =
* })
* ```
*
* # 2. Simple write call
* #### 2. Simple write call
*
* For write calls that will be simulated and then sent to the network without
* further manipulation, only one more step is needed:
Expand Down Expand Up @@ -114,7 +122,7 @@ export const NULL_ACCOUNT =
* const { result } = await tx.signAndSend()
* ```
*
* # 3. More fine-grained control over transaction construction
* #### 3. More fine-grained control over transaction construction
*
* If you need more control over the transaction before simulating it, you can
* set various {@link MethodOptions} when constructing your
Expand Down Expand Up @@ -147,7 +155,7 @@ export const NULL_ACCOUNT =
* If you need to inspect the simulation later, you can access it with
* `tx.simulation`.
*
* # 4. Multi-auth workflows
* #### 4. Multi-auth workflows
*
* Soroban, and Stellar in general, allows multiple parties to sign a
* transaction.
Expand Down Expand Up @@ -234,6 +242,8 @@ export const NULL_ACCOUNT =
* To see an even more complicated example, where Alice swaps with Bob but the
* transaction is invoked by yet another party, check out
* [test-swap.js](../../test/e2e/src/test-swap.js).
*
* @memberof module:contract
*/
export class AssembledTransaction<T> {
/**
Expand Down
10 changes: 6 additions & 4 deletions src/contract/basic_node_signer.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
import { Keypair, TransactionBuilder, hash } from "@stellar/stellar-base";
import type { AssembledTransaction } from "./assembled_transaction";
import type { Client } from "./client";

/**
* For use with {@link Client} and {@link AssembledTransaction}.
* For use with {@link Client} and {@link module:contract.AssembledTransaction}.
* Implements `signTransaction` and `signAuthEntry` with signatures expected by
* those classes. This is useful for testing and maybe some simple Node
* applications. Feel free to use this as a starting point for your own
* Wallet/TransactionSigner implementation.
*
* @memberof module:contract
*
* @param {Keypair} keypair {@link Keypair} to use to sign the transaction or auth entry
* @param {string} networkPassphrase passphrase of network to sign for
*/
export const basicNodeSigner = (
/** {@link Keypair} to use to sign the transaction or auth entry */
keypair: Keypair,
/** passphrase of network to sign for */
networkPassphrase: string,
) => ({
// eslint-disable-next-line require-await
Expand Down
48 changes: 26 additions & 22 deletions src/contract/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,23 @@ import { AssembledTransaction } from "./assembled_transaction";
import type { ClientOptions, MethodOptions } from "./types";
import { processSpecEntryStream } from './utils';

/**
* Generate a class from the contract spec that where each contract method
* gets included with an identical name.
*
* Each method returns an {@link AssembledTransaction} that can be used to
* modify, simulate, decode results, and possibly sign, & submit the
* transaction.
*
* @memberof module:contract
*
* @constructor
* @param {module:contract.Spec} spec {@link Spec} to construct a Client for
* @param {ClientOptions} options see {@link ClientOptions}
*/
export class Client {
/**
* Generate a class from the contract spec that where each contract method
* gets included with an identical name.
*
* Each method returns an {@link AssembledTransaction} that can be used to
* modify, simulate, decode results, and possibly sign, & submit the
* transaction.
*/
constructor(
/** {@link Spec} to construct a Client for */
public readonly spec: Spec,
/** see {@link ClientOptions} */
public readonly options: ClientOptions,
) {
this.spec.funcs().forEach((xdrFn) => {
Expand Down Expand Up @@ -53,11 +57,11 @@ export class Client {
/**
* Generates a Client instance from the provided ClientOptions and the contract's wasm hash.
* The wasmHash can be provided in either hex or base64 format.
*
* @param wasmHash The hash of the contract's wasm binary, in either hex or base64 format.
* @param options The ClientOptions object containing the necessary configuration, including the rpcUrl.
* @param format The format of the provided wasmHash, either "hex" or "base64". Defaults to "hex".
* @returns A Promise that resolves to a Client instance.
*
* @param {Buffer | string} wasmHash The hash of the contract's wasm binary, in either hex or base64 format.
* @param {ClientOptions} options The ClientOptions object containing the necessary configuration, including the rpcUrl.
* @param {('hex' | 'base64')} [format='hex'] The format of the provided wasmHash, either "hex" or "base64". Defaults to "hex".
* @returns {Promise<module:contract.Client>} A Promise that resolves to a Client instance.
* @throws {TypeError} If the provided options object does not contain an rpcUrl.
*/
static async fromWasmHash(wasmHash: Buffer | string,
Expand All @@ -76,10 +80,10 @@ export class Client {

/**
* Generates a Client instance from the provided ClientOptions and the contract's wasm binary.
*
* @param wasm The contract's wasm binary as a Buffer.
* @param options The ClientOptions object containing the necessary configuration.
* @returns A Promise that resolves to a Client instance.
*
* @param {Buffer} wasm The contract's wasm binary as a Buffer.
* @param {ClientOptions} options The ClientOptions object containing the necessary configuration.
* @returns {Promise<module:contract.Client>} A Promise that resolves to a Client instance.
* @throws {Error} If the contract spec cannot be obtained from the provided wasm binary.
*/
static async fromWasm(wasm: Buffer, options: ClientOptions): Promise<Client> {
Expand All @@ -96,9 +100,9 @@ export class Client {

/**
* Generates a Client instance from the provided ClientOptions, which must include the contractId and rpcUrl.
*
* @param options The ClientOptions object containing the necessary configuration, including the contractId and rpcUrl.
* @returns A Promise that resolves to a Client instance.
*
* @param {ClientOptions} options The ClientOptions object containing the necessary configuration, including the contractId and rpcUrl.
* @returns {Promise<module:contract.Client>} A Promise that resolves to a Client instance.
* @throws {TypeError} If the provided options object does not contain both rpcUrl and contractId.
*/
static async from(options: ClientOptions): Promise<Client> {
Expand Down
2 changes: 2 additions & 0 deletions src/contract/rust_result.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export interface ErrorMessage {
* Part of implementing {@link Result}, a minimal implementation of Rust's
* `Result` type. Used for contract methods that return Results, to maintain
* their distinction from methods that simply either return a value or throw.
* @private
*/
export class Ok<T> implements Result<T, never> {
constructor(readonly value: T) {}
Expand All @@ -77,6 +78,7 @@ export class Ok<T> implements Result<T, never> {
* Part of implementing {@link Result}, a minimal implementation of Rust's
* `Result` type. Used for contract methods that return Results, to maintain
* their distinction from methods that simply either return a value or throw.
* @private
*/
export class Err<E extends ErrorMessage> implements Result<never, E> {
constructor(readonly error: E) {}
Expand Down
16 changes: 14 additions & 2 deletions src/contract/sent_transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ import type { AssembledTransaction } from "./assembled_transaction";
* {@link MethodOptions.timeoutInSeconds} seconds. See all attempts in
* `getTransactionResponseAll` and the most recent attempt in
* `getTransactionResponse`.
*
* @memberof module:contract
* @constructor
*
* @param {function} signTransaction More info in {@link MethodOptions}
* @param {module:contract.AssembledTransaction<T>} assembled {@link AssembledTransaction} from which this SentTransaction was initialized
*/
export class SentTransaction<T> {
public server: Server;
Expand Down Expand Up @@ -61,6 +67,10 @@ export class SentTransaction<T> {
"You must provide a `signTransaction` function to send a transaction",
);
}
/**
* An RPC server that will be used to send this transaction to the network.
* @type {module:rpc.Server}
*/
this.server = new Server(this.assembled.options.rpcUrl, {
allowHttp: this.assembled.options.allowHttp ?? false,
});
Expand All @@ -72,9 +82,7 @@ export class SentTransaction<T> {
* network.
*/
static init = async <U>(
/** More info in {@link MethodOptions} */
signTransaction: ClientOptions["signTransaction"],
/** {@link AssembledTransaction} from which this SentTransaction was initialized */
assembled: AssembledTransaction<U>,
): Promise<SentTransaction<U>> => {
const tx = new SentTransaction(signTransaction, assembled);
Expand Down Expand Up @@ -103,6 +111,10 @@ export class SentTransaction<T> {
},
);

/**
* The transaction, signed by the necessary keypair(s), ready for submission to the network.
* @type {Types.Tx}
*/
this.signed = TransactionBuilder.fromXDR(
signature,
this.assembled.options.networkPassphrase,
Expand Down
Loading
Loading