@pezkuwi/typegen 16.5.18 → 16.5.32

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 (308) hide show
  1. package/{build-tsc-cjs → cjs}/generate/lookup.js +39 -10
  2. package/{build/cjs → cjs}/packageInfo.js +1 -1
  3. package/{build-tsc-cjs → cjs}/util/derived.js +15 -0
  4. package/{build-tsc-cjs → cjs}/util/formatting.js +5 -0
  5. package/generate/lookup.js +39 -10
  6. package/package.json +27 -27
  7. package/{build-tsc-esm/packageInfo.js → packageInfo.js} +1 -1
  8. package/{build/util → util}/derived.js +16 -1
  9. package/{build-tsc-esm/util → util}/formatting.js +5 -0
  10. package/build/LICENSE +0 -201
  11. package/build/README.md +0 -3
  12. package/build/augment.js +0 -2
  13. package/build/bundle.js +0 -2
  14. package/build/cjs/augment.d.ts +0 -2
  15. package/build/cjs/augment.js +0 -4
  16. package/build/cjs/bundle.d.ts +0 -2
  17. package/build/cjs/bundle.js +0 -7
  18. package/build/cjs/extractChain.js +0 -44
  19. package/build/cjs/fromChain.js +0 -95
  20. package/build/cjs/fromDefs.js +0 -82
  21. package/build/cjs/generate/consts.d.ts +0 -5
  22. package/build/cjs/generate/consts.js +0 -91
  23. package/build/cjs/generate/errors.d.ts +0 -4
  24. package/build/cjs/generate/errors.js +0 -59
  25. package/build/cjs/generate/events.d.ts +0 -5
  26. package/build/cjs/generate/events.js +0 -139
  27. package/build/cjs/generate/index.js +0 -23
  28. package/build/cjs/generate/interfaceRegistry.d.ts +0 -4
  29. package/build/cjs/generate/interfaceRegistry.js +0 -64
  30. package/build/cjs/generate/lookup.d.ts +0 -4
  31. package/build/cjs/generate/lookup.js +0 -240
  32. package/build/cjs/generate/query.d.ts +0 -5
  33. package/build/cjs/generate/query.js +0 -140
  34. package/build/cjs/generate/rpc.d.ts +0 -6
  35. package/build/cjs/generate/rpc.js +0 -115
  36. package/build/cjs/generate/runtime.d.ts +0 -7
  37. package/build/cjs/generate/runtime.js +0 -233
  38. package/build/cjs/generate/tsDef.d.ts +0 -16
  39. package/build/cjs/generate/tsDef.js +0 -254
  40. package/build/cjs/generate/tx.d.ts +0 -5
  41. package/build/cjs/generate/tx.js +0 -121
  42. package/build/cjs/generate/types.d.ts +0 -12
  43. package/build/cjs/generate/types.js +0 -16
  44. package/build/cjs/index.js +0 -5
  45. package/build/cjs/interfacesTs.js +0 -28
  46. package/build/cjs/metadataMd.js +0 -652
  47. package/build/cjs/util/assert.js +0 -15
  48. package/build/cjs/util/derived.js +0 -128
  49. package/build/cjs/util/docs.js +0 -10
  50. package/build/cjs/util/file.js +0 -33
  51. package/build/cjs/util/formatting.js +0 -237
  52. package/build/cjs/util/imports.js +0 -126
  53. package/build/cjs/util/index.js +0 -39
  54. package/build/cjs/util/initMeta.js +0 -22
  55. package/build/cjs/util/register.js +0 -10
  56. package/build/cjs/util/wsMeta.js +0 -60
  57. package/build/extractChain.d.ts +0 -1
  58. package/build/extractChain.js +0 -40
  59. package/build/fromChain.d.ts +0 -1
  60. package/build/fromChain.js +0 -91
  61. package/build/fromDefs.d.ts +0 -1
  62. package/build/fromDefs.js +0 -78
  63. package/build/generate/consts.d.ts +0 -5
  64. package/build/generate/consts.js +0 -87
  65. package/build/generate/errors.d.ts +0 -4
  66. package/build/generate/errors.js +0 -55
  67. package/build/generate/events.d.ts +0 -5
  68. package/build/generate/events.js +0 -135
  69. package/build/generate/index.d.ts +0 -10
  70. package/build/generate/index.js +0 -10
  71. package/build/generate/interfaceRegistry.d.ts +0 -4
  72. package/build/generate/interfaceRegistry.js +0 -59
  73. package/build/generate/lookup.d.ts +0 -4
  74. package/build/generate/lookup.js +0 -235
  75. package/build/generate/query.d.ts +0 -5
  76. package/build/generate/query.js +0 -136
  77. package/build/generate/rpc.d.ts +0 -6
  78. package/build/generate/rpc.js +0 -110
  79. package/build/generate/runtime.d.ts +0 -7
  80. package/build/generate/runtime.js +0 -228
  81. package/build/generate/tsDef.d.ts +0 -16
  82. package/build/generate/tsDef.js +0 -246
  83. package/build/generate/tx.d.ts +0 -5
  84. package/build/generate/tx.js +0 -117
  85. package/build/generate/types.d.ts +0 -12
  86. package/build/generate/types.js +0 -13
  87. package/build/index.d.ts +0 -2
  88. package/build/index.js +0 -2
  89. package/build/interfacesTs.d.ts +0 -1
  90. package/build/interfacesTs.js +0 -24
  91. package/build/metadataMd.d.ts +0 -1
  92. package/build/metadataMd.js +0 -648
  93. package/build/package.json +0 -548
  94. package/build/packageDetect.d.ts +0 -1
  95. package/build/packageDetect.js +0 -6
  96. package/build/packageInfo.d.ts +0 -6
  97. package/build/packageInfo.js +0 -1
  98. package/build/scripts/pezkuwi-types-chain-info.mjs +0 -7
  99. package/build/scripts/pezkuwi-types-from-chain.mjs +0 -7
  100. package/build/scripts/pezkuwi-types-from-defs.mjs +0 -7
  101. package/build/scripts/pezkuwi-types-internal-interfaces.mjs +0 -7
  102. package/build/scripts/pezkuwi-types-internal-metadata.mjs +0 -7
  103. package/build/templates/calls.hbs +0 -30
  104. package/build/templates/consts.hbs +0 -28
  105. package/build/templates/docs.hbs +0 -7
  106. package/build/templates/errors.hbs +0 -28
  107. package/build/templates/events.hbs +0 -28
  108. package/build/templates/header.hbs +0 -2
  109. package/build/templates/interfaceRegistry.hbs +0 -15
  110. package/build/templates/lookup/defs-named.hbs +0 -12
  111. package/build/templates/lookup/defs.hbs +0 -15
  112. package/build/templates/lookup/index.hbs +0 -3
  113. package/build/templates/lookup/types.hbs +0 -14
  114. package/build/templates/query.hbs +0 -29
  115. package/build/templates/rpc.hbs +0 -22
  116. package/build/templates/tsDef/index.hbs +0 -3
  117. package/build/templates/tsDef/moduleTypes.hbs +0 -10
  118. package/build/templates/tsDef/types.hbs +0 -7
  119. package/build/templates/tx.hbs +0 -30
  120. package/build/util/assert.d.ts +0 -2
  121. package/build/util/assert.js +0 -10
  122. package/build/util/derived.d.ts +0 -4
  123. package/build/util/docs.d.ts +0 -1
  124. package/build/util/docs.js +0 -6
  125. package/build/util/file.d.ts +0 -2
  126. package/build/util/file.js +0 -28
  127. package/build/util/formatting.d.ts +0 -11
  128. package/build/util/formatting.js +0 -230
  129. package/build/util/imports.d.ts +0 -23
  130. package/build/util/imports.js +0 -121
  131. package/build/util/index.d.ts +0 -16
  132. package/build/util/index.js +0 -34
  133. package/build/util/initMeta.d.ts +0 -12
  134. package/build/util/initMeta.js +0 -19
  135. package/build/util/register.d.ts +0 -4
  136. package/build/util/register.js +0 -7
  137. package/build/util/wsMeta.d.ts +0 -4
  138. package/build/util/wsMeta.js +0 -55
  139. package/build-tsc-cjs/packageDetect.js +0 -8
  140. package/build-tsc-cjs/packageInfo.js +0 -4
  141. package/build-tsc-esm/generate/consts.js +0 -87
  142. package/build-tsc-esm/generate/errors.js +0 -55
  143. package/build-tsc-esm/generate/events.js +0 -135
  144. package/build-tsc-esm/generate/interfaceRegistry.js +0 -59
  145. package/build-tsc-esm/generate/lookup.js +0 -235
  146. package/build-tsc-esm/generate/query.js +0 -136
  147. package/build-tsc-esm/generate/rpc.js +0 -110
  148. package/build-tsc-esm/generate/runtime.js +0 -228
  149. package/build-tsc-esm/generate/tsDef.js +0 -246
  150. package/build-tsc-esm/generate/tx.js +0 -117
  151. package/build-tsc-esm/generate/types.js +0 -13
  152. package/build-tsc-esm/util/derived.js +0 -125
  153. package/src/augment.ts +0 -5
  154. package/src/bundle.ts +0 -5
  155. package/src/extractChain.ts +0 -54
  156. package/src/fromChain.ts +0 -123
  157. package/src/fromDefs.ts +0 -106
  158. package/src/generate/consts.ts +0 -112
  159. package/src/generate/errors.ts +0 -75
  160. package/src/generate/events.ts +0 -165
  161. package/src/generate/index.ts +0 -13
  162. package/src/generate/interfaceRegistry.ts +0 -85
  163. package/src/generate/lookup.ts +0 -322
  164. package/src/generate/query.ts +0 -169
  165. package/src/generate/rpc.ts +0 -158
  166. package/src/generate/runtime.ts +0 -293
  167. package/src/generate/tsDef.ts +0 -321
  168. package/src/generate/tx.ts +0 -152
  169. package/src/generate/types.ts +0 -26
  170. package/src/index.ts +0 -6
  171. package/src/interfacesTs.ts +0 -35
  172. package/src/metadataMd.ts +0 -844
  173. package/src/packageDetect.ts +0 -14
  174. package/src/packageInfo.ts +0 -6
  175. package/src/templates/calls.hbs +0 -30
  176. package/src/templates/consts.hbs +0 -28
  177. package/src/templates/docs.hbs +0 -7
  178. package/src/templates/errors.hbs +0 -28
  179. package/src/templates/events.hbs +0 -28
  180. package/src/templates/header.hbs +0 -2
  181. package/src/templates/interfaceRegistry.hbs +0 -15
  182. package/src/templates/lookup/defs-named.hbs +0 -12
  183. package/src/templates/lookup/defs.hbs +0 -15
  184. package/src/templates/lookup/index.hbs +0 -3
  185. package/src/templates/lookup/types.hbs +0 -14
  186. package/src/templates/query.hbs +0 -29
  187. package/src/templates/rpc.hbs +0 -22
  188. package/src/templates/tsDef/index.hbs +0 -3
  189. package/src/templates/tsDef/moduleTypes.hbs +0 -10
  190. package/src/templates/tsDef/types.hbs +0 -7
  191. package/src/templates/tx.hbs +0 -30
  192. package/src/util/assert.ts +0 -18
  193. package/src/util/derived.spec.ts +0 -58
  194. package/src/util/derived.ts +0 -133
  195. package/src/util/docs.ts +0 -13
  196. package/src/util/file.ts +0 -42
  197. package/src/util/formatting.spec.ts +0 -30
  198. package/src/util/formatting.ts +0 -322
  199. package/src/util/imports.ts +0 -164
  200. package/src/util/index.ts +0 -42
  201. package/src/util/initMeta.ts +0 -37
  202. package/src/util/register.ts +0 -12
  203. package/src/util/wsMeta.ts +0 -70
  204. package/tsconfig.build.json +0 -28
  205. package/tsconfig.build.tsbuildinfo +0 -1
  206. package/tsconfig.scripts.json +0 -19
  207. package/tsconfig.spec.json +0 -17
  208. package/tsconfig.spec.tsbuildinfo +0 -1
  209. /package/{build-tsc/augment.d.ts → augment.d.ts} +0 -0
  210. /package/{build-tsc-esm/augment.js → augment.js} +0 -0
  211. /package/{build-tsc/bundle.d.ts → bundle.d.ts} +0 -0
  212. /package/{build-tsc-esm/bundle.js → bundle.js} +0 -0
  213. /package/{build → cjs}/augment.d.ts +0 -0
  214. /package/{build-tsc-cjs → cjs}/augment.js +0 -0
  215. /package/{build → cjs}/bundle.d.ts +0 -0
  216. /package/{build-tsc-cjs → cjs}/bundle.js +0 -0
  217. /package/{build-tsc → cjs}/extractChain.d.ts +0 -0
  218. /package/{build-tsc-cjs → cjs}/extractChain.js +0 -0
  219. /package/{build-tsc → cjs}/fromChain.d.ts +0 -0
  220. /package/{build-tsc-cjs → cjs}/fromChain.js +0 -0
  221. /package/{build-tsc → cjs}/fromDefs.d.ts +0 -0
  222. /package/{build-tsc-cjs → cjs}/fromDefs.js +0 -0
  223. /package/{build-tsc → cjs}/generate/consts.d.ts +0 -0
  224. /package/{build-tsc-cjs → cjs}/generate/consts.js +0 -0
  225. /package/{build-tsc → cjs}/generate/errors.d.ts +0 -0
  226. /package/{build-tsc-cjs → cjs}/generate/errors.js +0 -0
  227. /package/{build-tsc → cjs}/generate/events.d.ts +0 -0
  228. /package/{build-tsc-cjs → cjs}/generate/events.js +0 -0
  229. /package/{build-tsc → cjs}/generate/index.d.ts +0 -0
  230. /package/{build-tsc-cjs → cjs}/generate/index.js +0 -0
  231. /package/{build-tsc → cjs}/generate/interfaceRegistry.d.ts +0 -0
  232. /package/{build-tsc-cjs → cjs}/generate/interfaceRegistry.js +0 -0
  233. /package/{build-tsc → cjs}/generate/lookup.d.ts +0 -0
  234. /package/{build-tsc → cjs}/generate/query.d.ts +0 -0
  235. /package/{build-tsc-cjs → cjs}/generate/query.js +0 -0
  236. /package/{build-tsc → cjs}/generate/rpc.d.ts +0 -0
  237. /package/{build-tsc-cjs → cjs}/generate/rpc.js +0 -0
  238. /package/{build-tsc → cjs}/generate/runtime.d.ts +0 -0
  239. /package/{build-tsc-cjs → cjs}/generate/runtime.js +0 -0
  240. /package/{build-tsc → cjs}/generate/tsDef.d.ts +0 -0
  241. /package/{build-tsc-cjs → cjs}/generate/tsDef.js +0 -0
  242. /package/{build-tsc → cjs}/generate/tx.d.ts +0 -0
  243. /package/{build-tsc-cjs → cjs}/generate/tx.js +0 -0
  244. /package/{build-tsc → cjs}/generate/types.d.ts +0 -0
  245. /package/{build-tsc-cjs → cjs}/generate/types.js +0 -0
  246. /package/{build-tsc → cjs}/index.d.ts +0 -0
  247. /package/{build-tsc-cjs → cjs}/index.js +0 -0
  248. /package/{build-tsc → cjs}/interfacesTs.d.ts +0 -0
  249. /package/{build-tsc-cjs → cjs}/interfacesTs.js +0 -0
  250. /package/{build-tsc → cjs}/metadataMd.d.ts +0 -0
  251. /package/{build-tsc-cjs → cjs}/metadataMd.js +0 -0
  252. /package/{build/cjs → cjs}/package.json +0 -0
  253. /package/{build-tsc → cjs}/packageDetect.d.ts +0 -0
  254. /package/{build/cjs → cjs}/packageDetect.js +0 -0
  255. /package/{build-tsc → cjs}/packageInfo.d.ts +0 -0
  256. /package/{build-tsc → cjs}/util/assert.d.ts +0 -0
  257. /package/{build-tsc-cjs → cjs}/util/assert.js +0 -0
  258. /package/{build-tsc → cjs}/util/derived.d.ts +0 -0
  259. /package/{build-tsc → cjs}/util/docs.d.ts +0 -0
  260. /package/{build-tsc-cjs → cjs}/util/docs.js +0 -0
  261. /package/{build-tsc → cjs}/util/file.d.ts +0 -0
  262. /package/{build-tsc-cjs → cjs}/util/file.js +0 -0
  263. /package/{build-tsc → cjs}/util/formatting.d.ts +0 -0
  264. /package/{build-tsc → cjs}/util/imports.d.ts +0 -0
  265. /package/{build-tsc-cjs → cjs}/util/imports.js +0 -0
  266. /package/{build-tsc → cjs}/util/index.d.ts +0 -0
  267. /package/{build-tsc-cjs → cjs}/util/index.js +0 -0
  268. /package/{build-tsc → cjs}/util/initMeta.d.ts +0 -0
  269. /package/{build-tsc-cjs → cjs}/util/initMeta.js +0 -0
  270. /package/{build-tsc → cjs}/util/register.d.ts +0 -0
  271. /package/{build-tsc-cjs → cjs}/util/register.js +0 -0
  272. /package/{build-tsc → cjs}/util/wsMeta.d.ts +0 -0
  273. /package/{build-tsc-cjs → cjs}/util/wsMeta.js +0 -0
  274. /package/{build/cjs/extractChain.d.ts → extractChain.d.ts} +0 -0
  275. /package/{build-tsc-esm/extractChain.js → extractChain.js} +0 -0
  276. /package/{build/cjs/fromChain.d.ts → fromChain.d.ts} +0 -0
  277. /package/{build-tsc-esm/fromChain.js → fromChain.js} +0 -0
  278. /package/{build/cjs/fromDefs.d.ts → fromDefs.d.ts} +0 -0
  279. /package/{build-tsc-esm/fromDefs.js → fromDefs.js} +0 -0
  280. /package/{build/cjs/generate → generate}/index.d.ts +0 -0
  281. /package/{build-tsc-esm/generate → generate}/index.js +0 -0
  282. /package/{build/cjs/index.d.ts → index.d.ts} +0 -0
  283. /package/{build-tsc-esm/index.js → index.js} +0 -0
  284. /package/{build/cjs/interfacesTs.d.ts → interfacesTs.d.ts} +0 -0
  285. /package/{build-tsc-esm/interfacesTs.js → interfacesTs.js} +0 -0
  286. /package/{build/cjs/metadataMd.d.ts → metadataMd.d.ts} +0 -0
  287. /package/{build-tsc-esm/metadataMd.js → metadataMd.js} +0 -0
  288. /package/{build/cjs/packageDetect.d.ts → packageDetect.d.ts} +0 -0
  289. /package/{build-tsc-esm/packageDetect.js → packageDetect.js} +0 -0
  290. /package/{build/cjs/packageInfo.d.ts → packageInfo.d.ts} +0 -0
  291. /package/{build/cjs/util → util}/assert.d.ts +0 -0
  292. /package/{build-tsc-esm/util → util}/assert.js +0 -0
  293. /package/{build/cjs/util → util}/derived.d.ts +0 -0
  294. /package/{build/cjs/util → util}/docs.d.ts +0 -0
  295. /package/{build-tsc-esm/util → util}/docs.js +0 -0
  296. /package/{build/cjs/util → util}/file.d.ts +0 -0
  297. /package/{build-tsc-esm/util → util}/file.js +0 -0
  298. /package/{build/cjs/util → util}/formatting.d.ts +0 -0
  299. /package/{build/cjs/util → util}/imports.d.ts +0 -0
  300. /package/{build-tsc-esm/util → util}/imports.js +0 -0
  301. /package/{build/cjs/util → util}/index.d.ts +0 -0
  302. /package/{build-tsc-esm/util → util}/index.js +0 -0
  303. /package/{build/cjs/util → util}/initMeta.d.ts +0 -0
  304. /package/{build-tsc-esm/util → util}/initMeta.js +0 -0
  305. /package/{build/cjs/util → util}/register.d.ts +0 -0
  306. /package/{build-tsc-esm/util → util}/register.js +0 -0
  307. /package/{build/cjs/util → util}/wsMeta.d.ts +0 -0
  308. /package/{build-tsc-esm/util → util}/wsMeta.js +0 -0
@@ -1,125 +0,0 @@
1
- import { GenericAccountId, GenericCall, GenericLookupSource, GenericVote } from '@pezkuwi/types/generic';
2
- import { AllConvictions } from '@pezkuwi/types/interfaces/democracy/definitions';
3
- import { AbstractInt, bool, Compact, Enum, Null, Option, Struct, Tuple, Vec, WrapperKeepOpaque, WrapperOpaque } from '@pezkuwi/types-codec';
4
- import { getTypeDef, TypeDefInfo } from '@pezkuwi/types-create';
5
- import { isChildClass, stringify } from '@pezkuwi/util';
6
- import { formatType } from './formatting.js';
7
- import { setImports } from './imports.js';
8
- function arrayToStrType(arr) {
9
- return `${arr.map((c) => `'${c}'`).join(' | ')}`;
10
- }
11
- const voteConvictions = arrayToStrType(AllConvictions);
12
- /** @internal */
13
- export function getSimilarTypes(registry, definitions, _type, imports) {
14
- const typeParts = _type.split('::');
15
- const type = typeParts[typeParts.length - 1];
16
- const possibleTypes = [formatType(registry, definitions, type, imports)];
17
- if (type === 'Extrinsic') {
18
- setImports(definitions, imports, ['IExtrinsic']);
19
- return ['Extrinsic', 'IExtrinsic', 'string', 'Uint8Array'];
20
- }
21
- else if (type === 'Keys') {
22
- // This one is weird... surely it should popup as a Tuple? (but either way better as defined hex)
23
- return ['Keys', 'string', 'Uint8Array'];
24
- }
25
- else if (type === 'StorageKey') {
26
- // TODO We can do better
27
- return ['StorageKey', 'string', 'Uint8Array', 'any'];
28
- }
29
- else if (type === '()') {
30
- return ['null'];
31
- }
32
- const Clazz = registry.createClass(type);
33
- if (isChildClass(Vec, Clazz)) {
34
- const vecDef = getTypeDef(type);
35
- const subDef = (vecDef.sub);
36
- // this could be that we define a Vec type and refer to it by name
37
- if (subDef) {
38
- if (subDef.info === TypeDefInfo.Plain) {
39
- possibleTypes.push(`(${getSimilarTypes(registry, definitions, subDef.type, imports).join(' | ')})[]`);
40
- }
41
- else if (subDef.info === TypeDefInfo.Tuple) {
42
- const subs = subDef.sub.map(({ type }) => getSimilarTypes(registry, definitions, type, imports).join(' | '));
43
- possibleTypes.push(`([${subs.join(', ')}])[]`);
44
- }
45
- else if (subDef.info === TypeDefInfo.Option || subDef.info === TypeDefInfo.Vec || subDef.info === TypeDefInfo.VecFixed) {
46
- // TODO: Add possibleTypes so imports work
47
- }
48
- else if (subDef.info === TypeDefInfo.Struct) {
49
- // TODO: Add possibleTypes so imports work
50
- }
51
- else {
52
- throw new Error(`Unhandled subtype in Vec, ${stringify(subDef)}`);
53
- }
54
- }
55
- }
56
- else if (isChildClass(Enum, Clazz)) {
57
- const { defKeys, isBasic } = new Clazz(registry);
58
- const keys = defKeys.filter((v) => !v.startsWith('__Unused'));
59
- if (isBasic) {
60
- possibleTypes.push(arrayToStrType(keys), 'number');
61
- }
62
- else {
63
- // TODO We don't really want any here, these should be expanded
64
- possibleTypes.push(...keys.map((k) => `{ ${k}: any }`), 'string');
65
- }
66
- possibleTypes.push('Uint8Array');
67
- }
68
- else if (isChildClass(AbstractInt, Clazz) || isChildClass(Compact, Clazz)) {
69
- possibleTypes.push('AnyNumber', 'Uint8Array');
70
- }
71
- else if (isChildClass(GenericLookupSource, Clazz)) {
72
- possibleTypes.push('Address', 'AccountId', 'AccountIndex', 'LookupSource', 'string', 'Uint8Array');
73
- }
74
- else if (isChildClass(GenericAccountId, Clazz)) {
75
- possibleTypes.push('string', 'Uint8Array');
76
- }
77
- else if (isChildClass(GenericCall, Clazz)) {
78
- possibleTypes.push('IMethod', 'string', 'Uint8Array');
79
- }
80
- else if (isChildClass(bool, Clazz)) {
81
- possibleTypes.push('boolean', 'Uint8Array');
82
- }
83
- else if (isChildClass(Null, Clazz)) {
84
- possibleTypes.push('null');
85
- }
86
- else if (isChildClass(Struct, Clazz)) {
87
- const s = new Clazz(registry);
88
- const obj = s.defKeys.map((key) => `${key}?: any`).join('; ');
89
- possibleTypes.push(`{ ${obj} }`, 'string', 'Uint8Array');
90
- }
91
- else if (isChildClass(Option, Clazz)) {
92
- possibleTypes.push('null', 'Uint8Array');
93
- const optDef = getTypeDef(type);
94
- const subDef = (optDef.sub);
95
- if (subDef) {
96
- possibleTypes.push(...getSimilarTypes(registry, definitions, subDef.type, imports));
97
- }
98
- else {
99
- possibleTypes.push('object', 'string');
100
- }
101
- }
102
- else if (isChildClass(GenericVote, Clazz)) {
103
- possibleTypes.push(`{ aye: boolean; conviction?: ${voteConvictions} | number }`, 'boolean', 'string', 'Uint8Array');
104
- }
105
- else if (isChildClass(WrapperKeepOpaque, Clazz) || isChildClass(WrapperOpaque, Clazz)) {
106
- // TODO inspect container
107
- possibleTypes.push('object', 'string', 'Uint8Array');
108
- }
109
- else if (isChildClass(Uint8Array, Clazz)) {
110
- possibleTypes.push('string', 'Uint8Array');
111
- }
112
- else if (isChildClass(String, Clazz)) {
113
- possibleTypes.push('string');
114
- }
115
- else if (isChildClass(Tuple, Clazz)) {
116
- const tupDef = getTypeDef(type);
117
- const subDef = tupDef.sub;
118
- // this could be that we define a Tuple type and refer to it by name
119
- if (Array.isArray(subDef)) {
120
- const subs = subDef.map(({ type }) => getSimilarTypes(registry, definitions, type, imports).join(' | '));
121
- possibleTypes.push(`[${subs.join(', ')}]`);
122
- }
123
- }
124
- return [...new Set(possibleTypes)];
125
- }
package/src/augment.ts DELETED
@@ -1,5 +0,0 @@
1
- // Copyright 2017-2025 @pezkuwi/typegen authors & contributors
2
- // SPDX-License-Identifier: Apache-2.0
3
-
4
- import '@pezkuwi/api-augment';
5
- import '@pezkuwi/rpc-augment';
package/src/bundle.ts DELETED
@@ -1,5 +0,0 @@
1
- // Copyright 2017-2025 @pezkuwi/typegen authors & contributors
2
- // SPDX-License-Identifier: Apache-2.0
3
-
4
- export { packageInfo } from './packageInfo.js';
5
- export { formatType } from './util/formatting.js';
@@ -1,54 +0,0 @@
1
- // Copyright 2017-2025 @pezkuwi/typegen authors & contributors
2
- // SPDX-License-Identifier: Apache-2.0
3
-
4
- // Connects to the local chain and outputs a re-usable calls-only chain definition in the form
5
- // export default { chain: 'Development', genesisHash: '0x27b6d5e0f4fdce1c4d20b82406f193acacce0c19e0d2c0e7ca47725c2572a06a', ss58Format: 42, tokenDecimals: 0, tokenSymbol: 'UNIT'; metaCalls: 'bWV0...4AAA==' };
6
-
7
- import process from 'node:process';
8
- import yargs from 'yargs';
9
- import { hideBin } from 'yargs/helpers';
10
-
11
- import { ApiPromise, WsProvider } from '@pezkuwi/api';
12
-
13
- /** @internal */
14
- async function run (ws: string): Promise<void> {
15
- const provider = new WsProvider(ws);
16
- const api = await ApiPromise.create({ provider, throwOnConnect: true });
17
- const [chain, props] = await Promise.all([
18
- api.rpc.system.chain(),
19
- api.rpc.system.properties()
20
- ]);
21
-
22
- // output the chain info, for easy re-use
23
- console.error(`// Generated via 'yarn run chain:info ${ws}'\n\nexport default {\n chain: '${chain.toString()}',\n genesisHash: '${api.genesisHash.toHex()}',\n specVersion: ${api.runtimeVersion.specVersion.toNumber()},\n ss58Format: ${props.ss58Format.unwrapOr(42).toString()},\n tokenDecimals: ${props.tokenDecimals.unwrapOr(0).toString()},\n tokenSymbol: '${props.tokenSymbol.unwrapOr('UNIT').toString()}',\n metaCalls: '${Buffer.from(api.runtimeMetadata.asCallsOnly.toU8a()).toString('base64')}'\n};`);
24
-
25
- // show any missing types
26
- api.runtimeMetadata.getUniqTypes(false);
27
- }
28
-
29
- interface ArgV { ws: string }
30
-
31
- export function main (): void {
32
- // retrieve and parse arguments - we do this globally, since this is a single command
33
- const { ws } = yargs(hideBin(process.argv))
34
- .usage('Usage: [options]')
35
- .wrap(120)
36
- .strict()
37
- .options({
38
- ws: {
39
- default: 'ws://127.0.0.1:9944',
40
- description: 'The API endpoint to connect to, e.g. wss://dicle-rpc.pezkuwi.io',
41
- required: true,
42
- type: 'string'
43
- }
44
- }).argv as ArgV;
45
-
46
- run(ws)
47
- .then((): void => {
48
- process.exit(0);
49
- })
50
- .catch((error: Error) => {
51
- console.error('FATAL:', error.message);
52
- process.exit(-1);
53
- });
54
- }
package/src/fromChain.ts DELETED
@@ -1,123 +0,0 @@
1
- // Copyright 2017-2025 @pezkuwi/typegen authors & contributors
2
- // SPDX-License-Identifier: Apache-2.0
3
-
4
- import type { Definitions, DefinitionsTypes } from '@pezkuwi/types/types';
5
- import type { HexString } from '@pezkuwi/util/types';
6
-
7
- import fs from 'node:fs';
8
- import path from 'node:path';
9
- import yargs from 'yargs';
10
- import { hideBin } from 'yargs/helpers';
11
-
12
- import { formatNumber, isHex } from '@pezkuwi/util';
13
-
14
- import { generateDefaultConsts, generateDefaultErrors, generateDefaultEvents, generateDefaultQuery, generateDefaultRpc, generateDefaultRuntime, generateDefaultTx } from './generate/index.js';
15
- import { assertDir, assertFile, getMetadataViaWs, HEADER, writeFile } from './util/index.js';
16
-
17
- async function generate (metaHex: HexString, pkg: string | undefined, output: string, isStrict?: boolean): Promise<void> {
18
- console.log(`Generating from metadata, ${formatNumber((metaHex.length - 2) / 2)} bytes`);
19
-
20
- const outputPath = assertDir(path.join(process.cwd(), output));
21
- let extraTypes: Record<string, any> = {};
22
- let customLookupDefinitions: Definitions = { rpc: {}, types: {} };
23
-
24
- if (pkg) {
25
- try {
26
- const defCont = await import(
27
- assertFile(path.join(outputPath, 'definitions.ts'))
28
- ) as Record<string, any>;
29
-
30
- extraTypes = {
31
- [pkg]: defCont
32
- };
33
- } catch (error) {
34
- console.error('ERROR: No custom definitions found:', (error as Error).message);
35
- }
36
- }
37
-
38
- try {
39
- const lookCont = await import(
40
- assertFile(path.join(outputPath, 'lookup.ts'))
41
- ) as { default: DefinitionsTypes };
42
-
43
- customLookupDefinitions = {
44
- rpc: {},
45
- types: lookCont.default
46
- };
47
- } catch (error) {
48
- console.error('ERROR: No lookup definitions found:', (error as Error).message);
49
- }
50
-
51
- generateDefaultConsts(path.join(outputPath, 'augment-api-consts.ts'), metaHex, extraTypes, isStrict, customLookupDefinitions);
52
- generateDefaultErrors(path.join(outputPath, 'augment-api-errors.ts'), metaHex, extraTypes, isStrict);
53
- generateDefaultEvents(path.join(outputPath, 'augment-api-events.ts'), metaHex, extraTypes, isStrict, customLookupDefinitions);
54
- generateDefaultQuery(path.join(outputPath, 'augment-api-query.ts'), metaHex, extraTypes, isStrict, customLookupDefinitions);
55
- generateDefaultRpc(path.join(outputPath, 'augment-api-rpc.ts'), extraTypes);
56
- generateDefaultRuntime(path.join(outputPath, 'augment-api-runtime.ts'), metaHex, extraTypes, isStrict, customLookupDefinitions);
57
- generateDefaultTx(path.join(outputPath, 'augment-api-tx.ts'), metaHex, extraTypes, isStrict, customLookupDefinitions);
58
-
59
- writeFile(path.join(outputPath, 'augment-api.ts'), (): string =>
60
- [
61
- HEADER('chain'),
62
- ...[
63
- ...['consts', 'errors', 'events', 'query', 'tx', 'rpc', 'runtime']
64
- .filter((key) => !!key)
65
- .map((key) => `./augment-api-${key}.js`)
66
- ].map((path) => `import '${path}';\n`)
67
- ].join('')
68
- );
69
-
70
- process.exit(0);
71
- }
72
-
73
- interface ArgV { endpoint: string; output: string; package?: string; strict?: boolean }
74
-
75
- async function mainPromise (): Promise<void> {
76
- const { endpoint, output, package: pkg, strict: isStrict } = yargs(hideBin(process.argv)).strict().options({
77
- endpoint: {
78
- 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',
79
- required: true,
80
- type: 'string'
81
- },
82
- output: {
83
- description: 'The target directory to write the data to',
84
- required: true,
85
- type: 'string'
86
- },
87
- package: {
88
- description: 'Optional package in output location (for extra definitions)',
89
- type: 'string'
90
- },
91
- strict: {
92
- description: 'Turns on strict mode, no output of catch-all generic versions',
93
- type: 'boolean'
94
- }
95
- }).argv as ArgV;
96
-
97
- let metaHex: HexString;
98
-
99
- if (endpoint.startsWith('wss://') || endpoint.startsWith('ws://')) {
100
- metaHex = await getMetadataViaWs(endpoint);
101
- } else {
102
- metaHex = (
103
- JSON.parse(
104
- fs.readFileSync(assertFile(path.join(process.cwd(), endpoint)), 'utf-8')
105
- ) as { result: HexString }
106
- ).result;
107
-
108
- if (!isHex(metaHex)) {
109
- throw new Error('Invalid metadata file');
110
- }
111
- }
112
-
113
- await generate(metaHex, pkg, output, isStrict);
114
- }
115
-
116
- export function main (): void {
117
- mainPromise().catch((error) => {
118
- console.error();
119
- console.error(error);
120
- console.error();
121
- process.exit(1);
122
- });
123
- }
package/src/fromDefs.ts DELETED
@@ -1,106 +0,0 @@
1
- // Copyright 2017-2025 @pezkuwi/typegen authors & contributors
2
- // SPDX-License-Identifier: Apache-2.0
3
-
4
- import type { HexString } from '@pezkuwi/util/types';
5
-
6
- import fs from 'node:fs';
7
- import path from 'node:path';
8
- import yargs from 'yargs';
9
- import { hideBin } from 'yargs/helpers';
10
-
11
- import * as bizinikiwiDefs from '@pezkuwi/types/interfaces/definitions';
12
- import { isHex } from '@pezkuwi/util';
13
-
14
- import { generateDefaultLookup } from './generate/index.js';
15
- import { generateInterfaceTypes } from './generate/interfaceRegistry.js';
16
- import { generateTsDef } from './generate/tsDef.js';
17
- import { assertDir, assertFile, getMetadataViaWs } from './util/index.js';
18
-
19
- interface ArgV { input: string; package: string; endpoint?: string; }
20
-
21
- async function mainPromise (): Promise<void> {
22
- const { endpoint, input, package: pkg } = yargs(hideBin(process.argv)).strict().options({
23
- endpoint: {
24
- 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',
25
- type: 'string'
26
- },
27
- input: {
28
- description: 'The directory to use for the user definitions',
29
- required: true,
30
- type: 'string'
31
- },
32
- package: {
33
- description: 'The package name & path to use for the user types',
34
- required: true,
35
- type: 'string'
36
- }
37
- }).argv as ArgV;
38
-
39
- const inputPath = assertDir(path.join(process.cwd(), input));
40
- let userDefs: Record<string, any> = {};
41
-
42
- try {
43
- const defCont = await import(
44
- assertFile(path.join(inputPath, 'definitions.ts'))
45
- ) as Record<string, any>;
46
-
47
- userDefs = defCont;
48
- } catch (error) {
49
- console.error('ERROR: Unable to load user definitions:', (error as Error).message);
50
- }
51
-
52
- const userKeys = Object.keys(userDefs);
53
- const filteredBase = Object
54
- .entries(bizinikiwiDefs as Record<string, unknown>)
55
- .filter(([key]) => {
56
- if (userKeys.includes(key)) {
57
- console.warn(`Override found for ${key} in user types, ignoring in @pezkuwi/types`);
58
-
59
- return false;
60
- }
61
-
62
- return true;
63
- })
64
- .reduce((defs: Record<string, any>, [key, value]) => {
65
- defs[key] = value;
66
-
67
- return defs;
68
- }, {});
69
-
70
- const allDefs = {
71
- '@pezkuwi/types/interfaces': filteredBase,
72
- [pkg]: userDefs
73
- };
74
-
75
- generateTsDef(allDefs, inputPath, pkg);
76
- generateInterfaceTypes(allDefs, path.join(inputPath, 'augment-types.ts'));
77
-
78
- if (endpoint) {
79
- let metaHex: HexString;
80
-
81
- if (endpoint.startsWith('wss://') || endpoint.startsWith('ws://')) {
82
- metaHex = await getMetadataViaWs(endpoint);
83
- } else {
84
- metaHex = (
85
- JSON.parse(
86
- fs.readFileSync(assertFile(path.join(process.cwd(), endpoint)), 'utf-8')
87
- ) as { result: HexString }
88
- ).result;
89
-
90
- if (!isHex(metaHex)) {
91
- throw new Error('Invalid metadata file');
92
- }
93
- }
94
-
95
- generateDefaultLookup(inputPath, metaHex);
96
- }
97
- }
98
-
99
- export function main (): void {
100
- mainPromise().catch((error) => {
101
- console.error();
102
- console.error(error);
103
- console.error();
104
- process.exit(1);
105
- });
106
- }
@@ -1,112 +0,0 @@
1
- // Copyright 2017-2025 @pezkuwi/typegen authors & contributors
2
- // SPDX-License-Identifier: Apache-2.0
3
-
4
- import type { Metadata } from '@pezkuwi/types/metadata/Metadata';
5
- import type { Definitions } from '@pezkuwi/types/types';
6
- import type { HexString } from '@pezkuwi/util/types';
7
-
8
- import Handlebars from 'handlebars';
9
-
10
- import * as defaultDefs from '@pezkuwi/types/interfaces/definitions';
11
- import lookupDefinitions from '@pezkuwi/types-augment/lookup/definitions';
12
- import { stringCamelCase } from '@pezkuwi/util';
13
-
14
- import { compareName, createImports, formatType, initMeta, readTemplate, rebrandTypeName, setImports, writeFile } from '../util/index.js';
15
- import { ignoreUnusedLookups } from './lookup.js';
16
- import { type ExtraTypes, getDeprecationNotice } from './types.js';
17
-
18
- const generateForMetaTemplate = Handlebars.compile(readTemplate('consts'));
19
-
20
- /** @internal */
21
- function generateForMeta (meta: Metadata, dest: string, extraTypes: ExtraTypes, isStrict: boolean, customLookupDefinitions?: Definitions): void {
22
- writeFile(dest, (): string => {
23
- const allTypes = {
24
- '@pezkuwi/types-augment': {
25
- lookup: {
26
- ...lookupDefinitions,
27
- ...customLookupDefinitions
28
- }
29
- },
30
- '@pezkuwi/types/interfaces': defaultDefs,
31
- ...extraTypes
32
- };
33
- const imports = createImports(allTypes);
34
- const allDefs = Object.entries(allTypes).reduce((defs, [path, obj]) => {
35
- return Object.entries(obj).reduce((defs, [key, value]) => ({ ...defs, [`${path}/${key}`]: value }), defs);
36
- }, {});
37
- const { lookup, pallets, registry } = meta.asLatest;
38
- const usedTypes = new Set<string>([]);
39
-
40
- const modules = pallets
41
- .filter(({ constants }) => constants.length > 0)
42
- .map(({ constants, name }) => {
43
- if (!isStrict) {
44
- setImports(allDefs, imports, ['Codec']);
45
- }
46
-
47
- const items = constants
48
- .map(({ deprecationInfo, docs, name, type }) => {
49
- const typeDef = lookup.getTypeDef(type);
50
- const returnType = rebrandTypeName(typeDef.lookupName || '') || formatType(registry, allDefs, typeDef, imports);
51
-
52
- if (!deprecationInfo.isNotDeprecated) {
53
- const deprecationNotice = getDeprecationNotice(deprecationInfo, stringCamelCase(name), 'Constant');
54
-
55
- const items = docs.length
56
- ? ['', deprecationNotice]
57
- : [deprecationNotice];
58
-
59
- docs.push(...items.map((text) => registry.createType('Text', text)));
60
- }
61
-
62
- // Add the type to the list of used types
63
- if (!(imports.primitiveTypes[returnType])) {
64
- usedTypes.add(returnType);
65
- }
66
-
67
- setImports(allDefs, imports, [returnType]);
68
-
69
- return {
70
- docs,
71
- name: stringCamelCase(name),
72
- type: returnType
73
- };
74
- })
75
- .sort(compareName);
76
-
77
- return {
78
- items,
79
- name: stringCamelCase(name)
80
- };
81
- })
82
- .sort(compareName);
83
-
84
- // filter out the unused lookup types from imports
85
- ignoreUnusedLookups([...usedTypes], imports);
86
-
87
- return generateForMetaTemplate({
88
- headerType: 'chain',
89
- imports,
90
- isStrict,
91
- modules,
92
- types: [
93
- ...Object.keys(imports.localTypes).sort().map<{ file: string; types: string[] }>((packagePath) => ({
94
- file: packagePath.replace('@pezkuwi/types-augment', '@pezkuwi/types'),
95
- types: Object.keys(imports.localTypes[packagePath])
96
- })),
97
- {
98
- file: '@pezkuwi/api-base/types',
99
- types: ['ApiTypes', 'AugmentedConst']
100
- }
101
- ]
102
- });
103
- });
104
- }
105
-
106
- // Call `generateForMeta()` with current static metadata
107
- /** @internal */
108
- export function generateDefaultConsts (dest: string, data: HexString, extraTypes: ExtraTypes = {}, isStrict = false, customLookupDefinitions?: Definitions): void {
109
- const { metadata } = initMeta(data, extraTypes);
110
-
111
- return generateForMeta(metadata, dest, extraTypes, isStrict, customLookupDefinitions);
112
- }
@@ -1,75 +0,0 @@
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
- }