Add metadata constants to scripts/MetadataMd (#1131)
* Add metadata constants to scripts/MetadataMd * Use name instead of prefix for Extrinsics Since the js api uses the name and not the prefix (api.tx.name.xx) and finality_tracker doesn't have a prefix * Lint
This commit is contained in:
@@ -12,6 +12,8 @@ The API wrappers provide a standard interface for use -
|
||||
- [Storage chain state (runtime node interface)](../METHODS_STORAGE.md)
|
||||
- `api.tx.<section>.<method>` provides the ability to create a transaction, like chain state, this list is populated from a runtime query
|
||||
- [Extrinsics (runtime node interface)](../METHODS_EXTRINSICS.md)
|
||||
- `api.consts.<section>.<constant>` provides access to the module constants (parameter types).
|
||||
- [Constants (runtime node interface)](../METHODS_CONSTANTS.md)
|
||||
|
||||
## API Selection
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ import MetadataV6, { ModuleMetadataV6 } from '../Metadata/v6';
|
||||
const ANCHOR_TOP = '';
|
||||
const LINK_BACK_TO_TOP = '';
|
||||
|
||||
const DESC_CONSTANTS = '\n\n_The following sections contain the module constants, also known as parameter types.\n';
|
||||
const DESC_EXTRINSICS = '\n\n_The following sections contain Extrinsics methods are part of the default Substrate runtime._\n';
|
||||
const DESC_EVENTS = '\n\nEvents are emitted for certain operations on the runtime. The following sections describe the events that are part of the default Substrate runtime.\n';
|
||||
const DESC_RPC = '\n\n_The following sections contain RPC methods that are Remote Calls available by default and allow you to interact with the actual node, query, and submit. The RPCs are provided by Substrate itself._';
|
||||
@@ -67,6 +68,36 @@ function sortByName<T extends { name: any }> (a: T, b: T): number {
|
||||
return nameA.localeCompare(nameB);
|
||||
}
|
||||
|
||||
function addConstants (metadata: MetadataV6): string {
|
||||
const renderHeading = `## ${ANCHOR_TOP}Constants${DESC_CONSTANTS}`;
|
||||
const orderedSections = metadata.modules.sort(sortByName);
|
||||
let renderAnchors = '';
|
||||
const sections = orderedSections.reduce((md, moduleMetadata): string => {
|
||||
if (moduleMetadata.constants.isEmpty) {
|
||||
return md;
|
||||
}
|
||||
|
||||
const sectionName = stringLowerFirst(moduleMetadata.name.toString());
|
||||
|
||||
renderAnchors += sectionLink(sectionName);
|
||||
|
||||
const renderSection = generateSectionHeader(md, sectionName);
|
||||
const orderedConstants = moduleMetadata.constants.sort(sortByName);
|
||||
|
||||
return orderedConstants.reduce((md, func): string => {
|
||||
const methodName = stringLowerFirst(func.name.toString());
|
||||
const doc = func.documentation.reduce((md, doc): string => `${md} ${doc}`, '');
|
||||
const type = func.type;
|
||||
const renderSignature = `${md}\n▸ **${methodName}**: ` + '`' + type + '`';
|
||||
const renderSummary = `${doc ? `\n- **summary**: ${doc}\n` : '\n'}`;
|
||||
|
||||
return renderSignature + renderSummary;
|
||||
}, renderSection);
|
||||
}, '');
|
||||
|
||||
return renderHeading + renderAnchors + sections;
|
||||
}
|
||||
|
||||
function addEvents (metadata: MetadataV6): string {
|
||||
const renderHeading = `## ${ANCHOR_TOP}Events${DESC_EVENTS}`;
|
||||
const orderedSections = metadata.modules.sort(sortByName);
|
||||
@@ -108,7 +139,7 @@ function addExtrinsics (metadata: MetadataV6): string {
|
||||
}
|
||||
|
||||
const calls = meta.calls.unwrap();
|
||||
const sectionName = stringCamelCase(meta.prefix.toString());
|
||||
const sectionName = stringCamelCase(meta.name.toString());
|
||||
|
||||
renderAnchors += sectionLink(sectionName);
|
||||
|
||||
@@ -181,6 +212,10 @@ function writeToRpcMd (): void {
|
||||
writeFile('docs/METHODS_RPC.md', addRpc());
|
||||
}
|
||||
|
||||
function writeToConstantsMd (metadata: MetadataV6): void {
|
||||
writeFile('docs/METHODS_CONSTANTS.md', addConstants(metadata));
|
||||
}
|
||||
|
||||
function writeToStorageMd (metadata: MetadataV6): void {
|
||||
const options = { flags: 'r', encoding: 'utf8' };
|
||||
const data = fs.readFileSync('packages/types/src/scripts/METHODS_STORAGE_SUBSTRATE.md', options);
|
||||
@@ -199,6 +234,7 @@ function writeToEventsMd (metadata: MetadataV6): void {
|
||||
const metadata = new Metadata(rpcdata).asV6;
|
||||
|
||||
writeToRpcMd();
|
||||
writeToConstantsMd(metadata);
|
||||
writeToStorageMd(metadata);
|
||||
writeToExtrinsicsMd(metadata);
|
||||
writeToEventsMd(metadata);
|
||||
|
||||
Reference in New Issue
Block a user