Skip to content

Commit

Permalink
docs: update dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
penovicp committed Sep 5, 2024
1 parent 670a3ed commit a40e253
Show file tree
Hide file tree
Showing 83 changed files with 9,826 additions and 6,618 deletions.
4 changes: 2 additions & 2 deletions src/provider/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ export abstract class ProviderInterface {
* Get the value of the storage (contract's variable) at the given address and key
*
* @param contractAddress
* @param key - from getStorageVarAddress('<STORAGE_VARIABLE_NAME>') (WIP)
* @param key - from starknetKeccak()
* @param blockIdentifier - block identifier
* @returns the value of the storage variable
*/
Expand All @@ -147,7 +147,7 @@ export abstract class ProviderInterface {
* Gets the transaction information from a tx id.
*
* @param transactionHash
* @returns the transaction object \{ transaction_id, status, transaction, block_number?, block_number?, transaction_index?, transaction_failure_reason? \}
* @returns the transaction object `{ transaction_id, status, transaction, block_number?, block_number?, transaction_index?, transaction_failure_reason? }`
*/
public abstract getTransaction(transactionHash: BigNumberish): Promise<GetTransactionResponse>;

Expand Down
4 changes: 2 additions & 2 deletions src/utils/cairoDataTypes/uint256.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export class CairoUint256 {

/**
* Return Uint256 structure with HexString props
* {low: HexString, high: HexString}
* `{low: HexString, high: HexString}`
*/
toUint256HexString() {
return {
Expand All @@ -118,7 +118,7 @@ export class CairoUint256 {

/**
* Return Uint256 structure with DecimalString props
* {low: DecString, high: DecString}
* `{low: DecString, high: DecString}`
*/
toUint256DecimalString() {
return {
Expand Down
11 changes: 5 additions & 6 deletions src/utils/calldata/byteArray.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,12 @@ export function stringFromByteArray(myByteArray: ByteArray): string {
* @example
* ```typescript
* const myByteArray: ByteArray = byteArrayFromString("ABCDEFGHI");
* // result is: {
* // data: [],
* // pending_word: '0x414243444546474849',
* // pending_word_len: 9
* // }
* ```
* Result is :
* {
* data: [],
* pending_word: '0x414243444546474849',
* pending_word_len: 9
* }
*/
export function byteArrayFromString(targetString: string): ByteArray {
const shortStrings: string[] = splitLongString(targetString);
Expand Down
4 changes: 2 additions & 2 deletions src/utils/calldata/enum/CairoCustomEnum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ export type CairoEnumRaw = {

/**
* Class to handle Cairo custom Enum
* @param enumContent object containing the variants and its content. Example :
* {Success: 234, Warning: undefined, Error: undefined}.
* @param enumContent object containing the variants and its content. Example:
* `{Success: 234, Warning: undefined, Error: undefined}`.
* Only one variant with a value, object, array.
* @returns an instance representing a Cairo custom Enum.
* @example
Expand Down
14 changes: 5 additions & 9 deletions src/utils/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,15 +131,11 @@ export const getDefaultNodeUrl = (networkName?: NetworkName, mute: boolean = fal
export const validBlockTags = Object.values(BlockTag);

/**
* This class is formatting the identifier of a block.
*
* hex string and BigInt are detected as block hashes. identifier return { block_hash: hash }
*
* decimal string and number are detected as block numbers. identifier return { block_number: number }
*
* text string are detected as block tag. identifier return tag
*
* null is detected as 'pending' block tag. identifier return 'pending'
* This class formats the identifier of a block.
* - hex strings and BigInts are detected as block hashes. identifier return `{ block_hash: hash }`
* - decimal strings and numbers are detected as block numbers. identifier return `{ block_number: number }`
* - text strings are detected as block tag. identifier return tag
* - null is detected as 'pending' block tag. identifier return 'pending'
* @example
* ```typescript
* const result = new provider.Block(null).identifier;
Expand Down
20 changes: 11 additions & 9 deletions www/ApiTitle.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# Starknet.js API

This API is based on the <ins>[Starknet.js V3](https://github.com/starknet-io/starknet.js/discussions/102)</ins> Interface write up by <ins>[Janek](https://twitter.com/0xjanek)</ins> of <ins>[Argent](https://www.argent.xyz/)</ins>

## Provider

The Provider [**API**](./classes/Provider.md) allows you to interact with the Starknet network, without signing transactions or messages.
The Provider [**API**](./classes/Provider.md) [**API2**](./docs/API/classes/Provider.md) allows you to interact with the Starknet network, without signing transactions or messages.

Typically, these are _read_ calls on the blockchain.

Expand Down Expand Up @@ -34,18 +36,18 @@ The Signer [**API**](./classes/Signer.md) allows you to sign transactions and me

Util functions are provided so you can use various low level functions in your application:

### [elliptic curve](./namespaces/ec.md)
### [elliptic curve](./namespaces/ec/)

### [hash](./namespaces/hash.md)
### [hash](./namespaces/hash/)

### [num](./namespaces/num.md)
### [num](./namespaces/num/)

### [encode](./namespaces/encode.md)
### [encode](./namespaces/encode/)

### [merkle](./namespaces/merkle.md)
### [merkle](./namespaces/merkle/)

### [shortString](./namespaces/shortString.md)
### [shortString](./namespaces/shortString/)

### [stark](./namespaces/stark.md)
### [stark](./namespaces/stark/)

### [uint256](./namespaces/uint256.md)
### [uint256](./namespaces/uint256/)
30 changes: 15 additions & 15 deletions www/docs/guides/define_call_message.md
Original file line number Diff line number Diff line change
Expand Up @@ -538,21 +538,21 @@ const amount = res.amount;
const amount = myContract.call(...);
```

| Type in Cairo 1 | Cairo 1 code | Type expected in JS/TS | JS/TS function to recover data |
| --------------------------------------------------------- | ---------------------------------- | --------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| u8, u16, u32, usize, u64, u128, felt252, address | `func get_v()->u128` | bigint | `const res: bigint = myContract.call(...` |
| | | string representing an hex number | `const res=myContract.call(...`<br /> `const address: string = num.toHex(res);` |
| u8, u16, u32, usize | `func get_v() -> u16` | number (53 bits max) | `const res=myContract.call(...`<br /> `const total: number = Number(res)` |
| u256 (255 bits max) | `func get_v() -> u256` | bigint | `const res: bigint = myContract.call(...` |
| u512 (512 bits max) | `func get_v() -> u512` | bigint | `const res: bigint = myContract.call(...` |
| array of u8, u16, u32, usize, u64, u128, felt252, address | `func get_v() -> Array<u64>` | bigint[] | `const res: bigint[] = myContract.call(...` |
| bytes31 (31 ASCII characters max) | `func get_v() -> bytes31` | string | `const res: string = myContract.call(...` |
| felt252 (31 ASCII characters max) | `func get_v() -> felt252` | string | `const res = myContract.call(...`<br /> `const title:string = shortString.decodeShortstring(res);` |
| longString | `func get_v() -> Array<felt252>` | string | `const res=myContract.call(...`<br /> `const longString = res.map( (shortStr: bigint) => { return shortString.decodeShortString( num.toHex( shortStr)) }).join("");` |
| ByteArray | `func get_v() -> ByteArray` | string | `const res: string = myContract.call(...` |
| Tuple | `func get_v() -> (felt252, u8)` | Object {"0": bigint, "1": bigint} | `const res = myContract.call(...` <br /> `const res0: bigint = res["0"];` <br /> `const results: bigint[] = Object.values(res)` |
| Struct | ` func get_v() -> MyStruct` | MyStruct = { account: bigint, amount: bigint} | `const res: MyStruct = myContract.call(...` |
| complex array | `func get_v() -> Array<fMyStruct>` | MyStruct[] | `const res: MyStruct[] = myContract.call(...` |
| Type in Cairo 1 | Cairo 1 code | Type expected in JS/TS | JS/TS function to recover data |
| --------------------------------------------------------- | ---------------------------------- | ----------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| u8, u16, u32, usize, u64, u128, felt252, address | `func get_v()->u128` | `bigint` | `const res: bigint = myContract.call(...` |
| | | `string representing an hex number` | `const res=myContract.call(...`<br /> `const address: string = num.toHex(res);` |
| u8, u16, u32, usize | `func get_v() -> u16` | `number (53 bits max)` | `const res=myContract.call(...`<br /> `const total: number = Number(res)` |
| u256 (255 bits max) | `func get_v() -> u256` | `bigint` | `const res: bigint = myContract.call(...` |
| u512 (512 bits max) | `func get_v() -> u512` | `bigint` | `const res: bigint = myContract.call(...` |
| array of u8, u16, u32, usize, u64, u128, felt252, address | `func get_v() -> Array<u64>` | `bigint[]` | `const res: bigint[] = myContract.call(...` |
| bytes31 (31 ASCII characters max) | `func get_v() -> bytes31` | `string` | `const res: string = myContract.call(...` |
| felt252 (31 ASCII characters max) | `func get_v() -> felt252` | `string` | `const res = myContract.call(...`<br /> `const title:string = shortString.decodeShortstring(res);` |
| longString | `func get_v() -> Array<felt252>` | `string` | `const res=myContract.call(...`<br /> `const longString = res.map( (shortStr: bigint) => { return shortString.decodeShortString( num.toHex( shortStr)) }).join("");` |
| ByteArray | `func get_v() -> ByteArray` | `string` | `const res: string = myContract.call(...` |
| Tuple | `func get_v() -> (felt252, u8)` | `Object {"0": bigint, "1": bigint}` | `const res = myContract.call(...` <br /> `const res0: bigint = res["0"];` <br /> `const results: bigint[] = Object.values(res)` |
| Struct | `func get_v() -> MyStruct` | `MyStruct = { account: bigint, amount: bigint}` | `const res: MyStruct = myContract.call(...` |
| complex array | `func get_v() -> Array<fMyStruct>` | `MyStruct[]` | `const res: MyStruct[] = myContract.call(...` |

If you don't know if your Contract object is interacting with a Cairo 0 or a Cairo 1 contract, you have these methods:

Expand Down
84 changes: 50 additions & 34 deletions www/docusaurus.config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// @ts-check
// Note: type annotations allow type checking and IDEs autocompletion

const lightCodeTheme = require('prism-react-renderer/themes/github');
const darkCodeTheme = require('prism-react-renderer/themes/dracula');
const lightCodeTheme = require('prism-react-renderer').themes.github;
const darkCodeTheme = require('prism-react-renderer').themes.dracula;

const generateBaseUrl = (baseUrl = '') => `/${baseUrl.trim()}/`.replace(/\/+/g, '/');

Expand All @@ -13,6 +13,35 @@ const generateSourceLinkTemplate = (gitRevision) =>

const migrationGuideLink = `${generateBaseUrl(process.env.DOCS_BASE_URL)}docs/guides/migrate`;

/**
* @param {import('@docusaurus/plugin-content-docs/src/sidebars/types.js').SidebarItemsGeneratorArgs} args
* @param {import('@docusaurus/plugin-content-docs/src/sidebars/types.js').NormalizedSidebar} items
*/
function injectTypeDocSidebar(args, items) {
if (args.version.versionName !== 'current') return items;

return items.toReversed().map((item) => {
if (
item.type === 'category' &&
item.link?.type === 'doc' &&
item.link?.id === 'API/index' &&
item.label === 'Starknet.js API'
) {
item.label = 'API';

const groupedItems = item.items.reduce((grouped, entry) => {
// @ts-ignore
grouped[entry.label || 'globals'] = entry;
return grouped;
}, {});
const order = ['globals', 'namespaces', 'classes'];
if (order.length !== item.items.length) throw new Error('Sidebar mapping error');
item.items = order.map((x) => groupedItems[x]);
}
return item;
});
}

/** @type {import('@docusaurus/types').Config} */
const config = {
title: 'Starknet.js',
Expand All @@ -33,13 +62,18 @@ const config = {
theme: {
customCss: require.resolve('./src/css/custom.css'),
},
docs: {
async sidebarItemsGenerator({ defaultSidebarItemsGenerator, ...args }) {
return injectTypeDocSidebar(args, await defaultSidebarItemsGenerator(args));
},
},
}),
],
],

themeConfig:
/** @type {import('@docusaurus/preset-classic').ThemeConfig} */
{
({
algolia: {
// The application ID provided by Algolia
appId: '86VVNRI64B',
Expand Down Expand Up @@ -153,18 +187,17 @@ const config = {
theme: lightCodeTheme,
darkTheme: darkCodeTheme,
},
},
}),

plugins: [
[
'docusaurus-plugin-typedoc',
{
/** @type {Partial<import('typedoc').TypeDocOptions & import('docusaurus-plugin-typedoc').PluginOptions>} */
({
entryPoints: ['../src/index.ts'],
tsconfig: '../tsconfig.json',
out: 'API',
name: 'Starknet.js API',
out: 'docs/API',
includeVersion: true,
includeExtension: true,
sourceLinkTemplate: generateSourceLinkTemplate(
process.env.GIT_REVISION_OVERRIDE || 'develop'
),
Expand All @@ -173,33 +206,16 @@ const config = {
private: false,
},
sort: ['kind'],
kindSortOrder: [
'Reference',
'Project',
'Module',
'Class',
'Namespace',
'Enum',
'EnumMember',
'Interface',
'TypeAlias',
'Constructor',
'Property',
'Variable',
'Function',
'Accessor',
'Method',
'Parameter',
'TypeParameter',
'TypeLiteral',
'CallSignature',
'ConstructorSignature',
'IndexSignature',
'GetSignature',
'SetSignature',
],
sidebar: {
autoConfiguration: true,
},
readme: './ApiTitle.md',
},
parametersFormat: 'table',
interfacePropertiesFormat: 'table',
enumMembersFormat: 'table',
typeDeclarationFormat: 'table',
membersWithOwnFile: ['Class', 'Enum', 'Interface'],
}),
],
],
};
Expand Down
Loading

0 comments on commit a40e253

Please sign in to comment.