@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,165 +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 { 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
- }
@@ -1,13 +0,0 @@
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';
@@ -1,85 +0,0 @@
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
- }
@@ -1,322 +0,0 @@
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
- }