fix: Fixes #288. Alphabetical ordering for Sections and Methods of RPC, Storage, and Extrinsics (#291)
* fix: Manual alphabetical ordering for Storage Substrate methods * fix: Fixes #288. Alphabetical ordering for Sections and Methds of RPC, Storage, Extrinsics * refactor: Move alphabetical sorting of Methods in Extrinsics Section into separate function * refactor: Use localeCompare to sort more concisely
This commit is contained in:
@@ -5,22 +5,22 @@
|
||||
|
||||
_These are keys that are always available to the runtime implementation_
|
||||
|
||||
▸ **code**(): `Bytes`
|
||||
- **summary**: Wasm code of the runtime.
|
||||
|
||||
▸ **heapPages**(): `u64`
|
||||
- **summary**: Number of wasm linear memory pages required for execution of the runtime.
|
||||
|
||||
▸ **authorityCount**(): `u32`
|
||||
- **summary**: Number of authorities.
|
||||
|
||||
▸ **authorityPrefix**(): `u32`
|
||||
- **summary**: Prefix under which authorities are storied.
|
||||
|
||||
▸ **extrinsicIndex**(): `u32`
|
||||
- **summary**: Current extrinsic index (u32) is stored under this key.
|
||||
|
||||
▸ **changesTrieConfig**(): `u32`
|
||||
- **summary**: Changes trie configuration is stored under this key.
|
||||
|
||||
▸ **code**(): `Bytes`
|
||||
- **summary**: Wasm code of the runtime.
|
||||
|
||||
▸ **extrinsicIndex**(): `u32`
|
||||
- **summary**: Current extrinsic index (u32) is stored under this key.
|
||||
|
||||
▸ **heapPages**(): `u64`
|
||||
- **summary**: Number of wasm linear memory pages required for execution of the runtime.
|
||||
|
||||
---
|
||||
|
||||
@@ -50,13 +50,15 @@ function generateSectionHeader (md: string, sectionName: string) {
|
||||
|
||||
function addRpc () {
|
||||
const renderHeading = `## ${ANCHOR_TOP}JSON-RPC${DESC_RPC}\n`;
|
||||
const orderedSections = Object.keys(interfaces).sort();
|
||||
const renderAnchors = generateSectionLinks('rpc');
|
||||
|
||||
return Object.keys(interfaces).reduce((md, sectionName) => {
|
||||
return orderedSections.reduce((md, sectionName) => {
|
||||
const section = interfaces[sectionName];
|
||||
const renderSection = generateSectionHeader(md, sectionName) + `\n_${section.description}_\n`;
|
||||
const orderedMethods = Object.keys(section.methods).sort();
|
||||
|
||||
return Object.keys(section.methods).reduce((md, methodName) => {
|
||||
return orderedMethods.reduce((md, methodName) => {
|
||||
const method = section.methods[methodName];
|
||||
const args = method.params.map(({ name, isOptional, type }) => {
|
||||
return name + (isOptional ? '?' : '') + ': `' + type + '`';
|
||||
@@ -74,11 +76,22 @@ function addRpc () {
|
||||
}, renderHeading + renderAnchors);
|
||||
}
|
||||
|
||||
function sortExtrinsicsSectionMethods () {
|
||||
return function (a: any, b: any) {
|
||||
// ignore upper and lowercase
|
||||
const nameA = a.raw.name.raw.toUpperCase();
|
||||
const nameB = b.raw.name.raw.toUpperCase();
|
||||
|
||||
return nameA.localeCompare(nameB);
|
||||
};
|
||||
}
|
||||
|
||||
function addExtrinsics (metadata: any) {
|
||||
const renderHeading = `## ${ANCHOR_TOP}Extrinsics${DESC_EXTRINSICS}`;
|
||||
const orderedSections = metadata.modules.raw.sort();
|
||||
const renderAnchors = generateSectionLinks('extrinsics', metadata);
|
||||
|
||||
return metadata.modules.reduce((md: string, meta: any) => {
|
||||
return orderedSections.reduce((md: string, meta: any) => {
|
||||
if (!meta.module.call || !meta.module.call.functions.length) {
|
||||
return md;
|
||||
}
|
||||
@@ -86,7 +99,10 @@ function addExtrinsics (metadata: any) {
|
||||
const sectionName = stringCamelCase(meta.prefix.toString());
|
||||
const renderSection = generateSectionHeader(md, sectionName);
|
||||
|
||||
return meta.module.call.functions.reduce((md: string, func: any) => {
|
||||
// Sort methods by name. Reference: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort
|
||||
const orderedMethods = meta.module.call.functions.raw.sort(sortExtrinsicsSectionMethods());
|
||||
|
||||
return orderedMethods.reduce((md: string, func: any) => {
|
||||
const methodName = stringCamelCase(func.name.toString());
|
||||
const args = Method.filterOrigin(func).map(({ name, type }) => `${name}: ` + '`' + type + '`').join(', ');
|
||||
const doc = func.documentation.reduce((md: string, doc: string) => `${md} ${doc}`, '');
|
||||
@@ -100,17 +116,19 @@ function addExtrinsics (metadata: any) {
|
||||
|
||||
function addStorage (metadata: any) {
|
||||
const renderHeading = `## ${ANCHOR_TOP}Storage${DESC_STORAGE}`;
|
||||
const orderedSections = metadata.modules.raw.sort();
|
||||
const renderAnchors = generateSectionLinks('storage', metadata);
|
||||
|
||||
return metadata.modules.reduce((md: string, moduleMetadata: any) => {
|
||||
return orderedSections.reduce((md: string, moduleMetadata: any) => {
|
||||
if (!moduleMetadata.storage) {
|
||||
return md;
|
||||
}
|
||||
|
||||
const sectionName = stringLowerFirst(moduleMetadata.storage.prefix.toString());
|
||||
const renderSection = generateSectionHeader(md, sectionName);
|
||||
const orderedMethods = moduleMetadata.storage.functions.raw.sort();
|
||||
|
||||
return moduleMetadata.storage.functions.reduce((md: string, func: any) => {
|
||||
return orderedMethods.reduce((md: string, func: any) => {
|
||||
const methodName = stringLowerFirst(func.name.toString());
|
||||
const arg = func.type.isMap ? ('`' + func.type.asMap.key.toString() + '`') : '';
|
||||
const doc = func.documentation.reduce((md: string, doc: string) => `${md} ${doc}`, '');
|
||||
|
||||
Reference in New Issue
Block a user