@pezkuwi/typegen 16.5.5 → 16.5.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (193) hide show
  1. package/LICENSE +201 -0
  2. package/augment.js +2 -0
  3. package/bundle.js +2 -0
  4. package/cjs/augment.d.ts +2 -0
  5. package/cjs/augment.js +4 -0
  6. package/cjs/bundle.d.ts +2 -0
  7. package/cjs/bundle.js +7 -0
  8. package/cjs/extractChain.js +44 -0
  9. package/cjs/fromChain.js +95 -0
  10. package/cjs/fromDefs.js +82 -0
  11. package/cjs/generate/consts.js +91 -0
  12. package/cjs/generate/errors.js +59 -0
  13. package/cjs/generate/events.js +139 -0
  14. package/cjs/generate/index.js +23 -0
  15. package/cjs/generate/interfaceRegistry.js +64 -0
  16. package/cjs/generate/lookup.js +240 -0
  17. package/cjs/generate/query.js +140 -0
  18. package/cjs/generate/rpc.js +115 -0
  19. package/cjs/generate/runtime.js +233 -0
  20. package/{build → cjs}/generate/tsDef.d.ts +1 -1
  21. package/cjs/generate/tsDef.js +254 -0
  22. package/cjs/generate/tx.js +121 -0
  23. package/cjs/generate/types.js +16 -0
  24. package/cjs/index.js +5 -0
  25. package/cjs/interfacesTs.js +28 -0
  26. package/cjs/metadataMd.js +652 -0
  27. package/cjs/package.json +3 -0
  28. package/cjs/packageDetect.js +8 -0
  29. package/cjs/packageInfo.js +4 -0
  30. package/cjs/util/assert.js +15 -0
  31. package/cjs/util/derived.js +128 -0
  32. package/cjs/util/docs.js +10 -0
  33. package/cjs/util/file.js +33 -0
  34. package/{build → cjs}/util/formatting.d.ts +1 -1
  35. package/cjs/util/formatting.js +237 -0
  36. package/cjs/util/imports.js +126 -0
  37. package/{build → cjs}/util/index.d.ts +1 -0
  38. package/cjs/util/index.js +39 -0
  39. package/cjs/util/initMeta.js +22 -0
  40. package/cjs/util/register.js +10 -0
  41. package/cjs/util/wsMeta.js +60 -0
  42. package/extractChain.d.ts +1 -0
  43. package/extractChain.js +40 -0
  44. package/fromChain.d.ts +1 -0
  45. package/fromChain.js +91 -0
  46. package/fromDefs.d.ts +1 -0
  47. package/fromDefs.js +78 -0
  48. package/generate/consts.d.ts +5 -0
  49. package/generate/consts.js +87 -0
  50. package/generate/errors.d.ts +4 -0
  51. package/generate/errors.js +55 -0
  52. package/generate/events.d.ts +5 -0
  53. package/generate/events.js +135 -0
  54. package/{src/generate/index.ts → generate/index.d.ts} +0 -3
  55. package/generate/index.js +10 -0
  56. package/generate/interfaceRegistry.d.ts +4 -0
  57. package/generate/interfaceRegistry.js +59 -0
  58. package/generate/lookup.d.ts +4 -0
  59. package/generate/lookup.js +235 -0
  60. package/generate/query.d.ts +5 -0
  61. package/generate/query.js +136 -0
  62. package/generate/rpc.d.ts +6 -0
  63. package/generate/rpc.js +110 -0
  64. package/generate/runtime.d.ts +7 -0
  65. package/generate/runtime.js +228 -0
  66. package/generate/tsDef.d.ts +16 -0
  67. package/generate/tsDef.js +246 -0
  68. package/generate/tx.d.ts +5 -0
  69. package/generate/tx.js +117 -0
  70. package/generate/types.d.ts +12 -0
  71. package/generate/types.js +13 -0
  72. package/index.d.ts +2 -0
  73. package/index.js +2 -0
  74. package/interfacesTs.d.ts +1 -0
  75. package/interfacesTs.js +24 -0
  76. package/metadataMd.d.ts +1 -0
  77. package/metadataMd.js +648 -0
  78. package/package.json +520 -24
  79. package/packageDetect.d.ts +1 -0
  80. package/{src/packageDetect.ts → packageDetect.js} +0 -8
  81. package/packageInfo.d.ts +6 -0
  82. package/packageInfo.js +1 -0
  83. package/scripts/{polkadot-types-chain-info.mjs → pezkuwi-types-chain-info.mjs} +1 -1
  84. package/scripts/{polkadot-types-from-chain.mjs → pezkuwi-types-from-chain.mjs} +1 -1
  85. package/scripts/{polkadot-types-from-defs.mjs → pezkuwi-types-from-defs.mjs} +1 -1
  86. package/{build/scripts/polkadot-types-internal-interfaces.mjs → scripts/pezkuwi-types-internal-interfaces.mjs} +1 -1
  87. package/{build/scripts/polkadot-types-internal-metadata.mjs → scripts/pezkuwi-types-internal-metadata.mjs} +1 -1
  88. package/{src/templates → templates}/calls.hbs +2 -2
  89. package/{src/templates → templates}/consts.hbs +2 -2
  90. package/{src/templates → templates}/errors.hbs +2 -2
  91. package/{src/templates → templates}/events.hbs +2 -2
  92. package/{src/templates → templates}/interfaceRegistry.hbs +2 -2
  93. package/{src/templates → templates}/lookup/types.hbs +2 -2
  94. package/{src/templates → templates}/query.hbs +2 -2
  95. package/{src/templates → templates}/rpc.hbs +2 -2
  96. package/{src/templates → templates}/tx.hbs +2 -2
  97. package/util/assert.d.ts +2 -0
  98. package/util/assert.js +10 -0
  99. package/util/derived.d.ts +4 -0
  100. package/util/derived.js +125 -0
  101. package/util/docs.d.ts +1 -0
  102. package/util/docs.js +6 -0
  103. package/util/file.d.ts +2 -0
  104. package/util/file.js +28 -0
  105. package/util/formatting.d.ts +11 -0
  106. package/util/formatting.js +230 -0
  107. package/util/imports.d.ts +23 -0
  108. package/util/imports.js +121 -0
  109. package/{src/util/index.ts → util/index.d.ts} +6 -8
  110. package/util/index.js +34 -0
  111. package/util/initMeta.d.ts +12 -0
  112. package/util/initMeta.js +19 -0
  113. package/util/register.d.ts +4 -0
  114. package/util/register.js +7 -0
  115. package/util/wsMeta.d.ts +4 -0
  116. package/util/wsMeta.js +55 -0
  117. package/build/scripts/polkadot-types-chain-info.mjs +0 -7
  118. package/build/scripts/polkadot-types-from-chain.mjs +0 -7
  119. package/build/scripts/polkadot-types-from-defs.mjs +0 -7
  120. package/scripts/polkadot-types-internal-interfaces.mjs +0 -7
  121. package/scripts/polkadot-types-internal-metadata.mjs +0 -7
  122. package/src/augment.ts +0 -5
  123. package/src/bundle.ts +0 -5
  124. package/src/extractChain.ts +0 -54
  125. package/src/fromChain.ts +0 -123
  126. package/src/fromDefs.ts +0 -106
  127. package/src/generate/consts.ts +0 -112
  128. package/src/generate/errors.ts +0 -75
  129. package/src/generate/events.ts +0 -165
  130. package/src/generate/interfaceRegistry.ts +0 -85
  131. package/src/generate/lookup.ts +0 -294
  132. package/src/generate/query.ts +0 -169
  133. package/src/generate/rpc.ts +0 -158
  134. package/src/generate/runtime.ts +0 -284
  135. package/src/generate/tsDef.ts +0 -321
  136. package/src/generate/tx.ts +0 -152
  137. package/src/generate/types.ts +0 -26
  138. package/src/index.ts +0 -6
  139. package/src/interfacesTs.ts +0 -35
  140. package/src/metadataMd.ts +0 -844
  141. package/src/packageInfo.ts +0 -6
  142. package/src/util/assert.ts +0 -18
  143. package/src/util/derived.spec.ts +0 -58
  144. package/src/util/derived.ts +0 -133
  145. package/src/util/docs.ts +0 -13
  146. package/src/util/file.ts +0 -42
  147. package/src/util/formatting.spec.ts +0 -30
  148. package/src/util/formatting.ts +0 -295
  149. package/src/util/imports.ts +0 -164
  150. package/src/util/initMeta.ts +0 -37
  151. package/src/util/register.ts +0 -12
  152. package/src/util/wsMeta.ts +0 -70
  153. package/tsconfig.build.json +0 -28
  154. package/tsconfig.build.tsbuildinfo +0 -1
  155. package/tsconfig.scripts.json +0 -19
  156. package/tsconfig.spec.json +0 -17
  157. /package/{build/augment.d.ts → augment.d.ts} +0 -0
  158. /package/{build/bundle.d.ts → bundle.d.ts} +0 -0
  159. /package/{build → cjs}/extractChain.d.ts +0 -0
  160. /package/{build → cjs}/fromChain.d.ts +0 -0
  161. /package/{build → cjs}/fromDefs.d.ts +0 -0
  162. /package/{build → cjs}/generate/consts.d.ts +0 -0
  163. /package/{build → cjs}/generate/errors.d.ts +0 -0
  164. /package/{build → cjs}/generate/events.d.ts +0 -0
  165. /package/{build → cjs}/generate/index.d.ts +0 -0
  166. /package/{build → cjs}/generate/interfaceRegistry.d.ts +0 -0
  167. /package/{build → cjs}/generate/lookup.d.ts +0 -0
  168. /package/{build → cjs}/generate/query.d.ts +0 -0
  169. /package/{build → cjs}/generate/rpc.d.ts +0 -0
  170. /package/{build → cjs}/generate/runtime.d.ts +0 -0
  171. /package/{build → cjs}/generate/tx.d.ts +0 -0
  172. /package/{build → cjs}/generate/types.d.ts +0 -0
  173. /package/{build → cjs}/index.d.ts +0 -0
  174. /package/{build → cjs}/interfacesTs.d.ts +0 -0
  175. /package/{build → cjs}/metadataMd.d.ts +0 -0
  176. /package/{build → cjs}/packageDetect.d.ts +0 -0
  177. /package/{build → cjs}/packageInfo.d.ts +0 -0
  178. /package/{build → cjs}/util/assert.d.ts +0 -0
  179. /package/{build → cjs}/util/derived.d.ts +0 -0
  180. /package/{build → cjs}/util/docs.d.ts +0 -0
  181. /package/{build → cjs}/util/file.d.ts +0 -0
  182. /package/{build → cjs}/util/imports.d.ts +0 -0
  183. /package/{build → cjs}/util/initMeta.d.ts +0 -0
  184. /package/{build → cjs}/util/register.d.ts +0 -0
  185. /package/{build → cjs}/util/wsMeta.d.ts +0 -0
  186. /package/{src/templates → templates}/docs.hbs +0 -0
  187. /package/{src/templates → templates}/header.hbs +0 -0
  188. /package/{src/templates → templates}/lookup/defs-named.hbs +0 -0
  189. /package/{src/templates → templates}/lookup/defs.hbs +0 -0
  190. /package/{src/templates → templates}/lookup/index.hbs +0 -0
  191. /package/{src/templates → templates}/tsDef/index.hbs +0 -0
  192. /package/{src/templates → templates}/tsDef/moduleTypes.hbs +0 -0
  193. /package/{src/templates → templates}/tsDef/types.hbs +0 -0
@@ -0,0 +1,652 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.main = main;
4
+ const tslib_1 = require("tslib");
5
+ const comment_parser_1 = require("comment-parser");
6
+ const node_fs_1 = tslib_1.__importDefault(require("node:fs"));
7
+ const node_path_1 = tslib_1.__importStar(require("node:path"));
8
+ const node_process_1 = tslib_1.__importDefault(require("node:process"));
9
+ const node_url_1 = require("node:url");
10
+ const yargs_1 = tslib_1.__importDefault(require("yargs"));
11
+ const helpers_1 = require("yargs/helpers");
12
+ const api_derive_1 = require("@pezkuwi/api-derive");
13
+ const types_1 = require("@pezkuwi/types");
14
+ const definitions = tslib_1.__importStar(require("@pezkuwi/types/interfaces/definitions"));
15
+ const getStorage_1 = require("@pezkuwi/types/metadata/decorate/storage/getStorage");
16
+ const util_1 = require("@pezkuwi/types/util");
17
+ const asset_hub_dicle_hex_1 = tslib_1.__importDefault(require("@pezkuwi/types-support/metadata/v15/asset-hub-dicle-hex"));
18
+ const asset_hub_dicle_rpc_1 = tslib_1.__importDefault(require("@pezkuwi/types-support/metadata/v15/asset-hub-dicle-rpc"));
19
+ const asset_hub_dicle_ver_1 = tslib_1.__importDefault(require("@pezkuwi/types-support/metadata/v15/asset-hub-dicle-ver"));
20
+ const asset_hub_pezkuwi_hex_1 = tslib_1.__importDefault(require("@pezkuwi/types-support/metadata/v15/asset-hub-pezkuwi-hex"));
21
+ const asset_hub_pezkuwi_rpc_1 = tslib_1.__importDefault(require("@pezkuwi/types-support/metadata/v15/asset-hub-pezkuwi-rpc"));
22
+ const asset_hub_pezkuwi_ver_1 = tslib_1.__importDefault(require("@pezkuwi/types-support/metadata/v15/asset-hub-pezkuwi-ver"));
23
+ const dicle_hex_1 = tslib_1.__importDefault(require("@pezkuwi/types-support/metadata/v15/dicle-hex"));
24
+ const dicle_rpc_1 = tslib_1.__importDefault(require("@pezkuwi/types-support/metadata/v15/dicle-rpc"));
25
+ const dicle_ver_1 = tslib_1.__importDefault(require("@pezkuwi/types-support/metadata/v15/dicle-ver"));
26
+ const pezkuwi_hex_1 = tslib_1.__importDefault(require("@pezkuwi/types-support/metadata/v15/pezkuwi-hex"));
27
+ const pezkuwi_rpc_1 = tslib_1.__importDefault(require("@pezkuwi/types-support/metadata/v15/pezkuwi-rpc"));
28
+ const pezkuwi_ver_1 = tslib_1.__importDefault(require("@pezkuwi/types-support/metadata/v15/pezkuwi-ver"));
29
+ const bizinikiwi_hex_1 = tslib_1.__importDefault(require("@pezkuwi/types-support/metadata/v15/bizinikiwi-hex"));
30
+ const util_2 = require("@pezkuwi/util");
31
+ const util_crypto_1 = require("@pezkuwi/util-crypto");
32
+ const index_js_1 = require("./util/index.js");
33
+ const headerFn = (runtimeDesc) => `\n\n(NOTE: These were generated from a static/snapshot view of a recent ${runtimeDesc}. Some items may not be available in older nodes, or in any customized implementations.)`;
34
+ const ALL_STATIC = {
35
+ 'asset-hub-dicle': {
36
+ meta: asset_hub_dicle_hex_1.default,
37
+ rpc: asset_hub_dicle_rpc_1.default,
38
+ ver: asset_hub_dicle_ver_1.default
39
+ },
40
+ 'asset-hub-pezkuwi': {
41
+ meta: asset_hub_pezkuwi_hex_1.default,
42
+ rpc: asset_hub_pezkuwi_rpc_1.default,
43
+ ver: asset_hub_pezkuwi_ver_1.default
44
+ },
45
+ dicle: {
46
+ meta: dicle_hex_1.default,
47
+ rpc: dicle_rpc_1.default,
48
+ ver: dicle_ver_1.default
49
+ },
50
+ pezkuwi: {
51
+ meta: pezkuwi_hex_1.default,
52
+ rpc: pezkuwi_rpc_1.default,
53
+ ver: pezkuwi_ver_1.default
54
+ },
55
+ bizinikiwi: {
56
+ meta: bizinikiwi_hex_1.default
57
+ }
58
+ };
59
+ /** @internal */
60
+ function docsVecToMarkdown(docLines, indent = 0) {
61
+ const md = docLines
62
+ .map((docLine) => docLine
63
+ .toString()
64
+ .trimStart()
65
+ .replace(/^r"/g, '')
66
+ .trimStart())
67
+ .reduce((md, docLine) => // generate paragraphs
68
+ !docLine.length
69
+ ? `${md}\n\n` // empty line
70
+ : /^[*-]/.test(docLine.trimStart()) && !md.endsWith('\n\n')
71
+ ? `${md}\n\n${docLine}` // line calling for a preceding linebreak
72
+ : `${md} ${docLine.replace(/^#{1,3} /, '#### ')} `, '')
73
+ .replace(/#### <weight>/g, '<weight>')
74
+ .replace(/<weight>(.|\n)*?<\/weight>/g, '')
75
+ .replace(/#### Weight:/g, 'Weight:');
76
+ // prefix each line with indentation
77
+ return md?.split('\n\n').map((line) => `${' '.repeat(indent)}${line}`).join('\n\n');
78
+ }
79
+ function renderPage(page) {
80
+ let md = `---\ntitle: ${page.title}\n---\n\n`;
81
+ if (page.description) {
82
+ md += `${page.description}\n\n`;
83
+ }
84
+ // index
85
+ page.sections.forEach((section) => {
86
+ md += `- **[${(0, util_2.stringCamelCase)(section.name)}](#${(0, util_2.stringCamelCase)(section.name).toLowerCase()})**\n\n`;
87
+ });
88
+ // contents
89
+ page.sections.forEach((section) => {
90
+ md += '\n___\n\n\n';
91
+ md += section.link
92
+ ? `<h2 id="#${section.link}">${section.name}</h2>\n`
93
+ : `## ${section.name}\n`;
94
+ if (section.description) {
95
+ md += `\n_${section.description}_\n`;
96
+ }
97
+ section.items.forEach((item) => {
98
+ md += ' \n';
99
+ md += item.link
100
+ ? `<h3 id="#${item.link}">${item.name}</h3>`
101
+ : `### ${item.name}`;
102
+ Object
103
+ .keys(item)
104
+ .filter((key) => !['link', 'name'].includes(key))
105
+ .forEach((bullet) => {
106
+ md += `\n- **${bullet}**: ${
107
+ // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
108
+ item[bullet] instanceof types_1.Vec
109
+ ? docsVecToMarkdown(item[bullet], 2).toString()
110
+ : item[bullet]}`;
111
+ });
112
+ md += '\n';
113
+ });
114
+ });
115
+ return md;
116
+ }
117
+ function sortByName(a, b) {
118
+ // case insensitive (all-uppercase) sorting
119
+ return a.name.toString().toUpperCase().localeCompare(b.name.toString().toUpperCase());
120
+ }
121
+ function getSiName(lookup, type) {
122
+ const typeDef = lookup.getTypeDef(type);
123
+ return typeDef.lookupName || typeDef.type;
124
+ }
125
+ /** @internal */
126
+ function addRpc(_runtimeDesc, rpcMethods) {
127
+ return renderPage({
128
+ description: 'The following sections contain known RPC methods that may be available on specific nodes (depending on configuration and available pallets) and allow you to interact with the actual node, query, and submit.',
129
+ sections: Object
130
+ .keys(definitions)
131
+ .filter((key) => Object.keys(definitions[key].rpc || {}).length !== 0)
132
+ .sort()
133
+ .reduce((all, _sectionName) => {
134
+ const section = definitions[_sectionName];
135
+ Object
136
+ .keys(section.rpc || {})
137
+ .sort()
138
+ .forEach((methodName) => {
139
+ const method = section.rpc?.[methodName];
140
+ if (!method) {
141
+ throw new Error(`No ${methodName} RPC found in ${_sectionName}`);
142
+ }
143
+ const sectionName = method.aliasSection || _sectionName;
144
+ const jsonrpc = (method.endpoint || `${sectionName}_${methodName}`);
145
+ if (rpcMethods) {
146
+ // if we are passing the rpcMethods params and we cannot find this method, skip it
147
+ if (jsonrpc !== 'rpc_methods' && !rpcMethods.includes(jsonrpc)) {
148
+ return;
149
+ }
150
+ }
151
+ const topName = method.aliasSection ? `${_sectionName}/${method.aliasSection}` : _sectionName;
152
+ let container = all.find(({ name }) => name === topName);
153
+ if (!container) {
154
+ container = { items: [], name: topName };
155
+ all.push(container);
156
+ }
157
+ const args = method.params.map(({ isOptional, name, type }) => {
158
+ // eslint-disable-next-line @typescript-eslint/restrict-plus-operands
159
+ return name + (isOptional ? '?' : '') + ': `' + type + '`';
160
+ }).join(', ');
161
+ const type = '`' + method.type + '`';
162
+ container.items.push({
163
+ interface: '`' + `api.rpc.${sectionName}.${methodName}` + '`',
164
+ jsonrpc: '`' + jsonrpc + '`',
165
+ // link: jsonrpc,
166
+ name: `${methodName}(${args}): ${type}`,
167
+ ...((method.description && { summary: method.description }) || {}),
168
+ ...((method.deprecated && { deprecated: method.deprecated }) || {}),
169
+ ...((method.isUnsafe && { unsafe: 'This method is only active with appropriate flags' }) || {})
170
+ });
171
+ });
172
+ return all;
173
+ }, []).sort(sortByName),
174
+ title: 'JSON-RPC'
175
+ });
176
+ }
177
+ /** @internal */
178
+ function getMethods(registry, methods) {
179
+ const result = {};
180
+ methods.forEach((m) => {
181
+ const { docs, inputs, name, output } = m;
182
+ result[name.toString()] = {
183
+ description: docs.map((d) => d.toString()).join(),
184
+ params: inputs.map(({ name, type }) => {
185
+ return { name: name.toString(), type: registry.lookup.getName(type) || registry.lookup.getTypeDef(type).type };
186
+ }),
187
+ type: registry.lookup.getName(output) || registry.lookup.getTypeDef(output).type
188
+ };
189
+ });
190
+ return result;
191
+ }
192
+ /** @internal */
193
+ function getRuntimeDefViaMetadata(registry) {
194
+ const result = {};
195
+ const { apis } = registry.metadata;
196
+ for (let i = 0, count = apis.length; i < count; i++) {
197
+ const { methods, name } = apis[i];
198
+ result[name.toString()] = [{
199
+ methods: getMethods(registry, methods),
200
+ // We set the version to 0 here since it will not be relevant when we are grabbing the runtime apis
201
+ // from the Metadata.
202
+ version: 0
203
+ }];
204
+ }
205
+ return Object.entries(result);
206
+ }
207
+ function runtimeSections(registry) {
208
+ const sections = getRuntimeDefViaMetadata(registry);
209
+ const all = [];
210
+ for (let j = 0, jcount = sections.length; j < jcount; j++) {
211
+ const [_section, secs] = sections[j];
212
+ const sec = secs[0];
213
+ const section = (0, util_2.stringCamelCase)(_section);
214
+ const methods = Object.entries(sec.methods);
215
+ const container = { items: [], name: section };
216
+ all.push(container);
217
+ methods
218
+ .sort(([a], [b]) => a.localeCompare(b))
219
+ .forEach(([methodName, { description, params, type }]) => {
220
+ const args = params.map(({ name, type }) => {
221
+ // eslint-disable-next-line @typescript-eslint/restrict-plus-operands
222
+ return name + ': `' + type + '`';
223
+ }).join(', ');
224
+ container.items.push({
225
+ interface: '`' + `api.call.${(0, util_2.stringCamelCase)(section)}.${(0, util_2.stringCamelCase)(methodName)}` + '`',
226
+ name: `${(0, util_2.stringCamelCase)(methodName)}(${args}): ${'`' + type + '`'}`,
227
+ runtime: '`' + `${section}_${methodName}` + '`',
228
+ summary: description
229
+ });
230
+ });
231
+ }
232
+ return all.sort(sortByName);
233
+ }
234
+ /** @internal */
235
+ function addRuntime(_runtimeDesc, registry) {
236
+ return renderPage({
237
+ description: 'The following section contains known runtime calls that may be available on specific runtimes (depending on configuration and available pallets). These call directly into the WASM runtime for queries and operations.',
238
+ sections: runtimeSections(registry),
239
+ title: 'Runtime'
240
+ });
241
+ }
242
+ /** @internal */
243
+ function addLegacyRuntime(_runtimeDesc, _registry, apis) {
244
+ return renderPage({
245
+ description: 'The following section contains known runtime calls that may be available on specific runtimes (depending on configuration and available pallets). These call directly into the WASM runtime for queries and operations.',
246
+ sections: Object
247
+ .keys(definitions)
248
+ .filter((key) => Object.keys(definitions[key].runtime || {}).length !== 0)
249
+ .sort()
250
+ .reduce((all, _sectionName) => {
251
+ Object
252
+ .entries(definitions[_sectionName].runtime || {})
253
+ .forEach(([apiName, versions]) => {
254
+ versions
255
+ .sort((a, b) => b.version - a.version)
256
+ .forEach(({ methods, version }, index) => {
257
+ if (apis) {
258
+ // if we are passing the api hashes and we cannot find this one, skip it
259
+ const apiHash = (0, util_crypto_1.blake2AsHex)(apiName, 64);
260
+ const api = apis.find(([hash]) => hash === apiHash);
261
+ if (!api || api[1] !== version) {
262
+ return;
263
+ }
264
+ }
265
+ else if (index) {
266
+ // we only want the highest version
267
+ return;
268
+ }
269
+ const container = { items: [], name: apiName };
270
+ all.push(container);
271
+ Object
272
+ .entries(methods)
273
+ .sort(([a], [b]) => a.localeCompare(b))
274
+ .forEach(([methodName, { description, params, type }]) => {
275
+ const args = params.map(({ name, type }) => {
276
+ // eslint-disable-next-line @typescript-eslint/restrict-plus-operands
277
+ return name + ': `' + type + '`';
278
+ }).join(', ');
279
+ container.items.push({
280
+ interface: '`' + `api.call.${(0, util_2.stringCamelCase)(apiName)}.${(0, util_2.stringCamelCase)(methodName)}` + '`',
281
+ name: `${(0, util_2.stringCamelCase)(methodName)}(${args}): ${'`' + type + '`'}`,
282
+ runtime: '`' + `${apiName}_${methodName}` + '`',
283
+ summary: description
284
+ });
285
+ });
286
+ });
287
+ });
288
+ return all;
289
+ }, []).sort(sortByName),
290
+ title: 'Runtime'
291
+ });
292
+ }
293
+ /** @internal */
294
+ function addConstants(runtimeDesc, { lookup, pallets }) {
295
+ return renderPage({
296
+ description: `The following sections contain the module constants, also known as parameter types. These can only be changed as part of a runtime upgrade. On the api, these are exposed via \`api.consts.<module>.<method>\`. ${headerFn(runtimeDesc)}`,
297
+ sections: pallets
298
+ .sort(sortByName)
299
+ .filter(({ constants }) => !constants.isEmpty)
300
+ .map(({ constants, name }) => {
301
+ const sectionName = (0, util_2.stringLowerFirst)(name);
302
+ return {
303
+ items: constants
304
+ .sort(sortByName)
305
+ .map(({ docs, name, type }) => {
306
+ const methodName = (0, util_2.stringCamelCase)(name);
307
+ return {
308
+ interface: '`' + `api.consts.${sectionName}.${methodName}` + '`',
309
+ name: `${methodName}: ` + '`' + getSiName(lookup, type) + '`',
310
+ ...(docs.length && { summary: docs })
311
+ };
312
+ }),
313
+ name: sectionName
314
+ };
315
+ }),
316
+ title: 'Constants'
317
+ });
318
+ }
319
+ /** @internal */
320
+ function addStorage(runtimeDesc, { lookup, pallets, registry }) {
321
+ const { bizinikiwi } = (0, getStorage_1.getStorage)(registry);
322
+ const moduleSections = pallets
323
+ .sort(sortByName)
324
+ .filter((moduleMetadata) => !moduleMetadata.storage.isNone)
325
+ .map((moduleMetadata) => {
326
+ const sectionName = (0, util_2.stringLowerFirst)(moduleMetadata.name);
327
+ return {
328
+ items: moduleMetadata.storage.unwrap().items
329
+ .sort(sortByName)
330
+ .map((func) => {
331
+ let arg = '';
332
+ if (func.type.isMap) {
333
+ const { hashers, key } = func.type.asMap;
334
+ arg = '`' + (hashers.length === 1
335
+ ? getSiName(lookup, key)
336
+ : lookup.getSiType(key).def.asTuple.map((t) => getSiName(lookup, t)).join(', ')) + '`';
337
+ }
338
+ const methodName = (0, util_2.stringLowerFirst)(func.name);
339
+ const outputType = (0, util_1.unwrapStorageType)(registry, func.type, func.modifier.isOptional);
340
+ return {
341
+ interface: '`' + `api.query.${sectionName}.${methodName}` + '`',
342
+ name: `${methodName}(${arg}): ` + '`' + outputType + '`',
343
+ ...(func.docs.length && { summary: func.docs })
344
+ };
345
+ }),
346
+ name: sectionName
347
+ };
348
+ });
349
+ return renderPage({
350
+ description: `The following sections contain Storage methods are part of the ${runtimeDesc}. On the api, these are exposed via \`api.query.<module>.<method>\`. ${headerFn(runtimeDesc)}`,
351
+ sections: moduleSections.concat([{
352
+ description: 'These are well-known keys that are always available to the runtime implementation of any Bizinikiwi-based network.',
353
+ items: Object.entries(bizinikiwi).map(([name, { meta }]) => {
354
+ const arg = meta.type.isMap
355
+ ? ('`' + getSiName(lookup, meta.type.asMap.key) + '`')
356
+ : '';
357
+ const methodName = (0, util_2.stringLowerFirst)(name);
358
+ const outputType = (0, util_1.unwrapStorageType)(registry, meta.type, meta.modifier.isOptional);
359
+ return {
360
+ interface: '`' + `api.query.bizinikiwi.${methodName}` + '`',
361
+ name: `${methodName}(${arg}): ` + '`' + outputType + '`',
362
+ summary: meta.docs
363
+ };
364
+ }),
365
+ name: 'bizinikiwi'
366
+ }]).sort(sortByName),
367
+ title: 'Storage'
368
+ });
369
+ }
370
+ /** @internal */
371
+ function addExtrinsics(runtimeDesc, { lookup, pallets }) {
372
+ return renderPage({
373
+ description: `The following sections contain Extrinsics methods are part of the ${runtimeDesc}. On the api, these are exposed via \`api.tx.<module>.<method>\`. ${headerFn(runtimeDesc)}`,
374
+ sections: pallets
375
+ .sort(sortByName)
376
+ .filter(({ calls }) => calls.isSome)
377
+ .map(({ calls, name }) => {
378
+ const sectionName = (0, util_2.stringCamelCase)(name);
379
+ return {
380
+ items: lookup.getSiType(calls.unwrap().type).def.asVariant.variants
381
+ .sort(sortByName)
382
+ .map(({ docs, fields, name }, index) => {
383
+ const methodName = (0, util_2.stringCamelCase)(name);
384
+ const args = fields.map(({ name, type }) => `${name.isSome ? name.toString() : `param${index}`}: ` + '`' + getSiName(lookup, type) + '`').join(', ');
385
+ return {
386
+ interface: '`' + `api.tx.${sectionName}.${methodName}` + '`',
387
+ name: `${methodName}(${args})`,
388
+ ...(docs.length && { summary: docs })
389
+ };
390
+ }),
391
+ name: sectionName
392
+ };
393
+ }),
394
+ title: 'Extrinsics'
395
+ });
396
+ }
397
+ /** @internal */
398
+ function addEvents(runtimeDesc, { lookup, pallets }) {
399
+ return renderPage({
400
+ description: `Events are emitted for certain operations on the runtime. The following sections describe the events that are part of the ${runtimeDesc}. ${headerFn(runtimeDesc)}`,
401
+ sections: pallets
402
+ .sort(sortByName)
403
+ .filter(({ events }) => events.isSome)
404
+ .map((meta) => ({
405
+ items: lookup.getSiType(meta.events.unwrap().type).def.asVariant.variants
406
+ .sort(sortByName)
407
+ .map(({ docs, fields, name }) => {
408
+ const methodName = name.toString();
409
+ const args = fields.map(({ type }) => '`' + getSiName(lookup, type) + '`').join(', ');
410
+ return {
411
+ interface: '`' + `api.events.${(0, util_2.stringCamelCase)(meta.name)}.${methodName}.is` + '`',
412
+ name: `${methodName}(${args})`,
413
+ ...(docs.length && { summary: docs })
414
+ };
415
+ }),
416
+ name: (0, util_2.stringCamelCase)(meta.name)
417
+ })),
418
+ title: 'Events'
419
+ });
420
+ }
421
+ /** @internal */
422
+ function addErrors(runtimeDesc, { lookup, pallets }) {
423
+ return renderPage({
424
+ description: `This page lists the errors that can be encountered in the different modules. ${headerFn(runtimeDesc)}`,
425
+ sections: pallets
426
+ .sort(sortByName)
427
+ .filter(({ errors }) => errors.isSome)
428
+ .map((moduleMetadata) => ({
429
+ items: lookup.getSiType(moduleMetadata.errors.unwrap().type).def.asVariant.variants
430
+ .sort(sortByName)
431
+ .map((error) => ({
432
+ interface: '`' + `api.errors.${(0, util_2.stringCamelCase)(moduleMetadata.name)}.${error.name.toString()}.is` + '`',
433
+ name: error.name.toString(),
434
+ ...(error.docs.length && { summary: error.docs })
435
+ })),
436
+ name: (0, util_2.stringLowerFirst)(moduleMetadata.name)
437
+ })),
438
+ title: 'Errors'
439
+ });
440
+ }
441
+ function getDependencyBasePath(moduleName) {
442
+ const modulePath = import.meta.resolve(moduleName);
443
+ return (0, node_path_1.resolve)((0, node_path_1.dirname)((0, node_url_1.fileURLToPath)(modulePath)));
444
+ }
445
+ const BASE_DERIVE_PATH = getDependencyBasePath('@pezkuwi/api-derive');
446
+ const obtainDeriveFiles = (deriveModule) => {
447
+ const filePath = `${BASE_DERIVE_PATH}/${deriveModule}`;
448
+ const files = node_fs_1.default.readdirSync(filePath);
449
+ return files
450
+ .filter((file) => file.endsWith('.js'))
451
+ .map((file) => `${deriveModule}/${file}`);
452
+ };
453
+ function extractDeriveDescription(tags, name) {
454
+ const descriptionTag = tags.find((tag) => tag.tag === name);
455
+ return descriptionTag
456
+ ? `${descriptionTag.name ?? ''} ${descriptionTag.description ?? ''}`.trim()
457
+ : null;
458
+ }
459
+ function extractDeriveParams(tags) {
460
+ const descriptionTag = tags
461
+ .filter((tag) => tag.tag === 'param')
462
+ .map((param) => {
463
+ return {
464
+ description: param.description ?? null,
465
+ name: param.name ?? null,
466
+ type: param.type ?? null
467
+ };
468
+ });
469
+ return descriptionTag;
470
+ }
471
+ function extractDeriveExample(tags) {
472
+ const exampleTag = tags.find((tag) => tag.tag === 'example');
473
+ if (!exampleTag) {
474
+ return null;
475
+ }
476
+ let example = '';
477
+ const inCodeBlock = { done: false, found: false };
478
+ // Obtain code block from example tag.
479
+ exampleTag.source.forEach((line) => {
480
+ if (inCodeBlock.done) {
481
+ return;
482
+ }
483
+ if (line.source.indexOf('```') !== -1 && !inCodeBlock.found) {
484
+ inCodeBlock.found = true;
485
+ }
486
+ else if (line.source.indexOf('```') !== -1 && inCodeBlock.found) {
487
+ inCodeBlock.done = true;
488
+ }
489
+ if (!inCodeBlock.found) {
490
+ return;
491
+ }
492
+ example += line.source.slice(2, line.source.length);
493
+ if (!inCodeBlock.done) {
494
+ example += '\n';
495
+ }
496
+ });
497
+ return example;
498
+ }
499
+ const getDeriveDocs = (metadata, file) => {
500
+ const filePath = `${BASE_DERIVE_PATH}/${file}`;
501
+ const deriveModule = file.split('/')[0];
502
+ const fileContent = node_fs_1.default.readFileSync(filePath, 'utf8');
503
+ const comments = (0, comment_parser_1.parse)(fileContent);
504
+ const docs = comments
505
+ .filter((comment) => comment.tags)
506
+ .map((comment) => {
507
+ return {
508
+ description: extractDeriveDescription(comment.tags, 'description'),
509
+ example: extractDeriveExample(comment.tags),
510
+ name: comment.tags.find((tag) => tag.tag === 'name')?.name || null,
511
+ params: extractDeriveParams(comment.tags),
512
+ returns: extractDeriveDescription(comment.tags, 'returns')
513
+ };
514
+ });
515
+ metadata[deriveModule]
516
+ ? (metadata[deriveModule] = [...metadata[deriveModule], ...docs])
517
+ : (metadata[deriveModule] = [...docs]);
518
+ };
519
+ function renderDerives(metadata) {
520
+ let md = '---\ntitle: Derives\n---\n\nThis page lists the derives that can be encountered in the different modules. Designed to simplify the process of querying complex on-chain data by combining multiple RPC calls, storage queries, and runtime logic into a single, callable function. \n\nInstead of manually fetching and processing blockchain data, developers can use `api.derive.<module>.<method>()` to retrieve information.\n\n';
521
+ const deriveModules = Object.keys(metadata).filter((d) => metadata[d].length !== 0);
522
+ // index
523
+ deriveModules.forEach((deriveModule) => {
524
+ md += `- **[${deriveModule}](#${deriveModule})**\n\n`;
525
+ });
526
+ // contents
527
+ deriveModules.forEach((deriveModule) => {
528
+ md += `\n___\n## ${deriveModule}\n`;
529
+ metadata[deriveModule]
530
+ .filter((item) => item.name)
531
+ .forEach((item) => {
532
+ const { description, example, name, params, returns } = item;
533
+ md += ` \n### [${name}](#${name})`;
534
+ if (description) {
535
+ md += `\n${description}`;
536
+ }
537
+ md += `\n- **interface**: \`api.derive.${deriveModule}.${name}\``;
538
+ if (params.length) {
539
+ md += '\n- **params**:\n';
540
+ params.forEach((param) => (md += ` - ${param.name} \`${param.type}\`: ${param.description}\n`));
541
+ }
542
+ if (returns) {
543
+ md += `\n- **returns**: ${returns}`;
544
+ }
545
+ if (example) {
546
+ md += `\n- **example**: \n${example}`;
547
+ }
548
+ });
549
+ });
550
+ return md;
551
+ }
552
+ function generateDerives() {
553
+ let fileList = [];
554
+ Object.keys(api_derive_1.derive).forEach((deriveModule) => {
555
+ fileList = [...fileList, ...obtainDeriveFiles(deriveModule)];
556
+ });
557
+ const metadata = {};
558
+ fileList.forEach((file) => {
559
+ getDeriveDocs(metadata, file);
560
+ });
561
+ return renderDerives(metadata);
562
+ }
563
+ /** @internal */
564
+ function writeFile(name, ...chunks) {
565
+ const writeStream = node_fs_1.default.createWriteStream(name, { encoding: 'utf8', flags: 'w' });
566
+ writeStream.on('finish', () => {
567
+ console.log(`Completed writing ${name}`);
568
+ });
569
+ chunks.forEach((chunk) => {
570
+ writeStream.write(chunk);
571
+ });
572
+ writeStream.end();
573
+ }
574
+ async function mainPromise() {
575
+ const { chain, endpoint, metadataVer } = (0, yargs_1.default)((0, helpers_1.hideBin)(node_process_1.default.argv)).strict().options({
576
+ chain: {
577
+ description: 'The chain name to use for the output (defaults to "Bizinikiwi")',
578
+ type: 'string'
579
+ },
580
+ endpoint: {
581
+ description: 'The endpoint to connect to (e.g. wss://dicle-rpc.pezkuwi.io) or relative path to a file containing the JSON output of an RPC state_getMetadata call',
582
+ type: 'string'
583
+ },
584
+ metadataVer: {
585
+ description: 'The metadata version to use for generating type information. This will use state_call::Metadata_metadata_at_version to query metadata',
586
+ type: 'number'
587
+ }
588
+ }).argv;
589
+ /**
590
+ * This is unique to when the endpoint arg is used. Since the endpoint requires us to query the chain, it may query the chains
591
+ * rpc state_getMetadata method to get metadata, but this restricts us to v14 only. Therefore we must also check if the `metadataVer` is passed
592
+ * in as well. These checks will help us decide if we are using v14 or newer.
593
+ */
594
+ const useV14Metadata = endpoint && ((metadataVer && metadataVer < 15) || !metadataVer);
595
+ const chainName = chain || 'Bizinikiwi';
596
+ let metaHex;
597
+ let rpcMethods;
598
+ let runtimeApis;
599
+ if (endpoint) {
600
+ if (endpoint.startsWith('wss://') || endpoint.startsWith('ws://')) {
601
+ metaHex = await (0, index_js_1.getMetadataViaWs)(endpoint, metadataVer);
602
+ rpcMethods = await (0, index_js_1.getRpcMethodsViaWs)(endpoint);
603
+ runtimeApis = await (0, index_js_1.getRuntimeVersionViaWs)(endpoint);
604
+ }
605
+ else {
606
+ metaHex = JSON.parse(node_fs_1.default.readFileSync((0, index_js_1.assertFile)(node_path_1.default.join(node_process_1.default.cwd(), endpoint)), 'utf-8')).result;
607
+ if (!(0, util_2.isHex)(metaHex)) {
608
+ throw new Error('Invalid metadata file');
609
+ }
610
+ }
611
+ }
612
+ else if (ALL_STATIC[chainName.toLowerCase()]) {
613
+ metaHex = ALL_STATIC[chainName.toLowerCase()].meta;
614
+ rpcMethods = ALL_STATIC[chainName.toLowerCase()].rpc?.methods;
615
+ }
616
+ else {
617
+ metaHex = bizinikiwi_hex_1.default;
618
+ }
619
+ let metadata;
620
+ const registry = new types_1.TypeRegistry();
621
+ if (useV14Metadata) {
622
+ metadata = new types_1.Metadata(registry, metaHex);
623
+ }
624
+ else {
625
+ const opaqueMetadata = registry.createType('Option<OpaqueMetadata>', registry.createType('Raw', metaHex).toU8a()).unwrap();
626
+ metadata = new types_1.Metadata(registry, opaqueMetadata.toHex());
627
+ }
628
+ registry.setMetadata(metadata);
629
+ const latest = metadata.asLatest;
630
+ const runtimeDesc = `default ${chainName} runtime`;
631
+ const docRoot = `docs/${chainName.toLowerCase()}`;
632
+ writeFile(`${docRoot}/rpc.md`, addRpc(runtimeDesc, rpcMethods));
633
+ useV14Metadata
634
+ ? writeFile(`${docRoot}/runtime.md`, addLegacyRuntime(runtimeDesc, registry, runtimeApis))
635
+ : writeFile(`${docRoot}/runtime.md`, addRuntime(runtimeDesc, registry));
636
+ writeFile(`${docRoot}/constants.md`, addConstants(runtimeDesc, latest));
637
+ writeFile(`${docRoot}/storage.md`, addStorage(runtimeDesc, latest));
638
+ writeFile(`${docRoot}/extrinsics.md`, addExtrinsics(runtimeDesc, latest));
639
+ writeFile(`${docRoot}/events.md`, addEvents(runtimeDesc, latest));
640
+ writeFile(`${docRoot}/errors.md`, addErrors(runtimeDesc, latest));
641
+ if (chainName === 'Bizinikiwi') {
642
+ writeFile('docs/derives/derives.md', generateDerives());
643
+ }
644
+ }
645
+ function main() {
646
+ mainPromise().catch((error) => {
647
+ console.error();
648
+ console.error(error);
649
+ console.error();
650
+ node_process_1.default.exit(1);
651
+ });
652
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "commonjs"
3
+ }
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const packageInfo_1 = require("@pezkuwi/api/cjs/packageInfo");
4
+ const packageInfo_2 = require("@pezkuwi/rpc-provider/cjs/packageInfo");
5
+ const packageInfo_3 = require("@pezkuwi/types/cjs/packageInfo");
6
+ const util_1 = require("@pezkuwi/util");
7
+ const packageInfo_js_1 = require("./packageInfo.js");
8
+ (0, util_1.detectPackage)(packageInfo_js_1.packageInfo, null, [packageInfo_1.packageInfo, packageInfo_2.packageInfo, packageInfo_3.packageInfo]);
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.packageInfo = void 0;
4
+ exports.packageInfo = { name: '@pezkuwi/typegen', path: typeof __dirname === 'string' ? __dirname : 'auto', type: 'cjs', version: '16.5.4' };