@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,75 @@
1
+ // Copyright 2017-2025 @pezkuwi/typegen authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import type { VariantDeprecationInfoV16 } from '@pezkuwi/types/interfaces';
5
+ import type { Metadata } from '@pezkuwi/types/metadata/Metadata';
6
+ import type { HexString } from '@pezkuwi/util/types';
7
+
8
+ import Handlebars from 'handlebars';
9
+
10
+ import { stringCamelCase } from '@pezkuwi/util';
11
+
12
+ import { compareName, createImports, initMeta, readTemplate, writeFile } from '../util/index.js';
13
+ import { type ExtraTypes, getDeprecationNotice } from './types.js';
14
+
15
+ const generateForMetaTemplate = Handlebars.compile(readTemplate('errors'));
16
+
17
+ /** @internal */
18
+ function generateForMeta (meta: Metadata, dest: string, isStrict: boolean): void {
19
+ writeFile(dest, (): string => {
20
+ const imports = createImports({});
21
+ const { lookup, pallets } = meta.asLatest;
22
+ const modules = pallets
23
+ .filter(({ errors }) => errors.isSome)
24
+ .map((data) => {
25
+ const name = data.name;
26
+ const errors = data.errors.unwrap();
27
+ const deprecationInfo = errors.deprecationInfo.toJSON();
28
+
29
+ return {
30
+ items: lookup.getSiType(errors.type).def.asVariant.variants
31
+ .map(({ docs, index, name }) => {
32
+ const rawStatus = deprecationInfo?.[index.toNumber()];
33
+
34
+ if (rawStatus) {
35
+ const deprecationVariantInfo: VariantDeprecationInfoV16 = meta.registry.createTypeUnsafe('VariantDeprecationInfoV16', [rawStatus]);
36
+
37
+ const deprecationNotice = getDeprecationNotice(deprecationVariantInfo, name.toString());
38
+ const notice = docs.length ? ['', deprecationNotice] : [deprecationNotice];
39
+
40
+ docs.push(...notice.map((text) => meta.registry.createType('Text', text)));
41
+ }
42
+
43
+ return {
44
+ docs,
45
+ name: name.toString()
46
+ };
47
+ })
48
+ .sort(compareName),
49
+ name: stringCamelCase(name)
50
+ };
51
+ })
52
+ .sort(compareName);
53
+
54
+ return generateForMetaTemplate({
55
+ headerType: 'chain',
56
+ imports,
57
+ isStrict,
58
+ modules,
59
+ types: [
60
+ {
61
+ file: '@pezkuwi/api-base/types',
62
+ types: ['ApiTypes', 'AugmentedError']
63
+ }
64
+ ]
65
+ });
66
+ });
67
+ }
68
+
69
+ // Call `generateForMeta()` with current static metadata
70
+ /** @internal */
71
+ export function generateDefaultErrors (dest: string, data: HexString, extraTypes: ExtraTypes = {}, isStrict = false): void {
72
+ const { metadata } = initMeta(data, extraTypes);
73
+
74
+ return generateForMeta(metadata, dest, isStrict);
75
+ }
@@ -0,0 +1,165 @@
1
+ // Copyright 2017-2025 @pezkuwi/typegen authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import type { VariantDeprecationInfoV16 } from '@pezkuwi/types/interfaces';
5
+ import type { Metadata } from '@pezkuwi/types/metadata/Metadata';
6
+ import type { Definitions } from '@pezkuwi/types/types';
7
+ import type { HexString } from '@pezkuwi/util/types';
8
+
9
+ import Handlebars from 'handlebars';
10
+
11
+ import * as defaultDefs from '@pezkuwi/types/interfaces/definitions';
12
+ import lookupDefinitions from '@pezkuwi/types-augment/lookup/definitions';
13
+ import { stringCamelCase } from '@pezkuwi/util';
14
+
15
+ import { compareName, createImports, formatType, initMeta, readTemplate, rebrandTypeName, setImports, writeFile } from '../util/index.js';
16
+ import { ignoreUnusedLookups } from './lookup.js';
17
+ import { type ExtraTypes, getDeprecationNotice } from './types.js';
18
+
19
+ const generateForMetaTemplate = Handlebars.compile(readTemplate('events'));
20
+
21
+ // For babel itself we need some extra aliasing
22
+ // Also avoid reserved words to prevent generating invalid TS
23
+ // See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Lexical_grammar#reserved_words
24
+ const ALIAS = [
25
+ 'symbol',
26
+ 'break',
27
+ 'case',
28
+ 'catch',
29
+ 'class',
30
+ 'const',
31
+ 'continue',
32
+ 'debugger',
33
+ 'default',
34
+ 'delete',
35
+ 'do',
36
+ 'else',
37
+ 'export',
38
+ 'extends',
39
+ 'false',
40
+ 'finally',
41
+ 'for',
42
+ 'function',
43
+ 'if',
44
+ 'import',
45
+ 'in',
46
+ 'instanceof',
47
+ 'new',
48
+ 'null',
49
+ 'return',
50
+ 'static',
51
+ 'super',
52
+ 'switch',
53
+ 'this',
54
+ 'throw',
55
+ 'true',
56
+ 'try',
57
+ 'typeof',
58
+ 'var',
59
+ 'void',
60
+ 'while',
61
+ 'with',
62
+ 'yield'
63
+ ];
64
+
65
+ /** @internal */
66
+ function generateForMeta (meta: Metadata, dest: string, extraTypes: ExtraTypes, isStrict: boolean, customLookupDefinitions?: Definitions): void {
67
+ writeFile(dest, (): string => {
68
+ const allTypes = {
69
+ '@pezkuwi/types-augment': {
70
+ lookup: {
71
+ ...lookupDefinitions,
72
+ ...customLookupDefinitions
73
+ }
74
+ },
75
+ '@pezkuwi/types/interfaces': defaultDefs,
76
+ ...extraTypes
77
+ };
78
+ const imports = createImports(allTypes);
79
+ const allDefs = Object.entries(allTypes).reduce((defs, [path, obj]) => {
80
+ return Object.entries(obj).reduce((defs, [key, value]) => ({ ...defs, [`${path}/${key}`]: value }), defs);
81
+ }, {});
82
+ const { lookup, pallets, registry } = meta.asLatest;
83
+ const usedTypes = new Set<string>([]);
84
+ const modules = pallets
85
+ .filter(({ events }) => events.isSome)
86
+ .map((data) => {
87
+ const name = data.name;
88
+ const events = data.events.unwrap();
89
+ const deprecationInfo = events.deprecationInfo.toJSON();
90
+
91
+ return {
92
+ items: lookup.getSiType(events.type).def.asVariant.variants
93
+ .map(({ docs, fields, index, name }) => {
94
+ const rawStatus = deprecationInfo?.[index.toNumber()];
95
+
96
+ if (rawStatus) {
97
+ const deprecationVariantInfo: VariantDeprecationInfoV16 = meta.registry.createTypeUnsafe('VariantDeprecationInfoV16', [rawStatus]);
98
+ const deprecationNotice = getDeprecationNotice(deprecationVariantInfo, name.toString());
99
+ const notice = docs.length ? ['', deprecationNotice] : [deprecationNotice];
100
+
101
+ docs.push(...notice.map((text) => meta.registry.createType('Text', text)));
102
+ }
103
+
104
+ const args = fields
105
+ .map(({ type }) => lookup.getTypeDef(type))
106
+ .map((typeDef) => {
107
+ const arg = rebrandTypeName(typeDef.lookupName || '') || formatType(registry, allDefs, typeDef, imports);
108
+
109
+ // Add the type to the list of used types
110
+ if (!(imports.primitiveTypes[arg])) {
111
+ usedTypes.add(arg);
112
+ }
113
+
114
+ return arg;
115
+ });
116
+
117
+ const names = fields
118
+ .map(({ name }) => registry.lookup.sanitizeField(name)[0])
119
+ .filter((n): n is string => !!n);
120
+
121
+ setImports(allDefs, imports, args);
122
+
123
+ return {
124
+ docs,
125
+ name: name.toString(),
126
+ type: names.length !== 0 && names.length === args.length
127
+ ? `[${names.map((n, i) => `${ALIAS.includes(n) ? `${n}_` : n}: ${args[i]}`).join(', ')}], { ${names.map((n, i) => `${n}: ${args[i]}`).join(', ')} }`
128
+ : `[${args.join(', ')}]`
129
+ };
130
+ })
131
+ .sort(compareName),
132
+ name: stringCamelCase(name)
133
+ };
134
+ })
135
+ .sort(compareName);
136
+
137
+ // filter out the unused lookup types from imports
138
+ ignoreUnusedLookups([...usedTypes], imports);
139
+
140
+ return generateForMetaTemplate({
141
+ headerType: 'chain',
142
+ imports,
143
+ isStrict,
144
+ modules,
145
+ types: [
146
+ ...Object.keys(imports.localTypes).sort().map((packagePath): { file: string; types: string[] } => ({
147
+ file: packagePath.replace('@pezkuwi/types-augment', '@pezkuwi/types'),
148
+ types: Object.keys(imports.localTypes[packagePath])
149
+ })),
150
+ {
151
+ file: '@pezkuwi/api-base/types',
152
+ types: ['ApiTypes', 'AugmentedEvent']
153
+ }
154
+ ]
155
+ });
156
+ });
157
+ }
158
+
159
+ // Call `generateForMeta()` with current static metadata
160
+ /** @internal */
161
+ export function generateDefaultEvents (dest: string, data: HexString, extraTypes: ExtraTypes = {}, isStrict = false, customLookupDefinitions?: Definitions): void {
162
+ const { metadata } = initMeta(data, extraTypes);
163
+
164
+ return generateForMeta(metadata, dest, extraTypes, isStrict, customLookupDefinitions);
165
+ }
@@ -0,0 +1,13 @@
1
+ // Copyright 2017-2025 @pezkuwi/typegen authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ export { generateDefaultConsts } from './consts.js';
5
+ export { generateDefaultErrors } from './errors.js';
6
+ export { generateDefaultEvents } from './events.js';
7
+ export { generateDefaultInterface } from './interfaceRegistry.js';
8
+ export { generateDefaultLookup } from './lookup.js';
9
+ export { generateDefaultQuery } from './query.js';
10
+ export { generateDefaultRpc } from './rpc.js';
11
+ export { generateDefaultRuntime } from './runtime.js';
12
+ export { generateDefaultTsDef } from './tsDef.js';
13
+ export { generateDefaultTx } from './tx.js';
@@ -0,0 +1,85 @@
1
+ // Copyright 2017-2025 @pezkuwi/typegen authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import type { ModuleTypes } from '../util/imports.js';
5
+
6
+ import Handlebars from 'handlebars';
7
+
8
+ import { Json, Raw } from '@pezkuwi/types/codec';
9
+ import { TypeRegistry } from '@pezkuwi/types/create';
10
+ import * as defaultDefinitions from '@pezkuwi/types/interfaces/definitions';
11
+ import * as defaultPrimitives from '@pezkuwi/types/primitive';
12
+
13
+ import { createImports, readTemplate, setImports, writeFile } from '../util/index.js';
14
+
15
+ const primitiveClasses = {
16
+ ...defaultPrimitives,
17
+ Json,
18
+ Raw
19
+ };
20
+
21
+ const generateInterfaceTypesTemplate = Handlebars.compile(readTemplate('interfaceRegistry'));
22
+
23
+ /** @internal */
24
+ export function generateInterfaceTypes (importDefinitions: Record<string, Record<string, ModuleTypes>>, dest: string): void {
25
+ const registry = new TypeRegistry();
26
+
27
+ writeFile(dest, (): string => {
28
+ Object.entries(importDefinitions).reduce((acc, def) => Object.assign(acc, def), {});
29
+
30
+ const imports = createImports(importDefinitions);
31
+ const definitions = imports.definitions;
32
+ const items: string[] = [];
33
+
34
+ // first we create imports for our known classes from the API
35
+ Object
36
+ .keys(primitiveClasses)
37
+ .filter((name) => !name.includes('Generic'))
38
+ .forEach((primitiveName): void => {
39
+ setImports(definitions, imports, [primitiveName]);
40
+
41
+ items.push(primitiveName);
42
+ });
43
+
44
+ const existingTypes: Record<string, boolean> = {};
45
+
46
+ // ensure we have everything registered since we will get the definition
47
+ // form the available types (so any unknown should show after this)
48
+ Object.values(definitions).forEach(({ types }) => {
49
+ registry.register(types as Record<string, string>);
50
+ });
51
+
52
+ // create imports for everything that we have available
53
+ Object.values(definitions).forEach(({ types }) => {
54
+ setImports(definitions, imports, Object.keys(types));
55
+
56
+ const uniqueTypes = Object.keys(types).filter((type) => !existingTypes[type]);
57
+
58
+ uniqueTypes.forEach((type): void => {
59
+ existingTypes[type] = true;
60
+
61
+ items.push(type);
62
+ });
63
+ });
64
+
65
+ return generateInterfaceTypesTemplate({
66
+ headerType: 'defs',
67
+ imports,
68
+ items: items.sort((a, b) => a.localeCompare(b)),
69
+ types: [
70
+ ...Object.keys(imports.localTypes).sort().map((packagePath): { file: string; types: string[] } => ({
71
+ file: packagePath,
72
+ types: Object.keys(imports.localTypes[packagePath])
73
+ }))
74
+ ]
75
+ });
76
+ });
77
+ }
78
+
79
+ // Generate `packages/types/src/interfaceRegistry.ts`, the registry of all interfaces
80
+ export function generateDefaultInterface (): void {
81
+ generateInterfaceTypes(
82
+ { '@pezkuwi/types/interfaces': defaultDefinitions },
83
+ 'packages/types-augment/src/registry/interfaces.ts'
84
+ );
85
+ }
@@ -0,0 +1,322 @@
1
+ // Copyright 2017-2025 @pezkuwi/typegen authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import type { PortableType, SiLookupTypeId, SiPath, SiTypeParameter } from '@pezkuwi/types/interfaces';
5
+ import type { PortableRegistry } from '@pezkuwi/types/metadata';
6
+ import type { Registry } from '@pezkuwi/types/types';
7
+ import type { TypeDef } from '@pezkuwi/types-create/types';
8
+ import type { HexString } from '@pezkuwi/util/types';
9
+
10
+ import Handlebars from 'handlebars';
11
+ import path from 'node:path';
12
+
13
+ import * as defaultDefinitions from '@pezkuwi/types/interfaces/definitions';
14
+ import staticAhDicle from '@pezkuwi/types-support/metadata/v15/asset-hub-dicle-hex';
15
+ import staticAhPezkuwi from '@pezkuwi/types-support/metadata/v15/asset-hub-pezkuwi-hex';
16
+ import staticBizinikiwi from '@pezkuwi/types-support/metadata/v15/bizinikiwi-hex';
17
+ import staticDicle from '@pezkuwi/types-support/metadata/v15/dicle-hex';
18
+ import staticPezkuwi from '@pezkuwi/types-support/metadata/v15/pezkuwi-hex';
19
+ import { isString, stringify } from '@pezkuwi/util';
20
+
21
+ import { createImports, exportInterface, initMeta, readTemplate, rebrandTypeName, type TypeImports, writeFile } from '../util/index.js';
22
+ import { typeEncoders } from './tsDef.js';
23
+
24
+ // Deep rebrand TypeDef including all nested sub types
25
+ // isTopLevel indicates whether this is a top-level type (should set name from lookupName) or a sub type (preserve name)
26
+ function deepRebrandTypeDef (typeDef: TypeDef, isTopLevel = true): TypeDef {
27
+ const rebrandedLookupName = typeDef.lookupName ? rebrandTypeName(typeDef.lookupName) : typeDef.lookupName;
28
+
29
+ const rebranded: TypeDef = {
30
+ ...typeDef,
31
+ type: rebrandTypeName(typeDef.type),
32
+ // For top-level types: set name from lookupName (mimics original: typeDef.name = typeDef.lookupName)
33
+ // For sub types (enum variants, struct fields): preserve the original name (field/variant name)
34
+ name: isTopLevel ? (rebrandedLookupName || typeDef.name) : typeDef.name,
35
+ lookupName: rebrandedLookupName,
36
+ lookupNameRoot: typeDef.lookupNameRoot ? rebrandTypeName(typeDef.lookupNameRoot) : typeDef.lookupNameRoot
37
+ };
38
+
39
+ // Recursively rebrand sub types (mark as not top-level)
40
+ if (typeDef.sub) {
41
+ if (Array.isArray(typeDef.sub)) {
42
+ rebranded.sub = typeDef.sub.map((s) => deepRebrandTypeDef(s, false));
43
+ } else {
44
+ rebranded.sub = deepRebrandTypeDef(typeDef.sub, false);
45
+ }
46
+ }
47
+
48
+ return rebranded;
49
+ }
50
+
51
+ // Record<string, >
52
+ interface ParsedDef {
53
+ _set: Record<string, number>;
54
+
55
+ [key: string]: string | Record<string, string> | Record<string, number>;
56
+ }
57
+
58
+ const WITH_TYPEDEF = false;
59
+
60
+ const generateLookupDefsTmpl = Handlebars.compile(readTemplate('lookup/defs'));
61
+ const generateLookupDefsNamedTmpl = Handlebars.compile(readTemplate('lookup/defs-named'));
62
+ const generateLookupIndexTmpl = Handlebars.compile(readTemplate('lookup/index'));
63
+ const generateLookupTypesTmpl = Handlebars.compile(readTemplate('lookup/types'));
64
+ const generateRegistryTmpl = Handlebars.compile(readTemplate('interfaceRegistry'));
65
+
66
+ function generateParamType (registry: Registry, { name, type }: SiTypeParameter): string {
67
+ if (type.isSome) {
68
+ const link = registry.lookup.types[type.unwrap().toNumber()];
69
+
70
+ if (link.type.path.length) {
71
+ return generateTypeDocs(registry, null, link.type.path, link.type.params);
72
+ }
73
+ }
74
+
75
+ return name.toString();
76
+ }
77
+
78
+ function generateTypeDocs (registry: Registry, id: SiLookupTypeId | null, path: SiPath, params: SiTypeParameter[]): string {
79
+ return `${id ? `${registry.createLookupType(id)}${path.length ? ': ' : ''}` : ''}${path.map((p) => p.toString()).join('::')}${params.length ? `<${params.map((p) => generateParamType(registry, p)).join(', ')}>` : ''}`;
80
+ }
81
+
82
+ function formatObject (lines: string[]): string[] {
83
+ const max = lines.length - 1;
84
+
85
+ return [
86
+ '{',
87
+ ...lines.map((l, index) =>
88
+ (l.endsWith(',') || l.endsWith('{') || index === max || lines[index + 1].endsWith('}') || lines[index + 1].endsWith('}'))
89
+ ? l
90
+ : `${l},`
91
+ ),
92
+ '}'
93
+ ];
94
+ }
95
+
96
+ function expandSet (parsed: Record<string, number>): string[] {
97
+ return formatObject(
98
+ Object.entries(parsed).reduce<string[]>((all, [k, v]) => {
99
+ all.push(`${k}: ${v}`);
100
+
101
+ return all;
102
+ }, [])
103
+ );
104
+ }
105
+
106
+ function expandObject (parsed: ParsedDef): string[] {
107
+ if (parsed._set) {
108
+ return expandSet(parsed._set);
109
+ }
110
+
111
+ return formatObject(
112
+ Object.entries(parsed).reduce<string[]>((all, [k, v]) => {
113
+ const inner = isString(v)
114
+ ? expandType(v)
115
+ : Array.isArray(v)
116
+ ? [`[${(v as string[]).map((e) => `'${e}'`).join(', ')}]`]
117
+ : expandObject(v as ParsedDef);
118
+
119
+ inner.forEach((l, index): void => {
120
+ all.push(`${
121
+ index === 0
122
+ ? `${k}: ${l}`
123
+ : `${l}`
124
+ }`);
125
+ });
126
+
127
+ return all;
128
+ }, [])
129
+ );
130
+ }
131
+
132
+ function expandType (encoded: string): string[] {
133
+ if (!encoded.startsWith('{')) {
134
+ return [`'${rebrandTypeName(encoded)}'`];
135
+ }
136
+
137
+ return expandObject(JSON.parse(encoded) as ParsedDef);
138
+ }
139
+
140
+ function expandDefToString ({ lookupNameRoot, type }: TypeDef, indent: number): string {
141
+ if (lookupNameRoot) {
142
+ return `'${rebrandTypeName(lookupNameRoot)}'`;
143
+ }
144
+
145
+ const lines = expandType(type);
146
+ let inc = 0;
147
+
148
+ return lines.map((l, index) => {
149
+ let r: string;
150
+
151
+ if (l.endsWith('{')) {
152
+ r = index === 0
153
+ ? l
154
+ : `${' '.padStart(indent + inc)}${l}`;
155
+ inc += 2;
156
+ } else {
157
+ if (l.endsWith('},') || l.endsWith('}')) {
158
+ inc -= 2;
159
+ }
160
+
161
+ r = index === 0
162
+ ? l
163
+ : `${' '.padStart(indent + inc)}${l}`;
164
+ }
165
+
166
+ return r;
167
+ }).join('\n');
168
+ }
169
+
170
+ function getFilteredTypes (lookup: PortableRegistry, exclude: string[] = []): [PortableType, TypeDef][] {
171
+ const named = lookup.types.filter(({ id }) => !!lookup.getTypeDef(id).lookupName);
172
+ const names = named.map(({ id }) => lookup.getName(id));
173
+
174
+ return named
175
+ .filter((_, index) =>
176
+ !names.some((n, iindex) =>
177
+ index > iindex &&
178
+ n === names[index]
179
+ )
180
+ )
181
+ .map((p): [PortableType, TypeDef] => [p, lookup.getTypeDef(p.id)])
182
+ .filter(([, typeDef]) => !exclude.includes(typeDef.lookupName || '<invalid>'));
183
+ }
184
+
185
+ function generateLookupDefs (registry: Registry, filtered: [PortableType, TypeDef][], destDir: string, subPath?: string): void {
186
+ writeFile(path.join(destDir, `${subPath || 'definitions'}.ts`), (): string => {
187
+ const all = filtered.map(([{ id, type: { params, path } }, typeDef]) => {
188
+ const typeLookup = registry.createLookupType(id);
189
+ const def = expandDefToString(typeDef, subPath ? 2 : 4);
190
+
191
+ return {
192
+ docs: [
193
+ generateTypeDocs(registry, id, path, params),
194
+ WITH_TYPEDEF
195
+ ? `@typeDef ${stringify(typeDef)}`
196
+ : null
197
+ ].filter((d): d is string => !!d),
198
+ type: { def, typeLookup, typeName: typeDef.lookupName ? rebrandTypeName(typeDef.lookupName) : undefined }
199
+ };
200
+ });
201
+ const max = all.length - 1;
202
+
203
+ return (subPath ? generateLookupDefsNamedTmpl : generateLookupDefsTmpl)({
204
+ defs: all.map(({ docs, type }, i) => {
205
+ const { def, typeLookup, typeName } = type;
206
+
207
+ return {
208
+ defs: [
209
+ [typeName || typeLookup, `${def}${i !== max ? ',' : ''}`]
210
+ ].map(([n, t]) => `${n}: ${t}`),
211
+ docs
212
+ };
213
+ }),
214
+ headerType: 'defs'
215
+ });
216
+ });
217
+ }
218
+
219
+ function generateLookupTypes (registry: Registry, filtered: [PortableType, TypeDef][], destDir: string, subPath?: string): void {
220
+ const imports = {
221
+ ...createImports(
222
+ { '@pezkuwi/types/interfaces': defaultDefinitions },
223
+ { types: {} }
224
+ ),
225
+ interfaces: []
226
+ };
227
+ const items = filtered
228
+ .map(([, typeDef]) => {
229
+ // Deep rebrand the type names (including nested sub types) before generating interfaces
230
+ const rebranded = deepRebrandTypeDef(typeDef);
231
+
232
+ return rebranded.lookupNameRoot && rebranded.lookupName
233
+ ? exportInterface(rebranded.lookupIndex, rebranded.lookupName, rebranded.lookupNameRoot)
234
+ : typeEncoders[rebranded.info](registry, imports.definitions, rebranded, imports);
235
+ })
236
+ .filter((t): t is string => !!t)
237
+ .map((t) => t.replace(/\nexport /, '\n'));
238
+
239
+ writeFile(path.join(destDir, `types${subPath ? `-${subPath}` : ''}.ts`), () => generateLookupTypesTmpl({
240
+ headerType: 'defs',
241
+ imports,
242
+ items: items.map((l) =>
243
+ l
244
+ .split('\n')
245
+ .map((l) => l.length ? ` ${l}` : '')
246
+ .join('\n')
247
+ ),
248
+ types: [
249
+ ...Object.keys(imports.localTypes).sort().map((packagePath): { file: string; types: string[] } => ({
250
+ file: packagePath,
251
+ types: Object.keys(imports.localTypes[packagePath])
252
+ }))
253
+ ]
254
+ }), true);
255
+ writeFile(path.join(destDir, 'index.ts'), () => generateLookupIndexTmpl({ headerType: 'defs' }), true);
256
+ }
257
+
258
+ function generateRegistry (_registry: Registry, filtered: [PortableType, TypeDef][], destDir: string, subPath: string): void {
259
+ writeFile(path.join(destDir, `${subPath}.ts`), (): string => {
260
+ const items = filtered
261
+ .map(([, { lookupName }]) => lookupName ? rebrandTypeName(lookupName) : lookupName)
262
+ .filter((n): n is string => !!n)
263
+ .sort()
264
+ .reduce((all: string[], n) => all.includes(n) ? all : all.concat(n), []);
265
+ const imports = createImports({}, { types: {} });
266
+
267
+ imports.lookupTypes = items.reduce((all, n) => ({ ...all, [n]: true }), {});
268
+
269
+ return generateRegistryTmpl({
270
+ headerType: 'defs',
271
+ imports,
272
+ items,
273
+ types: []
274
+ });
275
+ }, true);
276
+ }
277
+
278
+ function generateLookup (destDir: string, entries: [string, HexString][]): void {
279
+ entries.reduce<string[]>((exclude, [subPath, staticMeta]): string[] => {
280
+ const { lookup, registry } = initMeta(staticMeta).metadata.asLatest;
281
+ const filtered = getFilteredTypes(lookup, exclude);
282
+
283
+ generateLookupDefs(registry, filtered, destDir, subPath);
284
+ generateLookupTypes(registry, filtered, destDir, subPath);
285
+ generateRegistry(registry, filtered, destDir, subPath === 'lookup' ? 'registry' : `../registry/${subPath}`);
286
+
287
+ return exclude.concat(
288
+ ...filtered
289
+ .map(([, typeDef]) => typeDef.lookupName)
290
+ .filter((n): n is string => !!n)
291
+ );
292
+ }, []);
293
+ }
294
+
295
+ // Generate `packages/types/src/lookup/*s`, the registry of all lookup types
296
+ export function generateDefaultLookup (destDir = 'packages/types-augment/src/lookup', staticData?: HexString): void {
297
+ generateLookup(
298
+ destDir,
299
+ staticData
300
+ ? [['lookup', staticData]]
301
+ : [
302
+ ['bizinikiwi', staticBizinikiwi],
303
+ ['pezkuwi', staticPezkuwi],
304
+ ['dicle', staticDicle],
305
+ ['assetHubPezkuwi', staticAhPezkuwi],
306
+ ['assetHubDicle', staticAhDicle]
307
+ ]
308
+ );
309
+ }
310
+
311
+ // Based on a list of types, it filters out the lookup types that are not needed.
312
+ export function ignoreUnusedLookups (usedTypes: string[], imports: TypeImports) {
313
+ const usedStringified = usedTypes.toString();
314
+
315
+ const [lookupKey, typeDefinitions] = Object.entries(imports.localTypes).find(([typeModule, _]) => typeModule.includes('/lookup')) || ['', {}];
316
+
317
+ Object.keys(typeDefinitions).forEach((typeDef) => {
318
+ if (!(usedStringified.includes(typeDef))) {
319
+ delete (imports.localTypes[lookupKey])[typeDef];
320
+ }
321
+ });
322
+ }