@pezkuwi/typegen 16.5.16 → 16.5.18

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 (307) hide show
  1. package/build/LICENSE +201 -0
  2. package/build/README.md +3 -0
  3. package/build/augment.js +2 -0
  4. package/build/bundle.js +2 -0
  5. package/build/cjs/augment.d.ts +2 -0
  6. package/build/cjs/augment.js +4 -0
  7. package/build/cjs/bundle.d.ts +2 -0
  8. package/build/cjs/bundle.js +7 -0
  9. package/build/cjs/extractChain.js +44 -0
  10. package/build/cjs/fromChain.js +95 -0
  11. package/build/cjs/fromDefs.js +82 -0
  12. package/build/cjs/generate/consts.d.ts +5 -0
  13. package/build/cjs/generate/consts.js +91 -0
  14. package/build/cjs/generate/errors.d.ts +4 -0
  15. package/build/cjs/generate/errors.js +59 -0
  16. package/build/cjs/generate/events.d.ts +5 -0
  17. package/build/cjs/generate/events.js +139 -0
  18. package/build/cjs/generate/index.js +23 -0
  19. package/build/cjs/generate/interfaceRegistry.d.ts +4 -0
  20. package/build/cjs/generate/interfaceRegistry.js +64 -0
  21. package/build/cjs/generate/lookup.d.ts +4 -0
  22. package/build/cjs/generate/lookup.js +240 -0
  23. package/build/cjs/generate/query.d.ts +5 -0
  24. package/build/cjs/generate/query.js +140 -0
  25. package/build/cjs/generate/rpc.d.ts +6 -0
  26. package/build/cjs/generate/rpc.js +115 -0
  27. package/build/cjs/generate/runtime.d.ts +7 -0
  28. package/build/cjs/generate/runtime.js +233 -0
  29. package/build/cjs/generate/tsDef.d.ts +16 -0
  30. package/build/cjs/generate/tsDef.js +254 -0
  31. package/build/cjs/generate/tx.d.ts +5 -0
  32. package/build/cjs/generate/tx.js +121 -0
  33. package/build/cjs/generate/types.d.ts +12 -0
  34. package/build/cjs/generate/types.js +16 -0
  35. package/build/cjs/index.js +5 -0
  36. package/build/cjs/interfacesTs.js +28 -0
  37. package/build/cjs/metadataMd.js +652 -0
  38. package/build/cjs/packageInfo.js +4 -0
  39. package/build/cjs/util/assert.js +15 -0
  40. package/build/cjs/util/derived.js +128 -0
  41. package/build/cjs/util/docs.js +10 -0
  42. package/build/cjs/util/file.js +33 -0
  43. package/build/cjs/util/formatting.js +237 -0
  44. package/build/cjs/util/imports.js +126 -0
  45. package/build/cjs/util/index.js +39 -0
  46. package/build/cjs/util/initMeta.js +22 -0
  47. package/build/cjs/util/register.js +10 -0
  48. package/build/cjs/util/wsMeta.js +60 -0
  49. package/build/extractChain.d.ts +1 -0
  50. package/build/extractChain.js +40 -0
  51. package/build/fromChain.d.ts +1 -0
  52. package/build/fromChain.js +91 -0
  53. package/build/fromDefs.d.ts +1 -0
  54. package/build/fromDefs.js +78 -0
  55. package/build/generate/consts.d.ts +5 -0
  56. package/build/generate/consts.js +87 -0
  57. package/build/generate/errors.d.ts +4 -0
  58. package/build/generate/errors.js +55 -0
  59. package/build/generate/events.d.ts +5 -0
  60. package/build/generate/events.js +135 -0
  61. package/build/generate/index.d.ts +10 -0
  62. package/build/generate/index.js +10 -0
  63. package/build/generate/interfaceRegistry.d.ts +4 -0
  64. package/build/generate/interfaceRegistry.js +59 -0
  65. package/build/generate/lookup.d.ts +4 -0
  66. package/build/generate/lookup.js +235 -0
  67. package/build/generate/query.d.ts +5 -0
  68. package/build/generate/query.js +136 -0
  69. package/build/generate/rpc.d.ts +6 -0
  70. package/build/generate/rpc.js +110 -0
  71. package/build/generate/runtime.d.ts +7 -0
  72. package/build/generate/runtime.js +228 -0
  73. package/build/generate/tsDef.d.ts +16 -0
  74. package/build/generate/tsDef.js +246 -0
  75. package/build/generate/tx.d.ts +5 -0
  76. package/build/generate/tx.js +117 -0
  77. package/build/generate/types.d.ts +12 -0
  78. package/build/generate/types.js +13 -0
  79. package/build/index.d.ts +2 -0
  80. package/build/index.js +2 -0
  81. package/build/interfacesTs.d.ts +1 -0
  82. package/build/interfacesTs.js +24 -0
  83. package/build/metadataMd.d.ts +1 -0
  84. package/build/metadataMd.js +648 -0
  85. package/build/package.json +548 -0
  86. package/build/packageDetect.d.ts +1 -0
  87. package/build/packageDetect.js +6 -0
  88. package/build/packageInfo.d.ts +6 -0
  89. package/build/packageInfo.js +1 -0
  90. package/build/scripts/pezkuwi-types-chain-info.mjs +7 -0
  91. package/build/scripts/pezkuwi-types-from-chain.mjs +7 -0
  92. package/build/scripts/pezkuwi-types-from-defs.mjs +7 -0
  93. package/build/scripts/pezkuwi-types-internal-interfaces.mjs +7 -0
  94. package/build/scripts/pezkuwi-types-internal-metadata.mjs +7 -0
  95. package/build/templates/calls.hbs +30 -0
  96. package/build/templates/consts.hbs +28 -0
  97. package/build/templates/docs.hbs +7 -0
  98. package/build/templates/errors.hbs +28 -0
  99. package/build/templates/events.hbs +28 -0
  100. package/build/templates/header.hbs +2 -0
  101. package/build/templates/interfaceRegistry.hbs +15 -0
  102. package/build/templates/lookup/defs-named.hbs +12 -0
  103. package/build/templates/lookup/defs.hbs +15 -0
  104. package/build/templates/lookup/index.hbs +3 -0
  105. package/build/templates/lookup/types.hbs +14 -0
  106. package/build/templates/query.hbs +29 -0
  107. package/build/templates/rpc.hbs +22 -0
  108. package/build/templates/tsDef/index.hbs +3 -0
  109. package/build/templates/tsDef/moduleTypes.hbs +10 -0
  110. package/build/templates/tsDef/types.hbs +7 -0
  111. package/build/templates/tx.hbs +30 -0
  112. package/build/util/assert.d.ts +2 -0
  113. package/build/util/assert.js +10 -0
  114. package/build/util/derived.d.ts +4 -0
  115. package/build/util/derived.js +125 -0
  116. package/build/util/docs.d.ts +1 -0
  117. package/build/util/docs.js +6 -0
  118. package/build/util/file.d.ts +2 -0
  119. package/build/util/file.js +28 -0
  120. package/build/util/formatting.d.ts +11 -0
  121. package/build/util/formatting.js +230 -0
  122. package/build/util/imports.d.ts +23 -0
  123. package/build/util/imports.js +121 -0
  124. package/build/util/index.d.ts +16 -0
  125. package/build/util/index.js +34 -0
  126. package/build/util/initMeta.d.ts +12 -0
  127. package/build/util/initMeta.js +19 -0
  128. package/build/util/register.d.ts +4 -0
  129. package/build/util/register.js +7 -0
  130. package/build/util/wsMeta.d.ts +4 -0
  131. package/build/util/wsMeta.js +55 -0
  132. package/build-tsc-cjs/packageDetect.js +8 -0
  133. package/{cjs → build-tsc-cjs}/packageInfo.js +1 -1
  134. package/build-tsc-esm/generate/consts.js +87 -0
  135. package/build-tsc-esm/generate/errors.js +55 -0
  136. package/build-tsc-esm/generate/events.js +135 -0
  137. package/build-tsc-esm/generate/interfaceRegistry.js +59 -0
  138. package/build-tsc-esm/generate/lookup.js +235 -0
  139. package/build-tsc-esm/generate/query.js +136 -0
  140. package/build-tsc-esm/generate/rpc.js +110 -0
  141. package/build-tsc-esm/generate/runtime.js +228 -0
  142. package/build-tsc-esm/generate/tsDef.js +246 -0
  143. package/build-tsc-esm/generate/tx.js +117 -0
  144. package/build-tsc-esm/generate/types.js +13 -0
  145. package/{packageInfo.js → build-tsc-esm/packageInfo.js} +1 -1
  146. package/package.json +27 -27
  147. package/src/augment.ts +5 -0
  148. package/src/bundle.ts +5 -0
  149. package/src/extractChain.ts +54 -0
  150. package/src/fromChain.ts +123 -0
  151. package/src/fromDefs.ts +106 -0
  152. package/src/generate/consts.ts +112 -0
  153. package/src/generate/errors.ts +75 -0
  154. package/src/generate/events.ts +165 -0
  155. package/src/generate/index.ts +13 -0
  156. package/src/generate/interfaceRegistry.ts +85 -0
  157. package/src/generate/lookup.ts +322 -0
  158. package/src/generate/query.ts +169 -0
  159. package/src/generate/rpc.ts +158 -0
  160. package/src/generate/runtime.ts +293 -0
  161. package/src/generate/tsDef.ts +321 -0
  162. package/src/generate/tx.ts +152 -0
  163. package/src/generate/types.ts +26 -0
  164. package/src/index.ts +6 -0
  165. package/src/interfacesTs.ts +35 -0
  166. package/src/metadataMd.ts +844 -0
  167. package/src/packageDetect.ts +14 -0
  168. package/src/packageInfo.ts +6 -0
  169. package/src/templates/calls.hbs +30 -0
  170. package/src/templates/consts.hbs +28 -0
  171. package/src/templates/docs.hbs +7 -0
  172. package/src/templates/errors.hbs +28 -0
  173. package/src/templates/events.hbs +28 -0
  174. package/src/templates/header.hbs +2 -0
  175. package/src/templates/interfaceRegistry.hbs +15 -0
  176. package/src/templates/lookup/defs-named.hbs +12 -0
  177. package/src/templates/lookup/defs.hbs +15 -0
  178. package/src/templates/lookup/index.hbs +3 -0
  179. package/src/templates/lookup/types.hbs +14 -0
  180. package/src/templates/query.hbs +29 -0
  181. package/src/templates/rpc.hbs +22 -0
  182. package/src/templates/tsDef/index.hbs +3 -0
  183. package/src/templates/tsDef/moduleTypes.hbs +10 -0
  184. package/src/templates/tsDef/types.hbs +7 -0
  185. package/src/templates/tx.hbs +30 -0
  186. package/src/util/assert.ts +18 -0
  187. package/src/util/derived.spec.ts +58 -0
  188. package/src/util/derived.ts +133 -0
  189. package/src/util/docs.ts +13 -0
  190. package/src/util/file.ts +42 -0
  191. package/src/util/formatting.spec.ts +30 -0
  192. package/src/util/formatting.ts +322 -0
  193. package/src/util/imports.ts +164 -0
  194. package/src/util/index.ts +42 -0
  195. package/src/util/initMeta.ts +37 -0
  196. package/src/util/register.ts +12 -0
  197. package/src/util/wsMeta.ts +70 -0
  198. package/tsconfig.build.json +28 -0
  199. package/tsconfig.build.tsbuildinfo +1 -0
  200. package/tsconfig.scripts.json +19 -0
  201. package/tsconfig.spec.json +17 -0
  202. package/tsconfig.spec.tsbuildinfo +1 -0
  203. /package/{cjs → build}/augment.d.ts +0 -0
  204. /package/{cjs → build}/bundle.d.ts +0 -0
  205. /package/{extractChain.d.ts → build/cjs/extractChain.d.ts} +0 -0
  206. /package/{fromChain.d.ts → build/cjs/fromChain.d.ts} +0 -0
  207. /package/{fromDefs.d.ts → build/cjs/fromDefs.d.ts} +0 -0
  208. /package/{generate → build/cjs/generate}/index.d.ts +0 -0
  209. /package/{index.d.ts → build/cjs/index.d.ts} +0 -0
  210. /package/{interfacesTs.d.ts → build/cjs/interfacesTs.d.ts} +0 -0
  211. /package/{metadataMd.d.ts → build/cjs/metadataMd.d.ts} +0 -0
  212. /package/{cjs → build/cjs}/package.json +0 -0
  213. /package/{packageDetect.d.ts → build/cjs/packageDetect.d.ts} +0 -0
  214. /package/{cjs → build/cjs}/packageDetect.js +0 -0
  215. /package/{packageInfo.d.ts → build/cjs/packageInfo.d.ts} +0 -0
  216. /package/{util → build/cjs/util}/assert.d.ts +0 -0
  217. /package/{util → build/cjs/util}/derived.d.ts +0 -0
  218. /package/{util → build/cjs/util}/docs.d.ts +0 -0
  219. /package/{util → build/cjs/util}/file.d.ts +0 -0
  220. /package/{util → build/cjs/util}/formatting.d.ts +0 -0
  221. /package/{util → build/cjs/util}/imports.d.ts +0 -0
  222. /package/{util → build/cjs/util}/index.d.ts +0 -0
  223. /package/{util → build/cjs/util}/initMeta.d.ts +0 -0
  224. /package/{util → build/cjs/util}/register.d.ts +0 -0
  225. /package/{util → build/cjs/util}/wsMeta.d.ts +0 -0
  226. /package/{augment.d.ts → build-tsc/augment.d.ts} +0 -0
  227. /package/{bundle.d.ts → build-tsc/bundle.d.ts} +0 -0
  228. /package/{cjs → build-tsc}/extractChain.d.ts +0 -0
  229. /package/{cjs → build-tsc}/fromChain.d.ts +0 -0
  230. /package/{cjs → build-tsc}/fromDefs.d.ts +0 -0
  231. /package/{cjs → build-tsc}/generate/consts.d.ts +0 -0
  232. /package/{cjs → build-tsc}/generate/errors.d.ts +0 -0
  233. /package/{cjs → build-tsc}/generate/events.d.ts +0 -0
  234. /package/{cjs → build-tsc}/generate/index.d.ts +0 -0
  235. /package/{cjs → build-tsc}/generate/interfaceRegistry.d.ts +0 -0
  236. /package/{cjs → build-tsc}/generate/lookup.d.ts +0 -0
  237. /package/{cjs → build-tsc}/generate/query.d.ts +0 -0
  238. /package/{cjs → build-tsc}/generate/rpc.d.ts +0 -0
  239. /package/{cjs → build-tsc}/generate/runtime.d.ts +0 -0
  240. /package/{cjs → build-tsc}/generate/tsDef.d.ts +0 -0
  241. /package/{cjs → build-tsc}/generate/tx.d.ts +0 -0
  242. /package/{cjs → build-tsc}/generate/types.d.ts +0 -0
  243. /package/{cjs → build-tsc}/index.d.ts +0 -0
  244. /package/{cjs → build-tsc}/interfacesTs.d.ts +0 -0
  245. /package/{cjs → build-tsc}/metadataMd.d.ts +0 -0
  246. /package/{cjs → build-tsc}/packageDetect.d.ts +0 -0
  247. /package/{cjs → build-tsc}/packageInfo.d.ts +0 -0
  248. /package/{cjs → build-tsc}/util/assert.d.ts +0 -0
  249. /package/{cjs → build-tsc}/util/derived.d.ts +0 -0
  250. /package/{cjs → build-tsc}/util/docs.d.ts +0 -0
  251. /package/{cjs → build-tsc}/util/file.d.ts +0 -0
  252. /package/{cjs → build-tsc}/util/formatting.d.ts +0 -0
  253. /package/{cjs → build-tsc}/util/imports.d.ts +0 -0
  254. /package/{cjs → build-tsc}/util/index.d.ts +0 -0
  255. /package/{cjs → build-tsc}/util/initMeta.d.ts +0 -0
  256. /package/{cjs → build-tsc}/util/register.d.ts +0 -0
  257. /package/{cjs → build-tsc}/util/wsMeta.d.ts +0 -0
  258. /package/{cjs → build-tsc-cjs}/augment.js +0 -0
  259. /package/{cjs → build-tsc-cjs}/bundle.js +0 -0
  260. /package/{cjs → build-tsc-cjs}/extractChain.js +0 -0
  261. /package/{cjs → build-tsc-cjs}/fromChain.js +0 -0
  262. /package/{cjs → build-tsc-cjs}/fromDefs.js +0 -0
  263. /package/{cjs → build-tsc-cjs}/generate/consts.js +0 -0
  264. /package/{cjs → build-tsc-cjs}/generate/errors.js +0 -0
  265. /package/{cjs → build-tsc-cjs}/generate/events.js +0 -0
  266. /package/{cjs → build-tsc-cjs}/generate/index.js +0 -0
  267. /package/{cjs → build-tsc-cjs}/generate/interfaceRegistry.js +0 -0
  268. /package/{cjs → build-tsc-cjs}/generate/lookup.js +0 -0
  269. /package/{cjs → build-tsc-cjs}/generate/query.js +0 -0
  270. /package/{cjs → build-tsc-cjs}/generate/rpc.js +0 -0
  271. /package/{cjs → build-tsc-cjs}/generate/runtime.js +0 -0
  272. /package/{cjs → build-tsc-cjs}/generate/tsDef.js +0 -0
  273. /package/{cjs → build-tsc-cjs}/generate/tx.js +0 -0
  274. /package/{cjs → build-tsc-cjs}/generate/types.js +0 -0
  275. /package/{cjs → build-tsc-cjs}/index.js +0 -0
  276. /package/{cjs → build-tsc-cjs}/interfacesTs.js +0 -0
  277. /package/{cjs → build-tsc-cjs}/metadataMd.js +0 -0
  278. /package/{cjs → build-tsc-cjs}/util/assert.js +0 -0
  279. /package/{cjs → build-tsc-cjs}/util/derived.js +0 -0
  280. /package/{cjs → build-tsc-cjs}/util/docs.js +0 -0
  281. /package/{cjs → build-tsc-cjs}/util/file.js +0 -0
  282. /package/{cjs → build-tsc-cjs}/util/formatting.js +0 -0
  283. /package/{cjs → build-tsc-cjs}/util/imports.js +0 -0
  284. /package/{cjs → build-tsc-cjs}/util/index.js +0 -0
  285. /package/{cjs → build-tsc-cjs}/util/initMeta.js +0 -0
  286. /package/{cjs → build-tsc-cjs}/util/register.js +0 -0
  287. /package/{cjs → build-tsc-cjs}/util/wsMeta.js +0 -0
  288. /package/{augment.js → build-tsc-esm/augment.js} +0 -0
  289. /package/{bundle.js → build-tsc-esm/bundle.js} +0 -0
  290. /package/{extractChain.js → build-tsc-esm/extractChain.js} +0 -0
  291. /package/{fromChain.js → build-tsc-esm/fromChain.js} +0 -0
  292. /package/{fromDefs.js → build-tsc-esm/fromDefs.js} +0 -0
  293. /package/{generate → build-tsc-esm/generate}/index.js +0 -0
  294. /package/{index.js → build-tsc-esm/index.js} +0 -0
  295. /package/{interfacesTs.js → build-tsc-esm/interfacesTs.js} +0 -0
  296. /package/{metadataMd.js → build-tsc-esm/metadataMd.js} +0 -0
  297. /package/{packageDetect.js → build-tsc-esm/packageDetect.js} +0 -0
  298. /package/{util → build-tsc-esm/util}/assert.js +0 -0
  299. /package/{util → build-tsc-esm/util}/derived.js +0 -0
  300. /package/{util → build-tsc-esm/util}/docs.js +0 -0
  301. /package/{util → build-tsc-esm/util}/file.js +0 -0
  302. /package/{util → build-tsc-esm/util}/formatting.js +0 -0
  303. /package/{util → build-tsc-esm/util}/imports.js +0 -0
  304. /package/{util → build-tsc-esm/util}/index.js +0 -0
  305. /package/{util → build-tsc-esm/util}/initMeta.js +0 -0
  306. /package/{util → build-tsc-esm/util}/register.js +0 -0
  307. /package/{util → build-tsc-esm/util}/wsMeta.js +0 -0
@@ -0,0 +1,169 @@
1
+ // Copyright 2017-2025 @pezkuwi/typegen authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import type { StorageEntryMetadataLatest } from '@pezkuwi/types/interfaces';
5
+ import type { Metadata, PortableRegistry } from '@pezkuwi/types/metadata';
6
+ import type { Definitions, Registry } from '@pezkuwi/types/types';
7
+ import type { HexString } from '@pezkuwi/util/types';
8
+ import type { ModuleTypes, TypeImports } from '../util/imports.js';
9
+
10
+ import Handlebars from 'handlebars';
11
+
12
+ import * as defaultDefs from '@pezkuwi/types/interfaces/definitions';
13
+ import { unwrapStorageSi } from '@pezkuwi/types/util';
14
+ import lookupDefinitions from '@pezkuwi/types-augment/lookup/definitions';
15
+ import { stringCamelCase } from '@pezkuwi/util';
16
+
17
+ import { compareName, createImports, formatType, getSimilarTypes, initMeta, readTemplate, rebrandTypeName, setImports, writeFile } from '../util/index.js';
18
+ import { ignoreUnusedLookups } from './lookup.js';
19
+ import { type ExtraTypes, getDeprecationNotice } from './types.js';
20
+
21
+ const generateForMetaTemplate = Handlebars.compile(readTemplate('query'));
22
+
23
+ // From a storage entry metadata, we return [args, returnType]
24
+ /** @internal */
25
+ function entrySignature (lookup: PortableRegistry, allDefs: Record<string, ModuleTypes>, registry: Registry, section: string, storageEntry: StorageEntryMetadataLatest, imports: TypeImports): [boolean, string, string, string] {
26
+ try {
27
+ const outputType = lookup.getTypeDef(unwrapStorageSi(storageEntry.type));
28
+
29
+ if (storageEntry.type.isPlain) {
30
+ const typeDef = lookup.getTypeDef(storageEntry.type.asPlain);
31
+
32
+ setImports(allDefs, imports, [
33
+ rebrandTypeName(typeDef.lookupName || typeDef.type),
34
+ storageEntry.modifier.isOptional
35
+ ? 'Option'
36
+ : null
37
+ ]);
38
+
39
+ return [storageEntry.modifier.isOptional, '', '', formatType(registry, allDefs, outputType, imports)];
40
+ } else if (storageEntry.type.isMap) {
41
+ const { hashers, key, value } = storageEntry.type.asMap;
42
+ const keyDefs = hashers.length === 1
43
+ ? [lookup.getTypeDef(key)]
44
+ : lookup.getSiType(key).def.asTuple.map((k) => lookup.getTypeDef(k));
45
+ const similarTypes = keyDefs.map((k) => getSimilarTypes(registry, allDefs, k.lookupName || k.type, imports));
46
+ const keyTypes = similarTypes.map((t) => t.join(' | '));
47
+ const defValue = lookup.getTypeDef(value);
48
+
49
+ setImports(allDefs, imports, [
50
+ ...similarTypes.reduce<string[]>((all, t) => all.concat(t), []),
51
+ storageEntry.modifier.isOptional
52
+ ? 'Option'
53
+ : null,
54
+ rebrandTypeName(defValue.lookupName || defValue.type)
55
+ ]);
56
+
57
+ return [
58
+ storageEntry.modifier.isOptional,
59
+ keyDefs.map((k) => formatType(registry, allDefs, k.lookupName || k.type, imports)).join(', '),
60
+ keyTypes.map((t, i) => `arg${keyTypes.length === 1 ? '' : (i + 1)}: ${t}`).join(', '),
61
+ rebrandTypeName(outputType.lookupName || '') || formatType(registry, allDefs, outputType, imports)
62
+ ];
63
+ }
64
+
65
+ throw new Error(`Expected Plain or Map type, found ${storageEntry.type.type}`);
66
+ } catch (error) {
67
+ throw new Error(`entrySignature: Cannot create signature for query ${section}.${storageEntry.name.toString()}:: ${(error as Error).message}`);
68
+ }
69
+ }
70
+
71
+ /** @internal */
72
+ function generateForMeta (registry: Registry, meta: Metadata, dest: string, extraTypes: ExtraTypes, isStrict: boolean, customLookupDefinitions?: Definitions): void {
73
+ writeFile(dest, (): string => {
74
+ const allTypes: ExtraTypes = {
75
+ '@pezkuwi/types-augment': {
76
+ lookup: {
77
+ ...lookupDefinitions,
78
+ ...customLookupDefinitions
79
+ }
80
+ },
81
+ '@pezkuwi/types/interfaces': defaultDefs,
82
+ ...extraTypes
83
+ };
84
+
85
+ const imports = createImports(allTypes);
86
+ const allDefs = Object.entries(allTypes).reduce((defs, [path, obj]) => {
87
+ return Object.entries(obj).reduce((defs, [key, value]) => ({ ...defs, [`${path}/${key}`]: value }), defs);
88
+ }, {});
89
+ const { lookup, pallets } = meta.asLatest;
90
+ const usedTypes = new Set<string>([]);
91
+ const modules = pallets
92
+ .filter(({ storage }) => storage.isSome)
93
+ .map(({ name, storage }) => {
94
+ const items = storage.unwrap().items
95
+ .map((storageEntry) => {
96
+ const { deprecationInfo, docs, name } = storageEntry;
97
+ const [isOptional, args, params, _returnType] = entrySignature(lookup, allDefs, registry, name.toString(), storageEntry, imports);
98
+
99
+ if (!deprecationInfo.isNotDeprecated) {
100
+ const deprecationNotice = getDeprecationNotice(deprecationInfo, stringCamelCase(name));
101
+ const items = docs.length
102
+ ? ['', deprecationNotice]
103
+ : [deprecationNotice];
104
+
105
+ docs.push(...items.map((text) => registry.createType('Text', text)));
106
+ }
107
+
108
+ // Add the type and args to the list of used types
109
+ if (!(imports.primitiveTypes[_returnType])) {
110
+ usedTypes.add(_returnType);
111
+ }
112
+
113
+ if (!(imports.primitiveTypes[args])) {
114
+ usedTypes.add(args);
115
+ }
116
+
117
+ const returnType = isOptional
118
+ ? `Option<${_returnType}>`
119
+ : _returnType;
120
+
121
+ return {
122
+ args,
123
+ docs,
124
+ entryType: 'AugmentedQuery',
125
+ name: stringCamelCase(storageEntry.name),
126
+ params,
127
+ returnType
128
+ };
129
+ })
130
+ .sort(compareName);
131
+
132
+ return {
133
+ items,
134
+ name: stringCamelCase(name)
135
+ };
136
+ })
137
+ .sort(compareName);
138
+
139
+ imports.typesTypes['Observable'] = true;
140
+
141
+ // filter out the unused lookup types from imports
142
+ ignoreUnusedLookups([...usedTypes], imports);
143
+
144
+ return generateForMetaTemplate({
145
+ headerType: 'chain',
146
+ imports,
147
+ isStrict,
148
+ modules,
149
+ types: [
150
+ ...Object.keys(imports.localTypes).sort().map((packagePath): { file: string; types: string[] } => ({
151
+ file: packagePath.replace('@pezkuwi/types-augment', '@pezkuwi/types'),
152
+ types: Object.keys(imports.localTypes[packagePath])
153
+ })),
154
+ {
155
+ file: '@pezkuwi/api-base/types',
156
+ types: ['ApiTypes', 'AugmentedQuery', 'QueryableStorageEntry']
157
+ }
158
+ ]
159
+ });
160
+ });
161
+ }
162
+
163
+ // Call `generateForMeta()` with current static metadata
164
+ /** @internal */
165
+ export function generateDefaultQuery (dest: string, data: HexString, extraTypes: ExtraTypes = {}, isStrict = false, customLookupDefinitions?: Definitions): void {
166
+ const { metadata, registry } = initMeta(data, extraTypes);
167
+
168
+ return generateForMeta(registry, metadata, dest, extraTypes, isStrict, customLookupDefinitions);
169
+ }
@@ -0,0 +1,158 @@
1
+ // Copyright 2017-2025 @pezkuwi/typegen authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import type { TypeRegistry } from '@pezkuwi/types/create';
5
+ import type { Definitions } from '@pezkuwi/types/types';
6
+ import type { ExtraTypes } from './types.js';
7
+
8
+ import Handlebars from 'handlebars';
9
+
10
+ import * as defaultDefinitions from '@pezkuwi/types/interfaces/definitions';
11
+ import staticBizinikiwi from '@pezkuwi/types-support/metadata/static-bizinikiwi';
12
+
13
+ import { createImports, formatType, getSimilarTypes, initMeta, readTemplate, setImports, writeFile } from '../util/index.js';
14
+
15
+ interface ItemDef {
16
+ args: string;
17
+ docs: string[];
18
+ generic: string | undefined;
19
+ name: string;
20
+ type: string | undefined;
21
+ }
22
+
23
+ interface ModuleDef {
24
+ items: ItemDef[];
25
+ name: string;
26
+ }
27
+
28
+ const StorageKeyType = 'StorageKey | string | Uint8Array | any';
29
+
30
+ const generateRpcTypesTemplate = Handlebars.compile(readTemplate('rpc'));
31
+
32
+ /** @internal */
33
+ export function generateRpcTypes (registry: TypeRegistry, importDefinitions: Record<string, Definitions>, dest: string, extraTypes: ExtraTypes): void {
34
+ writeFile(dest, (): string => {
35
+ const allTypes: ExtraTypes = { '@pezkuwi/types/interfaces': importDefinitions, ...extraTypes };
36
+ const imports = createImports(allTypes);
37
+ const definitions = imports.definitions as Record<string, Definitions>;
38
+ const allDefs = Object.entries(allTypes).reduce((defs, [path, obj]) => {
39
+ return Object.entries(obj).reduce((defs, [key, value]) => ({ ...defs, [`${path}/${key}`]: value }), defs);
40
+ }, {});
41
+
42
+ const rpcKeys = Object
43
+ .keys(definitions)
44
+ .filter((key) => Object.keys(definitions[key].rpc || {}).length !== 0)
45
+ .sort();
46
+
47
+ const additional: Record<string, ModuleDef> = {};
48
+ const modules = rpcKeys.map((sectionFullName) => {
49
+ const rpc = definitions[sectionFullName].rpc || {};
50
+ const section = sectionFullName.split('/').pop();
51
+
52
+ const allMethods = Object.keys(rpc).sort().map((methodName) => {
53
+ const def = rpc[methodName];
54
+
55
+ let args;
56
+ let type;
57
+ let generic;
58
+
59
+ // These are too hard to type with generics, do manual overrides
60
+ if (section === 'state') {
61
+ setImports(allDefs, imports, ['Codec', 'Hash', 'StorageKey', 'Vec']);
62
+
63
+ if (methodName === 'getStorage') {
64
+ generic = 'T = Codec';
65
+ args = [`key: ${StorageKeyType}, block?: Hash | Uint8Array | string`];
66
+ type = 'T';
67
+ } else if (methodName === 'queryStorage') {
68
+ generic = 'T = Codec[]';
69
+ args = [`keys: Vec<StorageKey> | (${StorageKeyType})[], fromBlock?: Hash | Uint8Array | string, toBlock?: Hash | Uint8Array | string`];
70
+ type = '[Hash, T][]';
71
+ } else if (methodName === 'queryStorageAt') {
72
+ generic = 'T = Codec[]';
73
+ args = [`keys: Vec<StorageKey> | (${StorageKeyType})[], at?: Hash | Uint8Array | string`];
74
+ type = 'T';
75
+ } else if (methodName === 'subscribeStorage') {
76
+ generic = 'T = Codec[]';
77
+ args = [`keys?: Vec<StorageKey> | (${StorageKeyType})[]`];
78
+ type = 'T';
79
+ }
80
+ }
81
+
82
+ if (args === undefined) {
83
+ setImports(allDefs, imports, [def.type]);
84
+
85
+ args = def.params.map((param) => {
86
+ const similarTypes = getSimilarTypes(registry, definitions, param.type, imports);
87
+
88
+ setImports(allDefs, imports, [param.type, ...similarTypes]);
89
+
90
+ return `${param.name}${param.isOptional ? '?' : ''}: ${similarTypes.join(' | ')}`;
91
+ });
92
+
93
+ type = formatType(registry, allDefs, def.type, imports);
94
+ generic = '';
95
+ }
96
+
97
+ const item = {
98
+ args: args.join(', '),
99
+ docs: def.deprecated
100
+ ? [`@deprecated ${def.deprecated}`, def.description]
101
+ : [def.description],
102
+ generic,
103
+ name: methodName,
104
+ type
105
+ };
106
+
107
+ if (def.aliasSection) {
108
+ if (!additional[def.aliasSection]) {
109
+ additional[def.aliasSection] = {
110
+ items: [],
111
+ name: def.aliasSection
112
+ };
113
+ }
114
+
115
+ additional[def.aliasSection].items.push(item);
116
+
117
+ return null;
118
+ }
119
+
120
+ return item;
121
+ }).filter((item): item is ItemDef => !!item);
122
+
123
+ return {
124
+ items: allMethods,
125
+ name: section || 'unknown'
126
+ };
127
+ }).concat(...Object.values(additional)).sort((a, b) => a.name.localeCompare(b.name));
128
+
129
+ imports.typesTypes['Observable'] = true;
130
+
131
+ return generateRpcTypesTemplate({
132
+ headerType: 'chain',
133
+ imports,
134
+ modules,
135
+ types: [
136
+ ...Object.keys(imports.localTypes).sort().map((packagePath): { file: string; types: string[] } => ({
137
+ file: packagePath.replace('@pezkuwi/types-augment', '@pezkuwi/types'),
138
+ types: Object.keys(imports.localTypes[packagePath])
139
+ })),
140
+ {
141
+ file: '@pezkuwi/rpc-core/types',
142
+ types: ['AugmentedRpc']
143
+ }
144
+ ]
145
+ });
146
+ });
147
+ }
148
+
149
+ export function generateDefaultRpc (dest = 'packages/rpc-augment/src/augment/jsonrpc.ts', extraTypes: ExtraTypes = {}): void {
150
+ const { registry } = initMeta(staticBizinikiwi, extraTypes);
151
+
152
+ generateRpcTypes(
153
+ registry,
154
+ defaultDefinitions,
155
+ dest,
156
+ extraTypes
157
+ );
158
+ }
@@ -0,0 +1,293 @@
1
+ // Copyright 2017-2025 @pezkuwi/typegen authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import type { RuntimeApiMethodMetadataV16, SiLookupTypeId } from '@pezkuwi/types/interfaces';
5
+ import type { Metadata } from '@pezkuwi/types/metadata/Metadata';
6
+ import type { DefinitionCall, DefinitionCallNamed, Definitions, DefinitionsCall, Registry } from '@pezkuwi/types/types';
7
+ import type { Vec } from '@pezkuwi/types-codec';
8
+ import type { HexString } from '@pezkuwi/util/types';
9
+
10
+ import Handlebars from 'handlebars';
11
+
12
+ import * as defaultDefs from '@pezkuwi/types/interfaces/definitions';
13
+ import lookupDefinitions from '@pezkuwi/types-augment/lookup/definitions';
14
+ import { objectSpread, stringCamelCase } from '@pezkuwi/util';
15
+ import { blake2AsHex } from '@pezkuwi/util-crypto';
16
+
17
+ import { createImports, formatType, getSimilarTypes, initMeta, readTemplate, rebrandTypeName, setImports, writeFile } from '../util/index.js';
18
+ import { type ExtraTypes, getDeprecationNotice } from './types.js';
19
+
20
+ type Apis = [HexString, number][];
21
+
22
+ const generateCallsTypesTemplate = Handlebars.compile(readTemplate('calls'));
23
+
24
+ // This works similar to the PATHS_ALIAS set from the PortableRegistry
25
+ const aliases: Record<string, string> = {
26
+ AssetHubZagrosRuntimeRuntimeCall: 'RuntimeCall',
27
+ AssetHubPezkuwiRuntimeRuntimeCall: 'RuntimeCall',
28
+ AssetHubDicleRuntimeOriginCaller: 'OriginCaller',
29
+ AssetHubDicleRuntimeRuntimeCall: 'RuntimeCall',
30
+ DicleRuntimeConstantsProxyProxyType: 'ProxyType',
31
+ KitchensinkRuntimeRuntimeCall: 'RuntimeCall',
32
+ KitchensinkRuntimeRuntimeParametersKey: 'RuntimeParametersKey',
33
+ OpaqueValue: 'Bytes',
34
+ PezkuwiTeyrchainPrimitivesPrimitivesId: 'ParaId',
35
+ PezkuwiTeyrchainPrimitivesPrimitivesValidationCodeHash: 'ValidationCodeHash',
36
+ PezkuwiPrimitivesV7SlashingOpaqueKeyOwnershipProof: 'OpaqueKeyOwnershipProof',
37
+ PezkuwiPrimitivesV8SlashingOpaqueKeyOwnershipProof: 'OpaqueKeyOwnershipProof',
38
+ PezkuwiRuntimeRuntimeCall: 'RuntimeCall',
39
+ PrimitiveTypesH160: 'H160',
40
+ PrimitiveTypesH256: 'H256',
41
+ PrimitiveTypesU256: 'U256',
42
+ PezspConsensusBabeOpaqueKeyOwnershipProof: 'OpaqueKeyOwnershipProof',
43
+ PezspConsensusSlotsSlot: 'Slot',
44
+ PezspConsensusSlotsSlotDuration: 'SlotDuration',
45
+ PezspCoreCryptoAccountId32: 'AccountId32',
46
+ PezspCoreOpaqueMetadata: 'OpaqueMetadata',
47
+ PezspRuntimeOpaqueValue: 'Bytes',
48
+ PezspRuntimeUncheckedExtrinsic: 'Extrinsic',
49
+ StagingDicleRuntimeOriginCaller: 'OriginCaller',
50
+ StagingDicleRuntimeRuntimeCall: 'RuntimeCall',
51
+ StagingDicleRuntimeRuntimeParameters: 'RuntimeParameters',
52
+ StagingDicleRuntimeRuntimeParametersKey: 'RuntimeParametersKey',
53
+ StagingZagrosRuntimeRuntimeCall: 'RuntimeCall'
54
+ };
55
+
56
+ const getTypesViaAlias = (registry: Registry, id: SiLookupTypeId) => {
57
+ const rawTypeName = registry.lookup.getName(id) || registry.lookup.getTypeDef(id).type;
58
+ const typeName = rebrandTypeName(rawTypeName);
59
+
60
+ if (aliases[typeName]) {
61
+ return aliases[typeName];
62
+ }
63
+
64
+ return typeName;
65
+ };
66
+
67
+ /** @internal */
68
+ function getMethods (registry: Registry, methods: Vec<RuntimeApiMethodMetadataV16>) {
69
+ const result: Record<string, DefinitionCall> = {};
70
+
71
+ methods.forEach((m) => {
72
+ const { deprecationInfo, docs, inputs, name, output } = m;
73
+ let description = docs.map((d) => d.toString()).join();
74
+
75
+ if (!deprecationInfo.isNotDeprecated) {
76
+ const deprecationNotice = getDeprecationNotice(deprecationInfo, stringCamelCase(name));
77
+ const notice = description.length ? `\n * ${deprecationNotice}` : ` * ${deprecationNotice}`;
78
+
79
+ description += notice;
80
+ }
81
+
82
+ result[name.toString()] = {
83
+ description,
84
+ params: inputs.map(({ name, type }) => {
85
+ return { name: name.toString(), type: getTypesViaAlias(registry, type) };
86
+ }),
87
+ type: getTypesViaAlias(registry, output)
88
+ };
89
+ });
90
+
91
+ return result;
92
+ }
93
+
94
+ /** @internal */
95
+ function getRuntimeDefViaMetadata (registry: Registry) {
96
+ const result: DefinitionsCall = {};
97
+ const { apis } = registry.metadata;
98
+
99
+ for (let i = 0, count = apis.length; i < count; i++) {
100
+ const { methods, name } = apis[i];
101
+
102
+ result[name.toString()] = [{
103
+ methods: getMethods(registry, methods),
104
+ // We set the version to 0 here since it will not be relevant when we are grabbing the runtime apis
105
+ // from the Metadata.
106
+ version: 0
107
+ }];
108
+ }
109
+
110
+ return Object.entries(result);
111
+ }
112
+
113
+ /** @internal */
114
+ function getDefs (apis: Apis | null, defs: Record<string, Definitions>, registry: Registry): Record<string, Record<string, DefinitionCallNamed>> {
115
+ const named: Record<string, Record<string, DefinitionCallNamed>> = {};
116
+ const all = Object.values(defs);
117
+ const isApiInMetadata = registry.metadata.apis.length > 0;
118
+
119
+ if (isApiInMetadata) {
120
+ const sections = getRuntimeDefViaMetadata(registry);
121
+
122
+ for (let j = 0, jcount = sections.length; j < jcount; j++) {
123
+ const [_section, secs] = sections[j];
124
+ const sec = secs[0];
125
+ const sectionHash = blake2AsHex(_section, 64);
126
+
127
+ const section = stringCamelCase(_section);
128
+ const methods = Object.entries(sec.methods);
129
+
130
+ if (!named[section]) {
131
+ named[section] = {};
132
+ }
133
+
134
+ for (let m = 0, mcount = methods.length; m < mcount; m++) {
135
+ const [_method, def] = methods[m];
136
+ const method = stringCamelCase(_method);
137
+
138
+ named[section][method] = objectSpread({ method, name: `${_section}_${_method}`, section, sectionHash }, def);
139
+ }
140
+ }
141
+ } else {
142
+ for (let j = 0, jcount = all.length; j < jcount; j++) {
143
+ const set = all[j].runtime;
144
+
145
+ if (set) {
146
+ const sections = Object.entries(set);
147
+
148
+ for (let i = 0, scount = sections.length; i < scount; i++) {
149
+ const [_section, sec] = sections[i];
150
+ const sectionHash = blake2AsHex(_section, 64);
151
+ const api = apis?.find(([h]) => h === sectionHash);
152
+
153
+ if (api) {
154
+ const ver = sec.find(({ version }) => version === api[1]);
155
+
156
+ if (ver) {
157
+ const methods = Object.entries(ver.methods);
158
+ const mcount = methods.length;
159
+
160
+ if (mcount) {
161
+ const section = stringCamelCase(_section);
162
+
163
+ if (!named[section]) {
164
+ named[section] = {};
165
+ }
166
+
167
+ for (let m = 0; m < mcount; m++) {
168
+ const [_method, def] = methods[m];
169
+ const method = stringCamelCase(_method);
170
+
171
+ named[section][method] = objectSpread({ method, name: `${_section}_${method}`, section, sectionHash, version: ver.version }, def);
172
+ }
173
+ }
174
+ } else {
175
+ console.warn(`Unable to find matching version for runtime ${_section}, expected ${api[1]}`);
176
+ }
177
+ }
178
+ }
179
+ }
180
+ }
181
+ }
182
+
183
+ return named;
184
+ }
185
+
186
+ /** @internal */
187
+ export function generateCallTypes (registry: Registry, meta: Metadata, dest: string, extraTypes: ExtraTypes, isStrict: boolean, customLookupDefinitions?: Definitions): void {
188
+ writeFile(dest, (): string => {
189
+ const allTypes: ExtraTypes = {
190
+ '@pezkuwi/types-augment': {
191
+ lookup: {
192
+ ...lookupDefinitions,
193
+ ...customLookupDefinitions
194
+ }
195
+ },
196
+ '@pezkuwi/types/interfaces': defaultDefs,
197
+ ...extraTypes
198
+ };
199
+ const imports = createImports(allTypes);
200
+
201
+ // find the system.Version in metadata
202
+ let apis: Apis | null = null;
203
+ const sysp = meta.asLatest.pallets.find(({ name }) => name.eq('System'));
204
+
205
+ if (sysp) {
206
+ const verc = sysp.constants.find(({ name }) => name.eq('Version'));
207
+
208
+ if (verc) {
209
+ apis = registry.createType('RuntimeVersion', verc.value).apis.map(([k, v]): [HexString, number] => [k.toHex(), v.toNumber()]);
210
+ } else {
211
+ console.error('Unable to find System.Version pallet, skipping API extraction');
212
+ }
213
+ } else {
214
+ console.error('Unable to find System pallet, skipping API extraction');
215
+ }
216
+
217
+ const allDefs = Object.entries(allTypes).reduce((defs, [path, obj]) => {
218
+ return Object.entries(obj).reduce((defs, [key, value]) => ({ ...defs, [`${path}/${key}`]: value }), defs);
219
+ }, {});
220
+ const definitions = getDefs(apis, imports.definitions as Record<string, Definitions>, registry);
221
+ const callKeys = Object.keys(definitions);
222
+
223
+ const modules = callKeys.map((section) => {
224
+ const calls = definitions[section];
225
+
226
+ const allMethods = Object.keys(calls).sort().map((methodName) => {
227
+ const def = calls[methodName];
228
+
229
+ setImports(allDefs, imports, [def.type]);
230
+
231
+ const args = def.params.map((param) => {
232
+ const similarTypes = getSimilarTypes(registry, imports.definitions, param.type, imports);
233
+
234
+ setImports(allDefs, imports, [param.type, ...similarTypes]);
235
+
236
+ return `${param.name}: ${similarTypes.join(' | ')}`;
237
+ });
238
+
239
+ return {
240
+ args: args.join(', '),
241
+ docs: [def.description],
242
+ name: methodName,
243
+ sectionHash: def.sectionHash,
244
+ sectionName: def.section,
245
+ sectionVersion: def.version,
246
+ type: formatType(registry, allDefs, def.type, imports)
247
+ };
248
+ }).sort((a, b) => a.name.localeCompare(b.name));
249
+
250
+ return {
251
+ items: allMethods,
252
+ name: section || 'unknown',
253
+ sectionHash: allMethods.length && allMethods[0].sectionHash,
254
+ sectionName: allMethods.length && allMethods[0].sectionName,
255
+ sectionVersion: allMethods.length && allMethods[0].sectionVersion
256
+ };
257
+ }).filter(({ items }) => items.length).sort((a, b) => a.name.localeCompare(b.name));
258
+
259
+ if (modules.length) {
260
+ imports.typesTypes['Observable'] = true;
261
+ }
262
+
263
+ return generateCallsTypesTemplate({
264
+ headerType: 'chain',
265
+ imports,
266
+ isStrict,
267
+ modules,
268
+ types: [
269
+ ...Object.keys(imports.localTypes).sort().map((packagePath): { file: string; types: string[] } => ({
270
+ file: packagePath.replace('@pezkuwi/types-augment', '@pezkuwi/types'),
271
+ types: Object.keys(imports.localTypes[packagePath])
272
+ })),
273
+ {
274
+ file: '@pezkuwi/api-base/types',
275
+ types: ['ApiTypes', 'AugmentedCall', 'DecoratedCallBase']
276
+ }
277
+ ]
278
+ });
279
+ });
280
+ }
281
+
282
+ export function generateDefaultRuntime (dest: string, data: HexString, extraTypes: ExtraTypes = {}, isStrict = false, customLookupDefinitions?: Definitions): void {
283
+ const { metadata, registry } = initMeta(data, extraTypes);
284
+
285
+ generateCallTypes(
286
+ registry,
287
+ metadata,
288
+ dest,
289
+ extraTypes,
290
+ isStrict,
291
+ customLookupDefinitions
292
+ );
293
+ }