@pezkuwi/api 16.5.5 → 16.5.8

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 (498) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +12 -12
  3. package/augment.d.ts +1 -0
  4. package/augment.js +1 -0
  5. package/base/Decorate.d.ts +143 -0
  6. package/base/Decorate.js +752 -0
  7. package/base/Events.d.ts +67 -0
  8. package/base/Events.js +78 -0
  9. package/base/Getters.d.ts +163 -0
  10. package/base/Getters.js +207 -0
  11. package/base/Init.d.ts +44 -0
  12. package/base/Init.js +400 -0
  13. package/base/find.d.ts +3 -0
  14. package/base/find.js +7 -0
  15. package/base/index.d.ts +47 -0
  16. package/base/index.js +57 -0
  17. package/base/types.d.ts +15 -0
  18. package/base/types.js +1 -0
  19. package/build/LICENSE +201 -0
  20. package/build/README.md +100 -0
  21. package/build/augment.js +1 -0
  22. package/build/base/Decorate.js +752 -0
  23. package/build/base/Events.js +78 -0
  24. package/build/base/Getters.js +207 -0
  25. package/build/base/Init.js +400 -0
  26. package/build/base/find.js +7 -0
  27. package/build/base/index.d.ts +1 -1
  28. package/build/base/index.js +57 -0
  29. package/build/base/types.js +1 -0
  30. package/build/bundle-pezkuwi-api.js +26247 -0
  31. package/build/bundle.js +7 -0
  32. package/build/cjs/augment.d.ts +1 -0
  33. package/build/cjs/augment.js +3 -0
  34. package/build/cjs/base/Decorate.d.ts +143 -0
  35. package/build/cjs/base/Decorate.js +756 -0
  36. package/build/cjs/base/Events.d.ts +67 -0
  37. package/build/cjs/base/Events.js +82 -0
  38. package/build/cjs/base/Getters.d.ts +163 -0
  39. package/build/cjs/base/Getters.js +211 -0
  40. package/build/cjs/base/Init.d.ts +44 -0
  41. package/build/cjs/base/Init.js +404 -0
  42. package/build/cjs/base/find.d.ts +3 -0
  43. package/build/cjs/base/find.js +11 -0
  44. package/build/cjs/base/index.d.ts +47 -0
  45. package/build/cjs/base/index.js +61 -0
  46. package/build/cjs/base/types.d.ts +15 -0
  47. package/build/cjs/base/types.js +2 -0
  48. package/build/cjs/bundle.d.ts +7 -0
  49. package/build/cjs/bundle.js +17 -0
  50. package/build/cjs/index.d.ts +2 -0
  51. package/build/cjs/index.js +5 -0
  52. package/build/cjs/package.json +3 -0
  53. package/build/cjs/packageDetect.d.ts +1 -0
  54. package/build/cjs/packageDetect.js +10 -0
  55. package/build/cjs/packageInfo.d.ts +6 -0
  56. package/build/cjs/packageInfo.js +4 -0
  57. package/build/cjs/promise/Api.d.ts +158 -0
  58. package/build/cjs/promise/Api.js +195 -0
  59. package/build/cjs/promise/Combinator.d.ts +12 -0
  60. package/build/cjs/promise/Combinator.js +72 -0
  61. package/build/cjs/promise/decorateMethod.d.ts +14 -0
  62. package/build/cjs/promise/decorateMethod.js +75 -0
  63. package/build/cjs/promise/index.d.ts +2 -0
  64. package/build/cjs/promise/index.js +7 -0
  65. package/build/cjs/promise/types.d.ts +5 -0
  66. package/build/cjs/promise/types.js +2 -0
  67. package/build/cjs/rx/Api.d.ts +155 -0
  68. package/build/cjs/rx/Api.js +173 -0
  69. package/build/cjs/rx/decorateMethod.d.ts +3 -0
  70. package/build/cjs/rx/decorateMethod.js +6 -0
  71. package/build/cjs/rx/index.d.ts +2 -0
  72. package/build/cjs/rx/index.js +7 -0
  73. package/build/cjs/submittable/Result.d.ts +31 -0
  74. package/build/cjs/submittable/Result.js +84 -0
  75. package/build/cjs/submittable/createClass.d.ts +12 -0
  76. package/build/cjs/submittable/createClass.js +277 -0
  77. package/build/cjs/submittable/createSubmittable.d.ts +8 -0
  78. package/build/cjs/submittable/createSubmittable.js +8 -0
  79. package/build/cjs/submittable/index.d.ts +2 -0
  80. package/build/cjs/submittable/index.js +7 -0
  81. package/build/cjs/submittable/types.d.ts +1 -0
  82. package/build/cjs/submittable/types.js +2 -0
  83. package/build/cjs/types/calls.d.ts +1 -0
  84. package/build/cjs/types/calls.js +4 -0
  85. package/build/cjs/types/consts.d.ts +1 -0
  86. package/build/cjs/types/consts.js +4 -0
  87. package/build/cjs/types/errors.d.ts +1 -0
  88. package/build/cjs/types/errors.js +4 -0
  89. package/build/cjs/types/events.d.ts +1 -0
  90. package/build/cjs/types/events.js +4 -0
  91. package/build/cjs/types/index.d.ts +114 -0
  92. package/build/cjs/types/index.js +13 -0
  93. package/build/cjs/types/storage.d.ts +1 -0
  94. package/build/cjs/types/storage.js +4 -0
  95. package/build/cjs/types/submittable.d.ts +1 -0
  96. package/build/cjs/types/submittable.js +4 -0
  97. package/build/cjs/util/augmentObject.d.ts +9 -0
  98. package/build/cjs/util/augmentObject.js +84 -0
  99. package/build/cjs/util/decorate.d.ts +16 -0
  100. package/build/cjs/util/decorate.js +17 -0
  101. package/build/cjs/util/filterEvents.d.ts +6 -0
  102. package/build/cjs/util/filterEvents.js +25 -0
  103. package/build/cjs/util/index.d.ts +4 -0
  104. package/build/cjs/util/index.js +11 -0
  105. package/build/cjs/util/isKeyringPair.d.ts +3 -0
  106. package/build/cjs/util/isKeyringPair.js +7 -0
  107. package/build/cjs/util/logging.d.ts +1 -0
  108. package/build/cjs/util/logging.js +5 -0
  109. package/build/cjs/util/validate.d.ts +3 -0
  110. package/build/cjs/util/validate.js +26 -0
  111. package/build/index.js +2 -0
  112. package/build/package.json +612 -0
  113. package/build/packageDetect.js +8 -0
  114. package/build/packageInfo.js +1 -0
  115. package/build/promise/Api.d.ts +2 -2
  116. package/build/promise/Api.js +191 -0
  117. package/build/promise/Combinator.js +68 -0
  118. package/build/promise/decorateMethod.js +71 -0
  119. package/build/promise/index.js +2 -0
  120. package/build/promise/types.js +1 -0
  121. package/build/rx/Api.d.ts +2 -2
  122. package/build/rx/Api.js +169 -0
  123. package/build/rx/decorateMethod.js +3 -0
  124. package/build/rx/index.js +2 -0
  125. package/build/submittable/Result.js +80 -0
  126. package/build/submittable/createClass.js +274 -0
  127. package/build/submittable/createSubmittable.js +5 -0
  128. package/build/submittable/index.js +2 -0
  129. package/build/submittable/types.js +1 -0
  130. package/build/types/calls.js +1 -0
  131. package/build/types/consts.js +1 -0
  132. package/build/types/errors.js +1 -0
  133. package/build/types/events.js +1 -0
  134. package/build/types/index.js +8 -0
  135. package/build/types/storage.js +1 -0
  136. package/build/types/submittable.js +1 -0
  137. package/build/util/augmentObject.js +81 -0
  138. package/build/util/decorate.js +14 -0
  139. package/build/util/filterEvents.js +22 -0
  140. package/build/util/index.js +4 -0
  141. package/build/util/isKeyringPair.js +4 -0
  142. package/build/util/logging.js +2 -0
  143. package/build/util/validate.js +23 -0
  144. package/build-deno/README.md +95 -0
  145. package/build-deno/augment.ts +2 -0
  146. package/build-deno/base/Decorate.ts +1100 -0
  147. package/build-deno/base/Events.ts +89 -0
  148. package/build-deno/base/Getters.ts +243 -0
  149. package/build-deno/base/Init.ts +523 -0
  150. package/build-deno/base/find.ts +12 -0
  151. package/build-deno/base/index.ts +83 -0
  152. package/build-deno/base/types.ts +17 -0
  153. package/build-deno/bundle.ts +11 -0
  154. package/build-deno/checkTypes.manual.ts +320 -0
  155. package/build-deno/index.ts +4 -0
  156. package/build-deno/mod.ts +2 -0
  157. package/build-deno/packageDetect.ts +12 -0
  158. package/build-deno/packageInfo.ts +3 -0
  159. package/build-deno/promise/Api.ts +212 -0
  160. package/build-deno/promise/Combinator.ts +89 -0
  161. package/build-deno/promise/decorateMethod.ts +111 -0
  162. package/build-deno/promise/index.ts +3 -0
  163. package/build-deno/promise/types.ts +7 -0
  164. package/build-deno/rx/Api.ts +184 -0
  165. package/build-deno/rx/decorateMethod.ts +7 -0
  166. package/build-deno/rx/index.ts +3 -0
  167. package/build-deno/submittable/Result.ts +109 -0
  168. package/build-deno/submittable/createClass.ts +436 -0
  169. package/build-deno/submittable/createSubmittable.ts +17 -0
  170. package/build-deno/submittable/index.ts +3 -0
  171. package/build-deno/submittable/types.ts +2 -0
  172. package/build-deno/test/SingleAccountSigner.ts +51 -0
  173. package/build-deno/test/index.ts +3 -0
  174. package/build-deno/test/logEvents.ts +21 -0
  175. package/build-deno/types/calls.ts +2 -0
  176. package/build-deno/types/consts.ts +2 -0
  177. package/build-deno/types/errors.ts +2 -0
  178. package/build-deno/types/events.ts +2 -0
  179. package/build-deno/types/index.ts +124 -0
  180. package/build-deno/types/storage.ts +2 -0
  181. package/build-deno/types/submittable.ts +2 -0
  182. package/build-deno/util/augmentObject.ts +109 -0
  183. package/build-deno/util/decorate.ts +38 -0
  184. package/build-deno/util/filterEvents.ts +32 -0
  185. package/build-deno/util/index.ts +6 -0
  186. package/build-deno/util/isKeyringPair.ts +9 -0
  187. package/build-deno/util/logging.ts +4 -0
  188. package/build-deno/util/validate.ts +32 -0
  189. package/build-tsc/augment.d.ts +1 -0
  190. package/build-tsc/base/Decorate.d.ts +143 -0
  191. package/build-tsc/base/Events.d.ts +67 -0
  192. package/build-tsc/base/Getters.d.ts +163 -0
  193. package/build-tsc/base/Init.d.ts +44 -0
  194. package/build-tsc/base/find.d.ts +3 -0
  195. package/build-tsc/base/index.d.ts +47 -0
  196. package/build-tsc/base/types.d.ts +15 -0
  197. package/build-tsc/bundle.d.ts +7 -0
  198. package/build-tsc/index.d.ts +2 -0
  199. package/build-tsc/packageDetect.d.ts +1 -0
  200. package/build-tsc/packageInfo.d.ts +6 -0
  201. package/build-tsc/promise/Api.d.ts +158 -0
  202. package/build-tsc/promise/Combinator.d.ts +12 -0
  203. package/build-tsc/promise/decorateMethod.d.ts +14 -0
  204. package/build-tsc/promise/index.d.ts +2 -0
  205. package/build-tsc/promise/types.d.ts +5 -0
  206. package/build-tsc/rx/Api.d.ts +155 -0
  207. package/build-tsc/rx/decorateMethod.d.ts +3 -0
  208. package/build-tsc/rx/index.d.ts +2 -0
  209. package/build-tsc/submittable/Result.d.ts +31 -0
  210. package/build-tsc/submittable/createClass.d.ts +12 -0
  211. package/build-tsc/submittable/createSubmittable.d.ts +8 -0
  212. package/build-tsc/submittable/index.d.ts +2 -0
  213. package/build-tsc/submittable/types.d.ts +1 -0
  214. package/build-tsc/types/calls.d.ts +1 -0
  215. package/build-tsc/types/consts.d.ts +1 -0
  216. package/build-tsc/types/errors.d.ts +1 -0
  217. package/build-tsc/types/events.d.ts +1 -0
  218. package/build-tsc/types/index.d.ts +114 -0
  219. package/build-tsc/types/storage.d.ts +1 -0
  220. package/build-tsc/types/submittable.d.ts +1 -0
  221. package/build-tsc/util/augmentObject.d.ts +9 -0
  222. package/build-tsc/util/decorate.d.ts +16 -0
  223. package/build-tsc/util/filterEvents.d.ts +6 -0
  224. package/build-tsc/util/index.d.ts +4 -0
  225. package/build-tsc/util/isKeyringPair.d.ts +3 -0
  226. package/build-tsc/util/logging.d.ts +1 -0
  227. package/build-tsc/util/validate.d.ts +3 -0
  228. package/build-tsc-cjs/augment.js +3 -0
  229. package/build-tsc-cjs/base/Decorate.js +756 -0
  230. package/build-tsc-cjs/base/Events.js +82 -0
  231. package/build-tsc-cjs/base/Getters.js +211 -0
  232. package/build-tsc-cjs/base/Init.js +404 -0
  233. package/build-tsc-cjs/base/find.js +11 -0
  234. package/build-tsc-cjs/base/index.js +61 -0
  235. package/build-tsc-cjs/base/types.js +2 -0
  236. package/build-tsc-cjs/bundle.js +17 -0
  237. package/build-tsc-cjs/index.js +5 -0
  238. package/build-tsc-cjs/packageDetect.js +10 -0
  239. package/build-tsc-cjs/packageInfo.js +4 -0
  240. package/build-tsc-cjs/promise/Api.js +195 -0
  241. package/build-tsc-cjs/promise/Combinator.js +72 -0
  242. package/build-tsc-cjs/promise/decorateMethod.js +75 -0
  243. package/build-tsc-cjs/promise/index.js +7 -0
  244. package/build-tsc-cjs/promise/types.js +2 -0
  245. package/build-tsc-cjs/rx/Api.js +173 -0
  246. package/build-tsc-cjs/rx/decorateMethod.js +6 -0
  247. package/build-tsc-cjs/rx/index.js +7 -0
  248. package/build-tsc-cjs/submittable/Result.js +84 -0
  249. package/build-tsc-cjs/submittable/createClass.js +277 -0
  250. package/build-tsc-cjs/submittable/createSubmittable.js +8 -0
  251. package/build-tsc-cjs/submittable/index.js +7 -0
  252. package/build-tsc-cjs/submittable/types.js +2 -0
  253. package/build-tsc-cjs/types/calls.js +4 -0
  254. package/build-tsc-cjs/types/consts.js +4 -0
  255. package/build-tsc-cjs/types/errors.js +4 -0
  256. package/build-tsc-cjs/types/events.js +4 -0
  257. package/build-tsc-cjs/types/index.js +13 -0
  258. package/build-tsc-cjs/types/storage.js +4 -0
  259. package/build-tsc-cjs/types/submittable.js +4 -0
  260. package/build-tsc-cjs/util/augmentObject.js +84 -0
  261. package/build-tsc-cjs/util/decorate.js +17 -0
  262. package/build-tsc-cjs/util/filterEvents.js +25 -0
  263. package/build-tsc-cjs/util/index.js +11 -0
  264. package/build-tsc-cjs/util/isKeyringPair.js +7 -0
  265. package/build-tsc-cjs/util/logging.js +5 -0
  266. package/build-tsc-cjs/util/validate.js +26 -0
  267. package/build-tsc-esm/augment.js +1 -0
  268. package/build-tsc-esm/base/Decorate.js +752 -0
  269. package/build-tsc-esm/base/Events.js +78 -0
  270. package/build-tsc-esm/base/Getters.js +207 -0
  271. package/build-tsc-esm/base/Init.js +400 -0
  272. package/build-tsc-esm/base/find.js +7 -0
  273. package/build-tsc-esm/base/index.js +57 -0
  274. package/build-tsc-esm/base/types.js +1 -0
  275. package/build-tsc-esm/bundle.js +7 -0
  276. package/build-tsc-esm/index.js +2 -0
  277. package/build-tsc-esm/packageDetect.js +8 -0
  278. package/build-tsc-esm/packageInfo.js +1 -0
  279. package/build-tsc-esm/promise/Api.js +191 -0
  280. package/build-tsc-esm/promise/Combinator.js +68 -0
  281. package/build-tsc-esm/promise/decorateMethod.js +71 -0
  282. package/build-tsc-esm/promise/index.js +2 -0
  283. package/build-tsc-esm/promise/types.js +1 -0
  284. package/build-tsc-esm/rx/Api.js +169 -0
  285. package/build-tsc-esm/rx/decorateMethod.js +3 -0
  286. package/build-tsc-esm/rx/index.js +2 -0
  287. package/build-tsc-esm/submittable/Result.js +80 -0
  288. package/build-tsc-esm/submittable/createClass.js +274 -0
  289. package/build-tsc-esm/submittable/createSubmittable.js +5 -0
  290. package/build-tsc-esm/submittable/index.js +2 -0
  291. package/build-tsc-esm/submittable/types.js +1 -0
  292. package/build-tsc-esm/types/calls.js +1 -0
  293. package/build-tsc-esm/types/consts.js +1 -0
  294. package/build-tsc-esm/types/errors.js +1 -0
  295. package/build-tsc-esm/types/events.js +1 -0
  296. package/build-tsc-esm/types/index.js +8 -0
  297. package/build-tsc-esm/types/storage.js +1 -0
  298. package/build-tsc-esm/types/submittable.js +1 -0
  299. package/build-tsc-esm/util/augmentObject.js +81 -0
  300. package/build-tsc-esm/util/decorate.js +14 -0
  301. package/build-tsc-esm/util/filterEvents.js +22 -0
  302. package/build-tsc-esm/util/index.js +4 -0
  303. package/build-tsc-esm/util/isKeyringPair.js +4 -0
  304. package/build-tsc-esm/util/logging.js +2 -0
  305. package/build-tsc-esm/util/validate.js +23 -0
  306. package/bundle-pezkuwi-api.js +26247 -0
  307. package/bundle.d.ts +7 -0
  308. package/bundle.js +7 -0
  309. package/cjs/augment.d.ts +1 -0
  310. package/cjs/augment.js +3 -0
  311. package/cjs/base/Decorate.d.ts +143 -0
  312. package/cjs/base/Decorate.js +756 -0
  313. package/cjs/base/Events.d.ts +67 -0
  314. package/cjs/base/Events.js +82 -0
  315. package/cjs/base/Getters.d.ts +163 -0
  316. package/cjs/base/Getters.js +211 -0
  317. package/cjs/base/Init.d.ts +44 -0
  318. package/cjs/base/Init.js +404 -0
  319. package/cjs/base/find.d.ts +3 -0
  320. package/cjs/base/find.js +11 -0
  321. package/cjs/base/index.d.ts +47 -0
  322. package/cjs/base/index.js +61 -0
  323. package/cjs/base/types.d.ts +15 -0
  324. package/cjs/base/types.js +2 -0
  325. package/cjs/bundle.d.ts +7 -0
  326. package/cjs/bundle.js +17 -0
  327. package/cjs/index.d.ts +2 -0
  328. package/cjs/index.js +5 -0
  329. package/cjs/package.json +3 -0
  330. package/cjs/packageDetect.d.ts +1 -0
  331. package/cjs/packageDetect.js +10 -0
  332. package/cjs/packageInfo.d.ts +6 -0
  333. package/cjs/packageInfo.js +4 -0
  334. package/cjs/promise/Api.d.ts +158 -0
  335. package/cjs/promise/Api.js +195 -0
  336. package/cjs/promise/Combinator.d.ts +12 -0
  337. package/cjs/promise/Combinator.js +72 -0
  338. package/cjs/promise/decorateMethod.d.ts +14 -0
  339. package/cjs/promise/decorateMethod.js +75 -0
  340. package/cjs/promise/index.d.ts +2 -0
  341. package/cjs/promise/index.js +7 -0
  342. package/cjs/promise/types.d.ts +5 -0
  343. package/cjs/promise/types.js +2 -0
  344. package/cjs/rx/Api.d.ts +155 -0
  345. package/cjs/rx/Api.js +173 -0
  346. package/cjs/rx/decorateMethod.d.ts +3 -0
  347. package/cjs/rx/decorateMethod.js +6 -0
  348. package/cjs/rx/index.d.ts +2 -0
  349. package/cjs/rx/index.js +7 -0
  350. package/cjs/submittable/Result.d.ts +31 -0
  351. package/cjs/submittable/Result.js +84 -0
  352. package/cjs/submittable/createClass.d.ts +12 -0
  353. package/cjs/submittable/createClass.js +277 -0
  354. package/cjs/submittable/createSubmittable.d.ts +8 -0
  355. package/cjs/submittable/createSubmittable.js +8 -0
  356. package/cjs/submittable/index.d.ts +2 -0
  357. package/cjs/submittable/index.js +7 -0
  358. package/cjs/submittable/types.d.ts +1 -0
  359. package/cjs/submittable/types.js +2 -0
  360. package/cjs/types/calls.d.ts +1 -0
  361. package/cjs/types/calls.js +4 -0
  362. package/cjs/types/consts.d.ts +1 -0
  363. package/cjs/types/consts.js +4 -0
  364. package/cjs/types/errors.d.ts +1 -0
  365. package/cjs/types/errors.js +4 -0
  366. package/cjs/types/events.d.ts +1 -0
  367. package/cjs/types/events.js +4 -0
  368. package/cjs/types/index.d.ts +114 -0
  369. package/cjs/types/index.js +13 -0
  370. package/cjs/types/storage.d.ts +1 -0
  371. package/cjs/types/storage.js +4 -0
  372. package/cjs/types/submittable.d.ts +1 -0
  373. package/cjs/types/submittable.js +4 -0
  374. package/cjs/util/augmentObject.d.ts +9 -0
  375. package/cjs/util/augmentObject.js +84 -0
  376. package/cjs/util/decorate.d.ts +16 -0
  377. package/cjs/util/decorate.js +17 -0
  378. package/cjs/util/filterEvents.d.ts +6 -0
  379. package/cjs/util/filterEvents.js +25 -0
  380. package/cjs/util/index.d.ts +4 -0
  381. package/cjs/util/index.js +11 -0
  382. package/cjs/util/isKeyringPair.d.ts +3 -0
  383. package/cjs/util/isKeyringPair.js +7 -0
  384. package/cjs/util/logging.d.ts +1 -0
  385. package/cjs/util/logging.js +5 -0
  386. package/cjs/util/validate.d.ts +3 -0
  387. package/cjs/util/validate.js +26 -0
  388. package/index.d.ts +2 -0
  389. package/index.js +2 -0
  390. package/package.json +588 -22
  391. package/packageDetect.d.ts +1 -0
  392. package/packageDetect.js +8 -0
  393. package/packageInfo.d.ts +6 -0
  394. package/packageInfo.js +1 -0
  395. package/promise/Api.d.ts +158 -0
  396. package/promise/Api.js +191 -0
  397. package/promise/Combinator.d.ts +12 -0
  398. package/promise/Combinator.js +68 -0
  399. package/promise/decorateMethod.d.ts +14 -0
  400. package/promise/decorateMethod.js +71 -0
  401. package/promise/index.d.ts +2 -0
  402. package/promise/index.js +2 -0
  403. package/promise/types.d.ts +5 -0
  404. package/promise/types.js +1 -0
  405. package/rx/Api.d.ts +155 -0
  406. package/rx/Api.js +169 -0
  407. package/rx/decorateMethod.d.ts +3 -0
  408. package/rx/decorateMethod.js +3 -0
  409. package/rx/index.d.ts +2 -0
  410. package/rx/index.js +2 -0
  411. package/src/augment.ts +1 -1
  412. package/src/base/Decorate.ts +1 -1
  413. package/src/base/Events.ts +1 -1
  414. package/src/base/Getters.ts +1 -1
  415. package/src/base/Init.ts +1 -1
  416. package/src/base/find.ts +1 -1
  417. package/src/base/index.ts +1 -1
  418. package/src/base/types.ts +1 -1
  419. package/src/bundle.ts +1 -1
  420. package/src/checkTypes.manual.ts +7 -7
  421. package/src/index.ts +1 -1
  422. package/src/mod.ts +1 -1
  423. package/src/packageDetect.ts +2 -2
  424. package/src/packageInfo.ts +3 -3
  425. package/src/promise/Api.ts +3 -3
  426. package/src/promise/Combinator.ts +1 -1
  427. package/src/promise/Combinators.spec.ts +1 -1
  428. package/src/promise/decorateMethod.ts +1 -1
  429. package/src/promise/index.spec.ts +1 -1
  430. package/src/promise/index.ts +1 -1
  431. package/src/promise/types.ts +1 -1
  432. package/src/rx/Api.ts +3 -3
  433. package/src/rx/decorateMethod.ts +1 -1
  434. package/src/rx/index.ts +1 -1
  435. package/src/submittable/Result.ts +1 -1
  436. package/src/submittable/createClass.ts +1 -1
  437. package/src/submittable/createSubmittable.ts +1 -1
  438. package/src/submittable/index.ts +1 -1
  439. package/src/submittable/types.ts +1 -1
  440. package/src/test/SingleAccountSigner.ts +1 -1
  441. package/src/test/index.ts +1 -1
  442. package/src/test/logEvents.ts +1 -1
  443. package/src/types/calls.ts +1 -1
  444. package/src/types/consts.ts +1 -1
  445. package/src/types/errors.ts +1 -1
  446. package/src/types/events.ts +1 -1
  447. package/src/types/index.ts +1 -1
  448. package/src/types/storage.ts +1 -1
  449. package/src/types/submittable.ts +1 -1
  450. package/src/util/augmentObject.spec.ts +1 -1
  451. package/src/util/augmentObject.ts +1 -1
  452. package/src/util/decorate.ts +1 -1
  453. package/src/util/filterEvents.ts +1 -1
  454. package/src/util/index.ts +1 -1
  455. package/src/util/isKeyringPair.ts +1 -1
  456. package/src/util/logging.ts +1 -1
  457. package/src/util/validate.spec.ts +2 -2
  458. package/src/util/validate.ts +1 -1
  459. package/submittable/Result.d.ts +31 -0
  460. package/submittable/Result.js +80 -0
  461. package/submittable/createClass.d.ts +12 -0
  462. package/submittable/createClass.js +274 -0
  463. package/submittable/createSubmittable.d.ts +8 -0
  464. package/submittable/createSubmittable.js +5 -0
  465. package/submittable/index.d.ts +2 -0
  466. package/submittable/index.js +2 -0
  467. package/submittable/types.d.ts +1 -0
  468. package/submittable/types.js +1 -0
  469. package/tsconfig.build.tsbuildinfo +1 -1
  470. package/tsconfig.spec.tsbuildinfo +1 -0
  471. package/types/calls.d.ts +1 -0
  472. package/types/calls.js +1 -0
  473. package/types/consts.d.ts +1 -0
  474. package/types/consts.js +1 -0
  475. package/types/errors.d.ts +1 -0
  476. package/types/errors.js +1 -0
  477. package/types/events.d.ts +1 -0
  478. package/types/events.js +1 -0
  479. package/types/index.d.ts +114 -0
  480. package/types/index.js +8 -0
  481. package/types/storage.d.ts +1 -0
  482. package/types/storage.js +1 -0
  483. package/types/submittable.d.ts +1 -0
  484. package/types/submittable.js +1 -0
  485. package/util/augmentObject.d.ts +9 -0
  486. package/util/augmentObject.js +81 -0
  487. package/util/decorate.d.ts +16 -0
  488. package/util/decorate.js +14 -0
  489. package/util/filterEvents.d.ts +6 -0
  490. package/util/filterEvents.js +22 -0
  491. package/util/index.d.ts +4 -0
  492. package/util/index.js +4 -0
  493. package/util/isKeyringPair.d.ts +3 -0
  494. package/util/isKeyringPair.js +4 -0
  495. package/util/logging.d.ts +1 -0
  496. package/util/logging.js +2 -0
  497. package/util/validate.d.ts +3 -0
  498. package/util/validate.js +23 -0
@@ -0,0 +1,1100 @@
1
+
2
+ import type { Observable } from 'https://esm.sh/rxjs@7.8.1';
3
+ import type { AugmentedCall, DeriveCustom, QueryableCalls } from 'https://deno.land/x/pezkuwi/api-base/types/index.ts';
4
+ import type { RpcInterface } from 'https://deno.land/x/pezkuwi/rpc-core/types/index.ts';
5
+ import type { Metadata, StorageKey, Text, u64, Vec } from 'https://deno.land/x/pezkuwi/types/mod.ts';
6
+ import type { Call, Hash, RuntimeApiMethodMetadataV16, RuntimeVersion } from 'https://deno.land/x/pezkuwi/types/interfaces/index.ts';
7
+ import type { DecoratedMeta } from 'https://deno.land/x/pezkuwi/types/metadata/decorate/types.ts';
8
+ import type { StorageEntry } from 'https://deno.land/x/pezkuwi/types/primitive/types.ts';
9
+ import type { AnyFunction, AnyJson, AnyTuple, CallFunction, Codec, DefinitionCall, DefinitionCallNamed, DefinitionRpc, DefinitionRpcSub, DefinitionsCall, DefinitionsCallEntry, DetectCodec, IMethod, IStorageKey, Registry, RegistryError, RegistryTypes } from 'https://deno.land/x/pezkuwi/types/types/index.ts';
10
+ import type { HexString } from 'https://deno.land/x/pezkuwi/util/types.ts';
11
+ import type { SubmittableExtrinsic } from '../submittable/types.ts';
12
+ import type { ApiDecoration, ApiInterfaceRx, ApiOptions, ApiTypes, AugmentedQuery, DecoratedErrors, DecoratedEvents, DecoratedRpc, DecorateMethod, GenericStorageEntryFunction, PaginationOptions, QueryableConsts, QueryableStorage, QueryableStorageEntry, QueryableStorageEntryAt, QueryableStorageMulti, QueryableStorageMultiArg, SubmittableExtrinsicFunction, SubmittableExtrinsics } from '../types/index.ts';
13
+ import type { AllDerives } from '../util/decorate.ts';
14
+ import type { VersionedRegistry } from './types.ts';
15
+
16
+ import { BehaviorSubject, combineLatest, from, map, of, switchMap, tap, toArray } from 'https://esm.sh/rxjs@7.8.1';
17
+
18
+ import { getAvailableDerives } from 'https://deno.land/x/pezkuwi/api-derive/mod.ts';
19
+ import { memo, RpcCore } from 'https://deno.land/x/pezkuwi/rpc-core/mod.ts';
20
+ import { WsProvider } from 'https://deno.land/x/pezkuwi/rpc-provider/mod.ts';
21
+ import { expandMetadata, GenericExtrinsic, typeDefinitions, TypeRegistry } from 'https://deno.land/x/pezkuwi/types/mod.ts';
22
+ import { getSpecRuntime } from 'https://deno.land/x/pezkuwi/types-known/mod.ts';
23
+ import { arrayChunk, arrayFlatten, assertReturn, BN, compactStripLength, lazyMethod, lazyMethods, logger, nextTick, objectSpread, stringCamelCase, stringUpperFirst, u8aConcatStrict, u8aToHex } from 'https://deno.land/x/pezkuwi/util/mod.ts';
24
+ import { blake2AsHex } from 'https://deno.land/x/pezkuwi/util-crypto/mod.ts';
25
+
26
+ import { createSubmittable } from '../submittable/index.ts';
27
+ import { augmentObject } from '../util/augmentObject.ts';
28
+ import { decorateDeriveSections } from '../util/decorate.ts';
29
+ import { extractStorageArgs } from '../util/validate.ts';
30
+ import { Events } from './Events.ts';
31
+ import { findCall, findError } from './find.ts';
32
+
33
+ interface MetaDecoration {
34
+ callIndex?: Uint8Array;
35
+ meta: Record<string, unknown>;
36
+ method: string;
37
+ section: string;
38
+ toJSON: () => any;
39
+ }
40
+
41
+ interface FullDecoration<ApiType extends ApiTypes> {
42
+ createdAt?: Uint8Array | undefined;
43
+ decoratedApi: ApiDecoration<ApiType>;
44
+ decoratedMeta: DecoratedMeta;
45
+ }
46
+
47
+ const PAGE_SIZE_K = 1000; // limit aligned with the 1k on the node (trie lookups are heavy)
48
+ const PAGE_SIZE_V = 250; // limited since the data may be > 16MB (e.g. misfiring elections)
49
+ const PAGE_SIZE_Q = 50; // queue of pending storage queries (mapped together, next tick)
50
+
51
+ const l = logger('api/init');
52
+
53
+ let instanceCounter = 0;
54
+
55
+ function getAtQueryFn<ApiType extends ApiTypes> (api: ApiDecoration<ApiType>, { method, section }: StorageEntry): AugmentedQuery<'rxjs', GenericStorageEntryFunction, AnyTuple> {
56
+ return assertReturn(api.rx.query[section] && api.rx.query[section][method], () => `query.${section}.${method} is not available in this version of the metadata`);
57
+ }
58
+
59
+ export abstract class Decorate<ApiType extends ApiTypes> extends Events {
60
+ readonly #instanceId: string;
61
+ readonly #runtimeLog: Record<string, boolean> = {};
62
+
63
+ #registry: Registry;
64
+ #storageGetQ: [Observable<Codec[]>, [StorageEntry, unknown[]][]][] = [];
65
+ #storageSubQ: [Observable<Codec[]>, [StorageEntry, unknown[]][]][] = [];
66
+
67
+ // HACK Use BN import so decorateDerive works... yes, wtf.
68
+ protected __phantom = new BN(0);
69
+
70
+ protected _type: ApiTypes;
71
+ protected _call: QueryableCalls<ApiType> = {} as QueryableCalls<ApiType>;
72
+ protected _consts: QueryableConsts<ApiType> = {} as QueryableConsts<ApiType>;
73
+ protected _derive?: ReturnType<Decorate<ApiType>['_decorateDerive']>;
74
+ protected _errors: DecoratedErrors<ApiType> = {} as DecoratedErrors<ApiType>;
75
+ protected _events: DecoratedEvents<ApiType> = {} as DecoratedEvents<ApiType>;
76
+ protected _extrinsics?: SubmittableExtrinsics<ApiType>;
77
+ protected _extrinsicType = GenericExtrinsic.LATEST_EXTRINSIC_VERSION;
78
+ protected _genesisHash?: Hash;
79
+ protected _isConnected: BehaviorSubject<boolean>;
80
+ protected _isReady = false;
81
+ protected _query: QueryableStorage<ApiType> = {} as QueryableStorage<ApiType>;
82
+ protected _queryMulti?: QueryableStorageMulti<ApiType>;
83
+ protected _rpc?: DecoratedRpc<ApiType, RpcInterface>;
84
+ protected _rpcCore: RpcCore & RpcInterface;
85
+ protected _runtimeMap: Record<HexString, string> = {};
86
+ protected _runtimeChain?: Text;
87
+ protected _runtimeMetadata?: Metadata;
88
+ protected _runtimeVersion?: RuntimeVersion;
89
+ protected _rx: ApiInterfaceRx = { call: {} as QueryableCalls<'rxjs'>, consts: {} as QueryableConsts<'rxjs'>, query: {} as QueryableStorage<'rxjs'>, tx: {} as SubmittableExtrinsics<'rxjs'> } as ApiInterfaceRx;
90
+
91
+ protected readonly _options: ApiOptions;
92
+
93
+ /**
94
+ * This is the one and only method concrete children classes need to implement.
95
+ * It's a higher-order function, which takes one argument
96
+ * `method: Method extends (...args: any[]) => Observable<any>`
97
+ * (and one optional `options`), and should return the user facing method.
98
+ * For example:
99
+ * - For ApiRx, `decorateMethod` should just be identity, because the input
100
+ * function is already an Observable
101
+ * - For ApiPromise, `decorateMethod` should return a function that takes all
102
+ * the parameters from `method`, adds an optional `callback` argument, and
103
+ * returns a Promise.
104
+ *
105
+ * We could easily imagine other user-facing interfaces, which are simply
106
+ * implemented by transforming the Observable to Stream/Iterator/Kefir/Bacon
107
+ * via `decorateMethod`.
108
+ */
109
+ protected _decorateMethod: DecorateMethod<ApiType>;
110
+
111
+ /**
112
+ * @description Create an instance of the class
113
+ *
114
+ * @param options Options object to create API instance or a Provider instance
115
+ *
116
+ * @example
117
+ * <BR>
118
+ *
119
+ * ```javascript
120
+ * import Api from 'https://deno.land/x/pezkuwi/api/promise/index.ts';
121
+ *
122
+ * const api = new Api().isReady();
123
+ *
124
+ * api.rpc.subscribeNewHeads((header) => {
125
+ * console.log(`new block #${header.number.toNumber()}`);
126
+ * });
127
+ * ```
128
+ */
129
+ constructor (options: ApiOptions, type: ApiTypes, decorateMethod: DecorateMethod<ApiType>) {
130
+ super();
131
+
132
+ this.#instanceId = `${++instanceCounter}`;
133
+ this.#registry = options.source?.registry || options.registry || new TypeRegistry();
134
+ this._rx.callAt = (blockHash: Uint8Array | string, knownVersion?: RuntimeVersion) =>
135
+ from(this.at(blockHash, knownVersion)).pipe(map((a) => a.rx.call));
136
+ this._rx.queryAt = (blockHash: Uint8Array | string, knownVersion?: RuntimeVersion) =>
137
+ from(this.at(blockHash, knownVersion)).pipe(map((a) => a.rx.query));
138
+ this._rx.registry = this.#registry;
139
+ this._decorateMethod = decorateMethod;
140
+ this._options = options;
141
+ this._type = type;
142
+
143
+ const provider = options.source
144
+ ? options.source._rpcCore.provider.isClonable
145
+ ? options.source._rpcCore.provider.clone()
146
+ : options.source._rpcCore.provider
147
+ : (options.provider || new WsProvider());
148
+
149
+ // The RPC interface decorates the known interfaces on init
150
+ this._rpcCore = new RpcCore(this.#instanceId, this.#registry, {
151
+ isPedantic: this._options.isPedantic,
152
+ provider,
153
+ rpcCacheCapacity: this._options.rpcCacheCapacity,
154
+ ttl: this._options.provider?.ttl,
155
+ userRpc: this._options.rpc
156
+ }) as (RpcCore & RpcInterface);
157
+ this._isConnected = new BehaviorSubject(this._rpcCore.provider.isConnected);
158
+ this._rx.hasSubscriptions = this._rpcCore.provider.hasSubscriptions;
159
+ }
160
+
161
+ public abstract at (blockHash: Uint8Array | string, knownVersion?: RuntimeVersion): Promise<ApiDecoration<ApiType>>;
162
+
163
+ /**
164
+ * @description Return the current used registry
165
+ */
166
+ public get registry (): Registry {
167
+ return this.#registry;
168
+ }
169
+
170
+ /**
171
+ * @description Creates an instance of a type as registered
172
+ */
173
+ public createType <T extends Codec = Codec, K extends string = string> (type: K, ...params: unknown[]): DetectCodec<T, K> {
174
+ return this.#registry.createType(type, ...params);
175
+ }
176
+
177
+ /**
178
+ * @description Register additional user-defined of chain-specific types in the type registry
179
+ */
180
+ public registerTypes (types?: RegistryTypes): void {
181
+ types && this.#registry.register(types);
182
+ }
183
+
184
+ /**
185
+ * @returns `true` if the API operates with subscriptions
186
+ */
187
+ get hasSubscriptions (): boolean {
188
+ return this._rpcCore.provider.hasSubscriptions;
189
+ }
190
+
191
+ /**
192
+ * @returns `true` if the API decorate multi-key queries
193
+ */
194
+ get supportMulti (): boolean {
195
+ return this._rpcCore.provider.hasSubscriptions || !!this._rpcCore.state.queryStorageAt;
196
+ }
197
+
198
+ protected _emptyDecorated (registry: Registry, blockHash?: Uint8Array): ApiDecoration<ApiType> {
199
+ return {
200
+ call: {},
201
+ consts: {},
202
+ errors: {},
203
+ events: {},
204
+ query: {},
205
+ registry,
206
+ rx: {
207
+ call: {},
208
+ query: {}
209
+ },
210
+ tx: createSubmittable(this._type, this._rx, this._decorateMethod, registry, blockHash)
211
+ } as ApiDecoration<ApiType>;
212
+ }
213
+
214
+ protected _createDecorated (registry: VersionedRegistry<ApiType>, fromEmpty: boolean, decoratedApi: ApiDecoration<ApiType> | null, blockHash?: Uint8Array): FullDecoration<ApiType> {
215
+ if (!decoratedApi) {
216
+ decoratedApi = this._emptyDecorated(registry.registry, blockHash);
217
+ }
218
+
219
+ if (fromEmpty || !registry.decoratedMeta) {
220
+ registry.decoratedMeta = expandMetadata(registry.registry, registry.metadata);
221
+ }
222
+
223
+ const runtime = this._decorateCalls(registry, this._decorateMethod, blockHash);
224
+ const runtimeRx = this._decorateCalls<'rxjs'>(registry, this._rxDecorateMethod, blockHash);
225
+ const storage = this._decorateStorage(registry.decoratedMeta, this._decorateMethod, blockHash);
226
+ const storageRx = this._decorateStorage<'rxjs'>(registry.decoratedMeta, this._rxDecorateMethod, blockHash);
227
+
228
+ augmentObject('consts', registry.decoratedMeta.consts, decoratedApi.consts, fromEmpty);
229
+ augmentObject('errors', registry.decoratedMeta.errors, decoratedApi.errors, fromEmpty);
230
+ augmentObject('events', registry.decoratedMeta.events, decoratedApi.events, fromEmpty);
231
+ augmentObject('query', storage, decoratedApi.query, fromEmpty);
232
+ augmentObject('query', storageRx, decoratedApi.rx.query, fromEmpty);
233
+ augmentObject('call', runtime, decoratedApi.call, fromEmpty);
234
+ augmentObject('call', runtimeRx, decoratedApi.rx.call, fromEmpty);
235
+
236
+ decoratedApi.findCall = (callIndex: Uint8Array | string): CallFunction =>
237
+ findCall(registry.registry, callIndex);
238
+ decoratedApi.findError = (errorIndex: Uint8Array | string): RegistryError =>
239
+ findError(registry.registry, errorIndex);
240
+ decoratedApi.queryMulti = blockHash
241
+ ? this._decorateMultiAt(decoratedApi, this._decorateMethod, blockHash)
242
+ : this._decorateMulti(this._decorateMethod);
243
+ decoratedApi.runtimeVersion = registry.runtimeVersion;
244
+
245
+ return {
246
+ createdAt: blockHash,
247
+ decoratedApi,
248
+ decoratedMeta: registry.decoratedMeta
249
+ };
250
+ }
251
+
252
+ protected _injectMetadata (registry: VersionedRegistry<ApiType>, fromEmpty = false): void {
253
+ // clear the decoration, we are redoing it here
254
+ if (fromEmpty || !registry.decoratedApi) {
255
+ registry.decoratedApi = this._emptyDecorated(registry.registry);
256
+ }
257
+
258
+ const { decoratedApi, decoratedMeta } = this._createDecorated(registry, fromEmpty, registry.decoratedApi);
259
+
260
+ this._call = decoratedApi.call;
261
+ this._consts = decoratedApi.consts;
262
+ this._errors = decoratedApi.errors;
263
+ this._events = decoratedApi.events;
264
+ this._query = decoratedApi.query;
265
+
266
+ this._rx.call = decoratedApi.rx.call;
267
+ this._rx.query = decoratedApi.rx.query;
268
+
269
+ const tx = this._decorateExtrinsics(decoratedMeta, this._decorateMethod);
270
+ const rxtx = this._decorateExtrinsics(decoratedMeta, this._rxDecorateMethod);
271
+
272
+ if (fromEmpty || !this._extrinsics) {
273
+ this._extrinsics = tx;
274
+ this._rx.tx = rxtx;
275
+ } else {
276
+ augmentObject('tx', tx, this._extrinsics, false);
277
+ augmentObject(null, rxtx, this._rx.tx, false);
278
+ }
279
+
280
+ augmentObject(null, decoratedMeta.consts, this._rx.consts, fromEmpty);
281
+
282
+ this.emit('decorated');
283
+ }
284
+
285
+ /**
286
+ * @deprecated
287
+ * backwards compatible endpoint for metadata injection, may be removed in the future (However, it is still useful for testing injection)
288
+ */
289
+ public injectMetadata (metadata: Metadata, fromEmpty?: boolean, registry?: Registry): void {
290
+ this._injectMetadata({ counter: 0, metadata, registry: registry || this.#registry, runtimeVersion: this.#registry.createType('RuntimeVersionPartial') }, fromEmpty);
291
+ }
292
+
293
+ private _decorateFunctionMeta (input: MetaDecoration, output: MetaDecoration): MetaDecoration {
294
+ output.meta = input.meta;
295
+ output.method = input.method;
296
+ output.section = input.section;
297
+ output.toJSON = input.toJSON;
298
+
299
+ if (input.callIndex) {
300
+ output.callIndex = input.callIndex;
301
+ }
302
+
303
+ return output;
304
+ }
305
+
306
+ // Filter all RPC methods based on the results of the rpc_methods call. We do this in the following
307
+ // manner to cater for both old and new:
308
+ // - when the number of entries are 0, only remove the ones with isOptional (account & contracts)
309
+ // - when non-zero, remove anything that is not in the array (we don't do this)
310
+ protected _filterRpc (methods: string[], additional: Record<string, Record<string, DefinitionRpc | DefinitionRpcSub>>): void {
311
+ // add any specific user-base RPCs
312
+ if (Object.keys(additional).length !== 0) {
313
+ this._rpcCore.addUserInterfaces(additional);
314
+
315
+ // re-decorate, only adding any new additional interfaces
316
+ this._decorateRpc(this._rpcCore, this._decorateMethod, this._rpc);
317
+ this._decorateRpc(this._rpcCore, this._rxDecorateMethod, this._rx.rpc);
318
+ }
319
+
320
+ // extract the actual sections from the methods (this is useful when
321
+ // we try and create mappings to runtime names via a hash mapping)
322
+ const sectionMap: Record<string, boolean> = {};
323
+
324
+ for (let i = 0, count = methods.length; i < count; i++) {
325
+ const [section] = methods[i].split('_');
326
+
327
+ sectionMap[section] = true;
328
+ }
329
+
330
+ // convert the actual section names into an easy name lookup
331
+ const sections = Object.keys(sectionMap);
332
+
333
+ for (let i = 0, count = sections.length; i < count; i++) {
334
+ const nameA = stringUpperFirst(sections[i]);
335
+ const nameB = `${nameA}Api`;
336
+
337
+ this._runtimeMap[blake2AsHex(nameA, 64)] = nameA;
338
+ this._runtimeMap[blake2AsHex(nameB, 64)] = nameB;
339
+ }
340
+
341
+ // finally we filter the actual methods to expose
342
+ this._filterRpcMethods(methods);
343
+ }
344
+
345
+ protected _filterRpcMethods (exposed: string[]): void {
346
+ const hasResults = exposed.length !== 0;
347
+ const allKnown = [...this._rpcCore.mapping.entries()];
348
+ const allKeys: string[] = [];
349
+ const count = allKnown.length;
350
+
351
+ for (let i = 0; i < count; i++) {
352
+ const [, { alias, endpoint, method, pubsub, section }] = allKnown[i];
353
+
354
+ allKeys.push(`${section}_${method}`);
355
+
356
+ if (pubsub) {
357
+ allKeys.push(`${section}_${pubsub[1]}`);
358
+ allKeys.push(`${section}_${pubsub[2]}`);
359
+ }
360
+
361
+ if (alias) {
362
+ allKeys.push(...alias);
363
+ }
364
+
365
+ if (endpoint) {
366
+ allKeys.push(endpoint);
367
+ }
368
+ }
369
+
370
+ const unknown = exposed.filter((k: string) =>
371
+ !allKeys.includes(k) &&
372
+ !k.includes('_unstable_')
373
+ );
374
+
375
+ if (unknown.length && !this._options.noInitWarn) {
376
+ l.warn(`RPC methods not decorated: ${unknown.join(', ')}`);
377
+ }
378
+
379
+ // loop through all entries we have (populated in decorate) and filter as required
380
+ // only remove when we have results and method missing, or with no results if optional
381
+ for (let i = 0; i < count; i++) {
382
+ const [k, { method, section }] = allKnown[i];
383
+
384
+ if (hasResults && !exposed.includes(k) && k !== 'rpc_methods') {
385
+ if ((this._rpc as unknown as Record<string, Record<string, unknown>>)[section]) {
386
+ delete (this._rpc as unknown as Record<string, Record<string, unknown>>)[section][method];
387
+ delete (this._rx.rpc as unknown as Record<string, Record<string, unknown>>)[section][method];
388
+ }
389
+ }
390
+ }
391
+ }
392
+
393
+ private _rpcSubmitter<ApiType extends ApiTypes> (decorateMethod: DecorateMethod<ApiType>): DecoratedRpc<ApiType, RpcInterface> {
394
+ const method = (method: string, ...params: any[]) => {
395
+ return from(this._rpcCore.provider.send<AnyJson>(method, params));
396
+ };
397
+
398
+ return decorateMethod(method) as DecoratedRpc<ApiType, RpcInterface>;
399
+ }
400
+
401
+ protected _decorateRpc<ApiType extends ApiTypes> (rpc: RpcCore & RpcInterface, decorateMethod: DecorateMethod<ApiType>, input: Partial<DecoratedRpc<ApiType, RpcInterface>> = this._rpcSubmitter(decorateMethod)): DecoratedRpc<ApiType, RpcInterface> {
402
+ const out: Record<string, Record<string, unknown>> = input;
403
+
404
+ const decorateFn = (section: string, method: string): unknown => {
405
+ const source = rpc[section as 'chain'][method as 'getHeader'];
406
+ const fn = decorateMethod(source, { methodName: method }) as {
407
+ meta: unknown;
408
+ raw: unknown;
409
+ };
410
+
411
+ fn.meta = source.meta;
412
+ fn.raw = decorateMethod(source.raw, { methodName: method }) as unknown;
413
+
414
+ return fn;
415
+ };
416
+
417
+ for (let s = 0, scount = rpc.sections.length; s < scount; s++) {
418
+ const section = rpc.sections[s];
419
+
420
+ if (!Object.prototype.hasOwnProperty.call(out, section)) {
421
+ const methods = Object.keys(rpc[section as 'chain']);
422
+
423
+ const decorateInternal = (method: string) =>
424
+ decorateFn(section, method);
425
+
426
+ for (let m = 0, mcount = methods.length; m < mcount; m++) {
427
+ const method = methods[m];
428
+
429
+ // skip subscriptions where we have a non-subscribe interface
430
+ if (this.hasSubscriptions || !(method.startsWith('subscribe') || method.startsWith('unsubscribe'))) {
431
+ if (!Object.prototype.hasOwnProperty.call(out, section)) {
432
+ out[section] = {};
433
+ }
434
+
435
+ lazyMethod(out[section], method, decorateInternal);
436
+ }
437
+ }
438
+ }
439
+ }
440
+
441
+ return out as unknown as DecoratedRpc<ApiType, RpcInterface>;
442
+ }
443
+
444
+ // add all definition entries
445
+ protected _addRuntimeDef (result: DefinitionsCall, additional?: DefinitionsCall): void {
446
+ if (!additional) {
447
+ return;
448
+ }
449
+
450
+ const entries = Object.entries(additional);
451
+
452
+ for (let j = 0, ecount = entries.length; j < ecount; j++) {
453
+ const [key, defs] = entries[j];
454
+
455
+ if (result[key]) {
456
+ // we have this one already, step through for new versions or
457
+ // new methods and add those as applicable
458
+ for (let k = 0, dcount = defs.length; k < dcount; k++) {
459
+ const def = defs[k];
460
+ const prev = result[key].find(({ version }) => def.version === version);
461
+
462
+ if (prev) {
463
+ // interleave the new methods with the old - last definition wins
464
+ objectSpread(prev.methods, def.methods);
465
+ } else {
466
+ // we don't have this specific version, add it
467
+ result[key].push(def);
468
+ }
469
+ }
470
+ } else {
471
+ // we don't have this runtime definition, add it as-is
472
+ result[key] = defs;
473
+ }
474
+ }
475
+ }
476
+
477
+ // extract all runtime definitions
478
+ protected _getRuntimeDefs (registry: Registry, specName: Text, chain: Text | string = ''): [string, DefinitionsCallEntry[]][] {
479
+ const result: DefinitionsCall = {};
480
+ const defValues = Object.values(typeDefinitions);
481
+
482
+ // options > chain/spec > built-in, apply in reverse order with
483
+ // methods overriding previous definitions (or interleave missing)
484
+ for (let i = 0, count = defValues.length; i < count; i++) {
485
+ this._addRuntimeDef(result, defValues[i].runtime);
486
+ }
487
+
488
+ this._addRuntimeDef(result, getSpecRuntime(registry, chain, specName));
489
+ this._addRuntimeDef(result, this._options.runtime);
490
+
491
+ return Object.entries(result);
492
+ }
493
+
494
+ // Helper for _getRuntimeDefsViaMetadata
495
+ protected _getMethods (registry: Registry, methods: Vec<RuntimeApiMethodMetadataV16>) {
496
+ const result: Record<string, DefinitionCall> = {};
497
+
498
+ methods.forEach((m) => {
499
+ const { docs, inputs, name, output } = m;
500
+
501
+ result[name.toString()] = {
502
+ description: docs.map((d) => d.toString()).join(),
503
+ params: inputs.map(({ name, type }) => {
504
+ return { name: name.toString(), type: registry.lookup.getName(type) || registry.lookup.getTypeDef(type).type };
505
+ }),
506
+ type: registry.lookup.getName(output) || registry.lookup.getTypeDef(output).type
507
+ };
508
+ });
509
+
510
+ return result;
511
+ }
512
+
513
+ // Maintains the same structure as `_getRuntimeDefs` in order to make conversion easier.
514
+ protected _getRuntimeDefsViaMetadata (registry: Registry): [string, DefinitionsCallEntry[]][] {
515
+ const result: DefinitionsCall = {};
516
+ const { apis } = registry.metadata;
517
+
518
+ for (let i = 0, count = apis.length; i < count; i++) {
519
+ const { methods, name } = apis[i];
520
+
521
+ result[name.toString()] = [{
522
+ methods: this._getMethods(registry, methods),
523
+ // We set the version to 0 here since it will not be relevant when we are grabbing the runtime apis
524
+ // from the Metadata.
525
+ version: 0
526
+ }];
527
+ }
528
+
529
+ return Object.entries(result);
530
+ }
531
+
532
+ // When the calls are available in the metadata, it will generate them based off of the metadata.
533
+ // When they are not available it will use the hardcoded calls generated in the static types.
534
+ protected _decorateCalls<ApiType extends ApiTypes> ({ registry, runtimeVersion: { apis, specName, specVersion } }: VersionedRegistry<any>, decorateMethod: DecorateMethod<ApiType>, blockHash?: Uint8Array | string | null): QueryableCalls<ApiType> {
535
+ const result = {} as QueryableCalls<ApiType>;
536
+ const named: Record<string, Record<string, DefinitionCallNamed>> = {};
537
+ const hashes: Record<HexString, boolean> = {};
538
+ const isApiInMetadata = registry.metadata.apis.length > 0;
539
+ const sections = isApiInMetadata ? this._getRuntimeDefsViaMetadata(registry) : this._getRuntimeDefs(registry, specName, this._runtimeChain);
540
+ const older: string[] = [];
541
+ const implName = `${specName.toString()}/${specVersion.toString()}`;
542
+ const hasLogged = this.#runtimeLog[implName] || false;
543
+
544
+ this.#runtimeLog[implName] = true;
545
+
546
+ if (isApiInMetadata) {
547
+ for (let i = 0, scount = sections.length; i < scount; i++) {
548
+ const [_section, secs] = sections[i];
549
+ const sec = secs[0];
550
+ const sectionHash = blake2AsHex(_section, 64);
551
+
552
+ const section = stringCamelCase(_section);
553
+ const methods = Object.entries(sec.methods);
554
+
555
+ if (!named[section]) {
556
+ named[section] = {};
557
+ }
558
+
559
+ for (let m = 0, mcount = methods.length; m < mcount; m++) {
560
+ const [_method, def] = methods[m];
561
+ const method = stringCamelCase(_method);
562
+
563
+ named[section][method] = objectSpread({ method, name: `${_section}_${_method}`, section, sectionHash }, def);
564
+ }
565
+ }
566
+ } else {
567
+ for (let i = 0, scount = sections.length; i < scount; i++) {
568
+ const [_section, secs] = sections[i];
569
+ const sectionHash = blake2AsHex(_section, 64);
570
+ const rtApi = apis.find(([a]) => a.eq(sectionHash));
571
+
572
+ hashes[sectionHash] = true;
573
+
574
+ if (rtApi) {
575
+ const all = secs.map(({ version }) => version).sort();
576
+ const sec = secs.find(({ version }) => rtApi[1].eq(version));
577
+
578
+ if (sec) {
579
+ const section = stringCamelCase(_section);
580
+ const methods = Object.entries(sec.methods);
581
+
582
+ if (methods.length) {
583
+ if (!named[section]) {
584
+ named[section] = {};
585
+ }
586
+
587
+ for (let m = 0, mcount = methods.length; m < mcount; m++) {
588
+ const [_method, def] = methods[m];
589
+ const method = stringCamelCase(_method);
590
+
591
+ named[section][method] = objectSpread({ method, name: `${_section}_${_method}`, section, sectionHash }, def);
592
+ }
593
+ }
594
+ } else {
595
+ older.push(`${_section}/${rtApi[1].toString()} (${all.join('/')} known)`);
596
+ }
597
+ }
598
+ }
599
+
600
+ // find the runtimes that we don't have hashes for
601
+ const notFound = apis
602
+ .map(([a, v]): [HexString, string] => [a.toHex(), v.toString()])
603
+ .filter(([a]) => !hashes[a])
604
+ .map(([a, v]) => `${this._runtimeMap[a] || a}/${v}`);
605
+
606
+ if (!this._options.noInitWarn && !hasLogged) {
607
+ if (older.length) {
608
+ l.warn(`${implName}: Not decorating runtime apis without matching versions: ${older.join(', ')}`);
609
+ }
610
+
611
+ if (notFound.length) {
612
+ l.warn(`${implName}: Not decorating unknown runtime apis: ${notFound.join(', ')}`);
613
+ }
614
+ }
615
+ }
616
+
617
+ const stateCall = blockHash
618
+ ? (name: string, bytes: Uint8Array) => this._rpcCore.state.call(name, bytes, blockHash)
619
+ : (name: string, bytes: Uint8Array) => this._rpcCore.state.call(name, bytes);
620
+
621
+ const lazySection = (section: string) =>
622
+ lazyMethods({}, Object.keys(named[section]), (method: string) =>
623
+ this._decorateCall(registry, named[section][method], stateCall, decorateMethod)
624
+ );
625
+
626
+ const modules = Object.keys(named);
627
+
628
+ for (let i = 0, count = modules.length; i < count; i++) {
629
+ lazyMethod(result, modules[i], lazySection);
630
+ }
631
+
632
+ return result;
633
+ }
634
+
635
+ protected _decorateCall<ApiType extends ApiTypes> (registry: Registry, def: DefinitionCallNamed, stateCall: (method: string, bytes: Uint8Array) => Observable<Codec>, decorateMethod: DecorateMethod<ApiType>): AugmentedCall<ApiType> {
636
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
637
+ const decorated = decorateMethod((...args: unknown[]): Observable<Codec> => {
638
+ if (args.length !== def.params.length) {
639
+ throw new Error(`${def.name}:: Expected ${def.params.length} arguments, found ${args.length}`);
640
+ }
641
+
642
+ const bytes = registry.createType('Raw', u8aConcatStrict(
643
+ args.map((a, i) => registry.createTypeUnsafe(def.params[i].type, [a]).toU8a())
644
+ ));
645
+
646
+ return stateCall(def.name, bytes).pipe(
647
+ map((r) => registry.createTypeUnsafe(def.type, [r]))
648
+ );
649
+ });
650
+
651
+ (decorated as AugmentedCall<ApiType>).meta = def;
652
+
653
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return
654
+ return decorated;
655
+ }
656
+
657
+ // only be called if supportMulti is true
658
+ protected _decorateMulti<ApiType extends ApiTypes> (decorateMethod: DecorateMethod<ApiType>): QueryableStorageMulti<ApiType> {
659
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return
660
+ return decorateMethod((keys: QueryableStorageMultiArg<ApiType>[]): Observable<Codec[]> =>
661
+ keys.length
662
+ ? (this.hasSubscriptions
663
+ ? this._rpcCore.state.subscribeStorage
664
+ : this._rpcCore.state.queryStorageAt
665
+ )(keys.map((args: QueryableStorageMultiArg<ApiType>): [StorageEntry, ...unknown[]] =>
666
+ Array.isArray(args)
667
+ ? args[0].creator.meta.type.isPlain
668
+ ? [args[0].creator]
669
+ : args[0].creator.meta.type.asMap.hashers.length === 1
670
+ ? [args[0].creator, args.slice(1)]
671
+ : [args[0].creator, ...args.slice(1)]
672
+ : [args.creator]
673
+ ))
674
+ : of([])
675
+ );
676
+ }
677
+
678
+ protected _decorateMultiAt<ApiType extends ApiTypes> (atApi: ApiDecoration<ApiType>, decorateMethod: DecorateMethod<ApiType>, blockHash: Uint8Array | string): QueryableStorageMulti<ApiType> {
679
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return
680
+ return decorateMethod((calls: QueryableStorageMultiArg<ApiType>[]): Observable<Codec[]> =>
681
+ calls.length
682
+ ? this._rpcCore.state.queryStorageAt(
683
+ calls.map((args: QueryableStorageMultiArg<ApiType>) => {
684
+ if (Array.isArray(args)) {
685
+ const { creator } = getAtQueryFn(atApi, args[0].creator);
686
+
687
+ return creator.meta.type.isPlain
688
+ ? [creator]
689
+ : creator.meta.type.asMap.hashers.length === 1
690
+ ? [creator, args.slice(1)]
691
+ : [creator, ...args.slice(1)];
692
+ }
693
+
694
+ return [getAtQueryFn(atApi, args.creator).creator];
695
+ }),
696
+ blockHash)
697
+ : of([])
698
+ );
699
+ }
700
+
701
+ protected _decorateExtrinsics<ApiType extends ApiTypes> ({ tx }: DecoratedMeta, decorateMethod: DecorateMethod<ApiType>): SubmittableExtrinsics<ApiType> {
702
+ const result = createSubmittable(this._type, this._rx, decorateMethod) as SubmittableExtrinsics<ApiType>;
703
+
704
+ const lazySection = (section: string) =>
705
+ lazyMethods({}, Object.keys(tx[section]), (method: string) =>
706
+ method.startsWith('$')
707
+ ? tx[section][method]
708
+ : this._decorateExtrinsicEntry(tx[section][method], result)
709
+ );
710
+
711
+ const sections = Object.keys(tx);
712
+
713
+ for (let i = 0, count = sections.length; i < count; i++) {
714
+ lazyMethod(result, sections[i], lazySection);
715
+ }
716
+
717
+ return result;
718
+ }
719
+
720
+ private _decorateExtrinsicEntry<ApiType extends ApiTypes> (method: CallFunction, creator: (value: Call | Uint8Array | string) => SubmittableExtrinsic<ApiType>): SubmittableExtrinsicFunction<ApiType> {
721
+ const decorated = (...params: unknown[]): SubmittableExtrinsic<ApiType> =>
722
+ creator(method(...params));
723
+
724
+ // pass through the `.is`
725
+ decorated.is = (other: IMethod<AnyTuple>) =>
726
+ method.is(other);
727
+
728
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return
729
+ return this._decorateFunctionMeta(method as unknown as MetaDecoration, decorated as unknown as MetaDecoration) as unknown as SubmittableExtrinsicFunction<ApiType>;
730
+ }
731
+
732
+ protected _decorateStorage<ApiType extends ApiTypes> ({ query, registry }: DecoratedMeta, decorateMethod: DecorateMethod<ApiType>, blockHash?: Uint8Array): QueryableStorage<ApiType> {
733
+ const result = {} as QueryableStorage<ApiType>;
734
+
735
+ const lazySection = (section: string) =>
736
+ lazyMethods({}, Object.keys(query[section]), (method: string) =>
737
+ blockHash
738
+ ? this._decorateStorageEntryAt(registry, query[section][method], decorateMethod, blockHash)
739
+ : this._decorateStorageEntry(query[section][method], decorateMethod)
740
+ );
741
+
742
+ const sections = Object.keys(query);
743
+
744
+ for (let i = 0, count = sections.length; i < count; i++) {
745
+ lazyMethod(result, sections[i], lazySection);
746
+ }
747
+
748
+ return result;
749
+ }
750
+
751
+ private _decorateStorageEntry<ApiType extends ApiTypes> (creator: StorageEntry, decorateMethod: DecorateMethod<ApiType>): QueryableStorageEntry<ApiType> {
752
+ const getArgs = (args: unknown[], registry?: Registry) =>
753
+ extractStorageArgs(registry || this.#registry, creator, args);
754
+
755
+ const getQueryAt = (blockHash: Hash | Uint8Array | string): Observable<AugmentedQuery<'rxjs', GenericStorageEntryFunction, AnyTuple>> =>
756
+ from(this.at(blockHash)).pipe(
757
+ map((api) => getAtQueryFn(api, creator)));
758
+
759
+ // Disable this where it occurs for each field we are decorating
760
+ /* eslint-disable @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment */
761
+
762
+ const decorated: AugmentedQuery<'rxjs', GenericStorageEntryFunction, AnyTuple> & MetaDecoration = this._decorateStorageCall(creator, decorateMethod);
763
+
764
+ decorated.creator = creator;
765
+
766
+ // eslint-disable-next-line deprecation/deprecation
767
+ decorated.at = decorateMethod((blockHash: Hash, ...args: unknown[]): Observable<Codec> =>
768
+ getQueryAt(blockHash).pipe(
769
+ switchMap((q) => q(...args))));
770
+
771
+ decorated.hash = decorateMethod((...args: unknown[]): Observable<Hash> =>
772
+ this._rpcCore.state.getStorageHash(getArgs(args)));
773
+
774
+ decorated.is = <A extends AnyTuple> (key: IStorageKey<AnyTuple>): key is IStorageKey<A> =>
775
+ key.section === creator.section &&
776
+ key.method === creator.method;
777
+
778
+ decorated.key = (...args: unknown[]): string =>
779
+ u8aToHex(compactStripLength(creator(...args))[1]);
780
+
781
+ decorated.keyPrefix = (...args: unknown[]): string =>
782
+ u8aToHex(creator.keyPrefix(...args));
783
+
784
+ decorated.size = decorateMethod((...args: unknown[]): Observable<u64> =>
785
+ this._rpcCore.state.getStorageSize(getArgs(args)));
786
+
787
+ // eslint-disable-next-line deprecation/deprecation
788
+ decorated.sizeAt = decorateMethod((blockHash: Hash | Uint8Array | string, ...args: unknown[]): Observable<u64> =>
789
+ getQueryAt(blockHash).pipe(
790
+ switchMap((q) =>
791
+ this._rpcCore.state.getStorageSize(getArgs(args, q.creator.meta.registry), blockHash))));
792
+
793
+ // .keys() & .entries() only available on map types
794
+ if (creator.iterKey && creator.meta.type.isMap) {
795
+ decorated.entries = decorateMethod(
796
+ memo(this.#instanceId, (...args: unknown[]): Observable<[StorageKey, Codec][]> =>
797
+ this._retrieveMapEntries(creator, null, args)));
798
+
799
+ // eslint-disable-next-line deprecation/deprecation
800
+ decorated.entriesAt = decorateMethod(
801
+ memo(this.#instanceId, (blockHash: Hash | Uint8Array | string, ...args: unknown[]): Observable<[StorageKey, Codec][]> =>
802
+ getQueryAt(blockHash).pipe(
803
+ switchMap((q) => this._retrieveMapEntries(q.creator, blockHash, args)))));
804
+
805
+ decorated.entriesPaged = decorateMethod(
806
+ memo(this.#instanceId, (opts: PaginationOptions): Observable<[StorageKey, Codec][]> =>
807
+ this._retrieveMapEntriesPaged(creator, undefined, opts)));
808
+
809
+ decorated.keys = decorateMethod(
810
+ memo(this.#instanceId, (...args: unknown[]): Observable<StorageKey[]> =>
811
+ this._retrieveMapKeys(creator, null, args)));
812
+
813
+ // eslint-disable-next-line deprecation/deprecation
814
+ decorated.keysAt = decorateMethod(
815
+ memo(this.#instanceId, (blockHash: Hash | Uint8Array | string, ...args: unknown[]): Observable<StorageKey[]> =>
816
+ getQueryAt(blockHash).pipe(
817
+ switchMap((q) => this._retrieveMapKeys(q.creator, blockHash, args)))));
818
+
819
+ decorated.keysPaged = decorateMethod(
820
+ memo(this.#instanceId, (opts: PaginationOptions): Observable<StorageKey[]> =>
821
+ this._retrieveMapKeysPaged(creator, undefined, opts)));
822
+ }
823
+
824
+ if (this.supportMulti && creator.meta.type.isMap) {
825
+ // When using double map storage function, user need to pass double map key as an array
826
+ decorated.multi = decorateMethod((args: unknown[]): Observable<Codec[]> =>
827
+ creator.meta.type.asMap.hashers.length === 1
828
+ ? this._retrieveMulti(args.map((a) => [creator, [a]]))
829
+ : this._retrieveMulti(args.map((a) => [creator, a as unknown[]]))
830
+ );
831
+ }
832
+
833
+ /* eslint-enable @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment */
834
+
835
+ return this._decorateFunctionMeta(creator as unknown as MetaDecoration, decorated) as unknown as QueryableStorageEntry<ApiType>;
836
+ }
837
+
838
+ private _decorateStorageEntryAt<ApiType extends ApiTypes> (registry: Registry, creator: StorageEntry, decorateMethod: DecorateMethod<ApiType>, blockHash: Uint8Array): QueryableStorageEntryAt<ApiType> {
839
+ const getArgs = (args: unknown[]): unknown[] => extractStorageArgs(registry, creator, args);
840
+
841
+ // Disable this where it occurs for each field we are decorating
842
+ /* eslint-disable @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment */
843
+
844
+ const decorated: AugmentedQuery<'rxjs', GenericStorageEntryFunction, AnyTuple> & MetaDecoration = decorateMethod((...args: unknown[]): Observable<Codec> =>
845
+ this._rpcCore.state.getStorage(getArgs(args), blockHash));
846
+
847
+ decorated.creator = creator;
848
+
849
+ decorated.hash = decorateMethod((...args: unknown[]): Observable<Hash> =>
850
+ this._rpcCore.state.getStorageHash(getArgs(args), blockHash));
851
+
852
+ decorated.is = <A extends AnyTuple> (key: IStorageKey<AnyTuple>): key is IStorageKey<A> =>
853
+ key.section === creator.section &&
854
+ key.method === creator.method;
855
+
856
+ decorated.key = (...args: unknown[]): string =>
857
+ u8aToHex(compactStripLength(creator(...args))[1]);
858
+
859
+ decorated.keyPrefix = (...keys: unknown[]): string =>
860
+ u8aToHex(creator.keyPrefix(...keys));
861
+
862
+ decorated.size = decorateMethod((...args: unknown[]): Observable<u64> =>
863
+ this._rpcCore.state.getStorageSize(getArgs(args), blockHash));
864
+
865
+ // .keys() & .entries() only available on map types
866
+ if (creator.iterKey && creator.meta.type.isMap) {
867
+ decorated.entries = decorateMethod(
868
+ memo(this.#instanceId, (...args: unknown[]): Observable<[StorageKey, Codec][]> =>
869
+ this._retrieveMapEntries(creator, blockHash, args)));
870
+
871
+ decorated.entriesPaged = decorateMethod(
872
+ memo(this.#instanceId, (opts: PaginationOptions): Observable<[StorageKey, Codec][]> =>
873
+ this._retrieveMapEntriesPaged(creator, blockHash, opts)));
874
+
875
+ decorated.keys = decorateMethod(
876
+ memo(this.#instanceId, (...args: unknown[]): Observable<StorageKey[]> =>
877
+ this._retrieveMapKeys(creator, blockHash, args)));
878
+
879
+ decorated.keysPaged = decorateMethod(
880
+ memo(this.#instanceId, (opts: PaginationOptions): Observable<StorageKey[]> =>
881
+ this._retrieveMapKeysPaged(creator, blockHash, opts)));
882
+ }
883
+
884
+ if (this.supportMulti && creator.meta.type.isMap) {
885
+ // When using double map storage function, user need to pass double map key as an array
886
+ decorated.multi = decorateMethod((args: unknown[]): Observable<Codec[]> =>
887
+ creator.meta.type.asMap.hashers.length === 1
888
+ ? this._retrieveMulti(args.map((a) => [creator, [a]]), blockHash)
889
+ : this._retrieveMulti(args.map((a) => [creator, a as unknown[]]), blockHash)
890
+ );
891
+ }
892
+
893
+ /* eslint-enable @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment */
894
+
895
+ return this._decorateFunctionMeta(creator as unknown as MetaDecoration, decorated) as unknown as QueryableStorageEntry<ApiType>;
896
+ }
897
+
898
+ private _queueStorage (call: [StorageEntry, unknown[]], queue: [Observable<Codec[]>, [StorageEntry, unknown[]][]][]): Observable<Codec> {
899
+ const query = queue === this.#storageSubQ
900
+ ? this._rpcCore.state.subscribeStorage
901
+ : this._rpcCore.state.queryStorageAt;
902
+ let queueIdx = queue.length - 1;
903
+ let valueIdx = 0;
904
+ let valueObs: Observable<Codec[]>;
905
+
906
+ // if we don't have queue entries yet,
907
+ // or the current queue has fired (see from below),
908
+ // or the current queue has the max entries,
909
+ // then we create a new queue
910
+ if (queueIdx === -1 || !queue[queueIdx] || queue[queueIdx][1].length === PAGE_SIZE_Q) {
911
+ queueIdx++;
912
+
913
+ valueObs = from(
914
+ // we delay the execution until the next tick, this allows
915
+ // any queries made in this timeframe to be added to the same
916
+ // queue for a single query
917
+ new Promise<[StorageEntry, unknown[]][]>((resolve): void => {
918
+ nextTick((): void => {
919
+ // get all the calls in this instance, resolve with it
920
+ // and then clear the queue so we don't add more
921
+ // (anything after this will be added to a new queue)
922
+ const calls = queue[queueIdx][1];
923
+
924
+ delete queue[queueIdx];
925
+
926
+ resolve(calls);
927
+ });
928
+ })
929
+ ).pipe(
930
+ switchMap((calls) => query(calls))
931
+ );
932
+
933
+ queue.push([valueObs, [call]]);
934
+ } else {
935
+ valueObs = queue[queueIdx][0];
936
+ valueIdx = queue[queueIdx][1].length;
937
+
938
+ queue[queueIdx][1].push(call);
939
+ }
940
+
941
+ return valueObs.pipe(
942
+ // return the single value at this index
943
+ map((values) => values[valueIdx])
944
+ );
945
+ }
946
+
947
+ // Decorate the base storage call. In the case or rxjs or promise-without-callback (await)
948
+ // we make a subscription, alternatively we push this through a single-shot query
949
+ private _decorateStorageCall<ApiType extends ApiTypes> (creator: StorageEntry, decorateMethod: DecorateMethod<ApiType>): ReturnType<DecorateMethod<ApiType>> {
950
+ const memoed = memo(this.#instanceId, (...args: unknown[]): Observable<Codec> => {
951
+ const call = extractStorageArgs(this.#registry, creator, args);
952
+
953
+ if (!this.hasSubscriptions) {
954
+ return this._rpcCore.state.getStorage(call);
955
+ }
956
+
957
+ return this._queueStorage(call, this.#storageSubQ);
958
+ });
959
+
960
+ return decorateMethod(memoed, {
961
+ methodName: creator.method,
962
+ overrideNoSub: (...args: unknown[]) =>
963
+ this._queueStorage(extractStorageArgs(this.#registry, creator, args), this.#storageGetQ)
964
+ });
965
+ }
966
+
967
+ // retrieve a set of values for a specific set of keys - here we chunk the keys into PAGE_SIZE sizes
968
+ private _retrieveMulti (keys: [StorageEntry, unknown[]][], blockHash?: Uint8Array): Observable<Codec[]> {
969
+ if (!keys.length) {
970
+ return of([]);
971
+ }
972
+
973
+ const query = this.hasSubscriptions && !blockHash
974
+ ? this._rpcCore.state.subscribeStorage
975
+ : this._rpcCore.state.queryStorageAt;
976
+
977
+ if (keys.length <= PAGE_SIZE_V) {
978
+ return blockHash
979
+ ? query(keys, blockHash)
980
+ : query(keys);
981
+ }
982
+
983
+ return combineLatest(
984
+ arrayChunk(keys, PAGE_SIZE_V).map((k) =>
985
+ blockHash
986
+ ? query(k, blockHash)
987
+ : query(k)
988
+ )
989
+ ).pipe(
990
+ map(arrayFlatten)
991
+ );
992
+ }
993
+
994
+ private _retrieveMapKeys ({ iterKey, meta, method, section }: StorageEntry, at: Hash | Uint8Array | string | null, args: unknown[]): Observable<StorageKey[]> {
995
+ if (!iterKey || !meta.type.isMap) {
996
+ throw new Error('keys can only be retrieved on maps');
997
+ }
998
+
999
+ const headKey = iterKey(...args).toHex();
1000
+ const startSubject = new BehaviorSubject<string>(headKey);
1001
+ const query = at
1002
+ ? (startKey: string) =>
1003
+ this._rpcCore.state.getKeysPaged(headKey, PAGE_SIZE_K, startKey, at)
1004
+ : (startKey: string) =>
1005
+ this._rpcCore.state.getKeysPaged(headKey, PAGE_SIZE_K, startKey);
1006
+ const setMeta = (key: StorageKey) => key.setMeta(meta, section, method);
1007
+
1008
+ return startSubject.pipe(
1009
+ switchMap(query),
1010
+ map((keys) => keys.map(setMeta)),
1011
+ tap((keys) =>
1012
+ nextTick((): void => {
1013
+ keys.length === PAGE_SIZE_K
1014
+ ? startSubject.next(keys[PAGE_SIZE_K - 1].toHex())
1015
+ : startSubject.complete();
1016
+ })
1017
+ ),
1018
+ toArray(), // toArray since we want to startSubject to be completed
1019
+ map(arrayFlatten)
1020
+ );
1021
+ }
1022
+
1023
+ private _retrieveMapKeysPaged ({ iterKey, meta, method, section }: StorageEntry, at: Hash | Uint8Array | string | undefined, opts: PaginationOptions): Observable<StorageKey[]> {
1024
+ if (!iterKey || !meta.type.isMap) {
1025
+ throw new Error('keys can only be retrieved on maps');
1026
+ }
1027
+
1028
+ const setMeta = (key: StorageKey) => key.setMeta(meta, section, method);
1029
+ const query = at
1030
+ ? (headKey: string) =>
1031
+ this._rpcCore.state.getKeysPaged(headKey, opts.pageSize, opts.startKey || headKey, at)
1032
+ : (headKey: string) =>
1033
+ this._rpcCore.state.getKeysPaged(headKey, opts.pageSize, opts.startKey || headKey);
1034
+
1035
+ return query(iterKey(...opts.args).toHex()).pipe(
1036
+ map((keys) => keys.map(setMeta))
1037
+ );
1038
+ }
1039
+
1040
+ private _retrieveMapEntries (entry: StorageEntry, at: Hash | Uint8Array | string | null, args: unknown[]): Observable<[StorageKey, Codec][]> {
1041
+ const query = at
1042
+ ? (keys: StorageKey[]) =>
1043
+ this._rpcCore.state.queryStorageAt(keys, at)
1044
+ : (keys: StorageKey[]) =>
1045
+ this._rpcCore.state.queryStorageAt(keys);
1046
+
1047
+ return this._retrieveMapKeys(entry, at, args).pipe(
1048
+ switchMap((keys) =>
1049
+ keys.length
1050
+ ? combineLatest(arrayChunk(keys, PAGE_SIZE_V).map(query)).pipe(
1051
+ map((valsArr) =>
1052
+ arrayFlatten(valsArr).map((value, index): [StorageKey, Codec] => [keys[index], value])
1053
+ )
1054
+ )
1055
+ : of([])
1056
+ )
1057
+ );
1058
+ }
1059
+
1060
+ private _retrieveMapEntriesPaged (entry: StorageEntry, at: Hash | Uint8Array | string | undefined, opts: PaginationOptions): Observable<[StorageKey, Codec][]> {
1061
+ const query = at
1062
+ ? (keys: StorageKey[]) =>
1063
+ this._rpcCore.state.queryStorageAt(keys, at)
1064
+ : (keys: StorageKey[]) =>
1065
+ this._rpcCore.state.queryStorageAt(keys);
1066
+
1067
+ return this._retrieveMapKeysPaged(entry, at, opts).pipe(
1068
+ switchMap((keys) =>
1069
+ keys.length
1070
+ ? query(keys).pipe(
1071
+ map((valsArr) =>
1072
+ valsArr.map((value, index): [StorageKey, Codec] => [keys[index], value])
1073
+ )
1074
+ )
1075
+ : of([])
1076
+ )
1077
+ );
1078
+ }
1079
+
1080
+ protected _decorateDeriveRx (decorateMethod: DecorateMethod<ApiType>): AllDerives<'rxjs'> {
1081
+ const specName = this._runtimeVersion?.specName.toString();
1082
+
1083
+ // Pull in derive from api-derive
1084
+ const available = getAvailableDerives(this.#instanceId, this._rx, objectSpread<DeriveCustom>({}, this._options.derives, this._options.typesBundle?.spec?.[specName || '']?.derives));
1085
+
1086
+ return decorateDeriveSections<'rxjs'>(decorateMethod, available);
1087
+ }
1088
+
1089
+ protected _decorateDerive (decorateMethod: DecorateMethod<ApiType>): AllDerives<ApiType> {
1090
+ return decorateDeriveSections<ApiType>(decorateMethod, this._rx.derive);
1091
+ }
1092
+
1093
+ /**
1094
+ * Put the `this.onCall` function of ApiRx here, because it is needed by
1095
+ * `api._rx`.
1096
+ */
1097
+ protected _rxDecorateMethod = <Method extends AnyFunction>(method: Method): Method => {
1098
+ return method;
1099
+ };
1100
+ }