@pezkuwi/api 16.5.6 → 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 (379) hide show
  1. package/build/LICENSE +201 -0
  2. package/build/README.md +100 -0
  3. package/build/augment.d.ts +1 -0
  4. package/build/augment.js +1 -0
  5. package/build/base/Decorate.d.ts +143 -0
  6. package/build/base/Decorate.js +752 -0
  7. package/build/base/Events.d.ts +67 -0
  8. package/build/base/Events.js +78 -0
  9. package/build/base/Getters.d.ts +163 -0
  10. package/build/base/Getters.js +207 -0
  11. package/build/base/Init.d.ts +44 -0
  12. package/build/base/Init.js +400 -0
  13. package/build/base/find.d.ts +3 -0
  14. package/build/base/find.js +7 -0
  15. package/build/base/index.d.ts +47 -0
  16. package/build/base/index.js +57 -0
  17. package/build/base/types.d.ts +15 -0
  18. package/build/base/types.js +1 -0
  19. package/build/bundle-pezkuwi-api.js +26247 -0
  20. package/build/bundle.d.ts +7 -0
  21. package/build/bundle.js +7 -0
  22. package/build/cjs/augment.d.ts +1 -0
  23. package/build/cjs/augment.js +3 -0
  24. package/build/cjs/base/Decorate.d.ts +143 -0
  25. package/build/cjs/base/Decorate.js +756 -0
  26. package/build/cjs/base/Events.d.ts +67 -0
  27. package/build/cjs/base/Events.js +82 -0
  28. package/build/cjs/base/Getters.d.ts +163 -0
  29. package/build/cjs/base/Getters.js +211 -0
  30. package/build/cjs/base/Init.d.ts +44 -0
  31. package/build/cjs/base/Init.js +404 -0
  32. package/build/cjs/base/find.d.ts +3 -0
  33. package/build/cjs/base/find.js +11 -0
  34. package/build/cjs/base/index.d.ts +47 -0
  35. package/build/cjs/base/index.js +61 -0
  36. package/build/cjs/base/types.d.ts +15 -0
  37. package/build/cjs/base/types.js +2 -0
  38. package/build/cjs/bundle.d.ts +7 -0
  39. package/build/cjs/bundle.js +17 -0
  40. package/build/cjs/index.d.ts +2 -0
  41. package/build/cjs/index.js +5 -0
  42. package/build/cjs/package.json +3 -0
  43. package/build/cjs/packageDetect.d.ts +1 -0
  44. package/build/cjs/packageDetect.js +10 -0
  45. package/build/cjs/packageInfo.d.ts +6 -0
  46. package/build/cjs/packageInfo.js +4 -0
  47. package/build/cjs/promise/Api.d.ts +158 -0
  48. package/build/cjs/promise/Api.js +195 -0
  49. package/build/cjs/promise/Combinator.d.ts +12 -0
  50. package/build/cjs/promise/Combinator.js +72 -0
  51. package/build/cjs/promise/decorateMethod.d.ts +14 -0
  52. package/build/cjs/promise/decorateMethod.js +75 -0
  53. package/build/cjs/promise/index.d.ts +2 -0
  54. package/build/cjs/promise/index.js +7 -0
  55. package/build/cjs/promise/types.d.ts +5 -0
  56. package/build/cjs/promise/types.js +2 -0
  57. package/build/cjs/rx/Api.d.ts +155 -0
  58. package/build/cjs/rx/Api.js +173 -0
  59. package/build/cjs/rx/decorateMethod.d.ts +3 -0
  60. package/build/cjs/rx/decorateMethod.js +6 -0
  61. package/build/cjs/rx/index.d.ts +2 -0
  62. package/build/cjs/rx/index.js +7 -0
  63. package/build/cjs/submittable/Result.d.ts +31 -0
  64. package/build/cjs/submittable/Result.js +84 -0
  65. package/build/cjs/submittable/createClass.d.ts +12 -0
  66. package/build/cjs/submittable/createClass.js +277 -0
  67. package/build/cjs/submittable/createSubmittable.d.ts +8 -0
  68. package/build/cjs/submittable/createSubmittable.js +8 -0
  69. package/build/cjs/submittable/index.d.ts +2 -0
  70. package/build/cjs/submittable/index.js +7 -0
  71. package/build/cjs/submittable/types.d.ts +1 -0
  72. package/build/cjs/submittable/types.js +2 -0
  73. package/build/cjs/types/calls.d.ts +1 -0
  74. package/build/cjs/types/calls.js +4 -0
  75. package/build/cjs/types/consts.d.ts +1 -0
  76. package/build/cjs/types/consts.js +4 -0
  77. package/build/cjs/types/errors.d.ts +1 -0
  78. package/build/cjs/types/errors.js +4 -0
  79. package/build/cjs/types/events.d.ts +1 -0
  80. package/build/cjs/types/events.js +4 -0
  81. package/build/cjs/types/index.d.ts +114 -0
  82. package/build/cjs/types/index.js +13 -0
  83. package/build/cjs/types/storage.d.ts +1 -0
  84. package/build/cjs/types/storage.js +4 -0
  85. package/build/cjs/types/submittable.d.ts +1 -0
  86. package/build/cjs/types/submittable.js +4 -0
  87. package/build/cjs/util/augmentObject.d.ts +9 -0
  88. package/build/cjs/util/augmentObject.js +84 -0
  89. package/build/cjs/util/decorate.d.ts +16 -0
  90. package/build/cjs/util/decorate.js +17 -0
  91. package/build/cjs/util/filterEvents.d.ts +6 -0
  92. package/build/cjs/util/filterEvents.js +25 -0
  93. package/build/cjs/util/index.d.ts +4 -0
  94. package/build/cjs/util/index.js +11 -0
  95. package/build/cjs/util/isKeyringPair.d.ts +3 -0
  96. package/build/cjs/util/isKeyringPair.js +7 -0
  97. package/build/cjs/util/logging.d.ts +1 -0
  98. package/build/cjs/util/logging.js +5 -0
  99. package/build/cjs/util/validate.d.ts +3 -0
  100. package/build/cjs/util/validate.js +26 -0
  101. package/build/index.d.ts +2 -0
  102. package/build/index.js +2 -0
  103. package/build/package.json +612 -0
  104. package/build/packageDetect.d.ts +1 -0
  105. package/build/packageDetect.js +8 -0
  106. package/build/packageInfo.d.ts +6 -0
  107. package/build/packageInfo.js +1 -0
  108. package/build/promise/Api.d.ts +158 -0
  109. package/build/promise/Api.js +191 -0
  110. package/build/promise/Combinator.d.ts +12 -0
  111. package/build/promise/Combinator.js +68 -0
  112. package/build/promise/decorateMethod.d.ts +14 -0
  113. package/build/promise/decorateMethod.js +71 -0
  114. package/build/promise/index.d.ts +2 -0
  115. package/build/promise/index.js +2 -0
  116. package/build/promise/types.d.ts +5 -0
  117. package/build/promise/types.js +1 -0
  118. package/build/rx/Api.d.ts +155 -0
  119. package/build/rx/Api.js +169 -0
  120. package/build/rx/decorateMethod.d.ts +3 -0
  121. package/build/rx/decorateMethod.js +3 -0
  122. package/build/rx/index.d.ts +2 -0
  123. package/build/rx/index.js +2 -0
  124. package/build/submittable/Result.d.ts +31 -0
  125. package/build/submittable/Result.js +80 -0
  126. package/build/submittable/createClass.d.ts +12 -0
  127. package/build/submittable/createClass.js +274 -0
  128. package/build/submittable/createSubmittable.d.ts +8 -0
  129. package/build/submittable/createSubmittable.js +5 -0
  130. package/build/submittable/index.d.ts +2 -0
  131. package/build/submittable/index.js +2 -0
  132. package/build/submittable/types.d.ts +1 -0
  133. package/build/submittable/types.js +1 -0
  134. package/build/types/calls.d.ts +1 -0
  135. package/build/types/calls.js +1 -0
  136. package/build/types/consts.d.ts +1 -0
  137. package/build/types/consts.js +1 -0
  138. package/build/types/errors.d.ts +1 -0
  139. package/build/types/errors.js +1 -0
  140. package/build/types/events.d.ts +1 -0
  141. package/build/types/events.js +1 -0
  142. package/build/types/index.d.ts +114 -0
  143. package/build/types/index.js +8 -0
  144. package/build/types/storage.d.ts +1 -0
  145. package/build/types/storage.js +1 -0
  146. package/build/types/submittable.d.ts +1 -0
  147. package/build/types/submittable.js +1 -0
  148. package/build/util/augmentObject.d.ts +9 -0
  149. package/build/util/augmentObject.js +81 -0
  150. package/build/util/decorate.d.ts +16 -0
  151. package/build/util/decorate.js +14 -0
  152. package/build/util/filterEvents.d.ts +6 -0
  153. package/build/util/filterEvents.js +22 -0
  154. package/build/util/index.d.ts +4 -0
  155. package/build/util/index.js +4 -0
  156. package/build/util/isKeyringPair.d.ts +3 -0
  157. package/build/util/isKeyringPair.js +4 -0
  158. package/build/util/logging.d.ts +1 -0
  159. package/build/util/logging.js +2 -0
  160. package/build/util/validate.d.ts +3 -0
  161. package/build/util/validate.js +23 -0
  162. package/build-deno/README.md +95 -0
  163. package/build-deno/augment.ts +2 -0
  164. package/build-deno/base/Decorate.ts +1100 -0
  165. package/build-deno/base/Events.ts +89 -0
  166. package/build-deno/base/Getters.ts +243 -0
  167. package/build-deno/base/Init.ts +523 -0
  168. package/build-deno/base/find.ts +12 -0
  169. package/build-deno/base/index.ts +83 -0
  170. package/build-deno/base/types.ts +17 -0
  171. package/build-deno/bundle.ts +11 -0
  172. package/build-deno/checkTypes.manual.ts +320 -0
  173. package/build-deno/index.ts +4 -0
  174. package/build-deno/mod.ts +2 -0
  175. package/build-deno/packageDetect.ts +12 -0
  176. package/build-deno/packageInfo.ts +3 -0
  177. package/build-deno/promise/Api.ts +212 -0
  178. package/build-deno/promise/Combinator.ts +89 -0
  179. package/build-deno/promise/decorateMethod.ts +111 -0
  180. package/build-deno/promise/index.ts +3 -0
  181. package/build-deno/promise/types.ts +7 -0
  182. package/build-deno/rx/Api.ts +184 -0
  183. package/build-deno/rx/decorateMethod.ts +7 -0
  184. package/build-deno/rx/index.ts +3 -0
  185. package/build-deno/submittable/Result.ts +109 -0
  186. package/build-deno/submittable/createClass.ts +436 -0
  187. package/build-deno/submittable/createSubmittable.ts +17 -0
  188. package/build-deno/submittable/index.ts +3 -0
  189. package/build-deno/submittable/types.ts +2 -0
  190. package/build-deno/test/SingleAccountSigner.ts +51 -0
  191. package/build-deno/test/index.ts +3 -0
  192. package/build-deno/test/logEvents.ts +21 -0
  193. package/build-deno/types/calls.ts +2 -0
  194. package/build-deno/types/consts.ts +2 -0
  195. package/build-deno/types/errors.ts +2 -0
  196. package/build-deno/types/events.ts +2 -0
  197. package/build-deno/types/index.ts +124 -0
  198. package/build-deno/types/storage.ts +2 -0
  199. package/build-deno/types/submittable.ts +2 -0
  200. package/build-deno/util/augmentObject.ts +109 -0
  201. package/build-deno/util/decorate.ts +38 -0
  202. package/build-deno/util/filterEvents.ts +32 -0
  203. package/build-deno/util/index.ts +6 -0
  204. package/build-deno/util/isKeyringPair.ts +9 -0
  205. package/build-deno/util/logging.ts +4 -0
  206. package/build-deno/util/validate.ts +32 -0
  207. package/build-tsc/augment.d.ts +1 -0
  208. package/build-tsc/base/Decorate.d.ts +143 -0
  209. package/build-tsc/base/Events.d.ts +67 -0
  210. package/build-tsc/base/Getters.d.ts +163 -0
  211. package/build-tsc/base/Init.d.ts +44 -0
  212. package/build-tsc/base/find.d.ts +3 -0
  213. package/build-tsc/base/index.d.ts +47 -0
  214. package/build-tsc/base/types.d.ts +15 -0
  215. package/build-tsc/bundle.d.ts +7 -0
  216. package/build-tsc/index.d.ts +2 -0
  217. package/build-tsc/packageDetect.d.ts +1 -0
  218. package/build-tsc/packageInfo.d.ts +6 -0
  219. package/build-tsc/promise/Api.d.ts +158 -0
  220. package/build-tsc/promise/Combinator.d.ts +12 -0
  221. package/build-tsc/promise/decorateMethod.d.ts +14 -0
  222. package/build-tsc/promise/index.d.ts +2 -0
  223. package/build-tsc/promise/types.d.ts +5 -0
  224. package/build-tsc/rx/Api.d.ts +155 -0
  225. package/build-tsc/rx/decorateMethod.d.ts +3 -0
  226. package/build-tsc/rx/index.d.ts +2 -0
  227. package/build-tsc/submittable/Result.d.ts +31 -0
  228. package/build-tsc/submittable/createClass.d.ts +12 -0
  229. package/build-tsc/submittable/createSubmittable.d.ts +8 -0
  230. package/build-tsc/submittable/index.d.ts +2 -0
  231. package/build-tsc/submittable/types.d.ts +1 -0
  232. package/build-tsc/types/calls.d.ts +1 -0
  233. package/build-tsc/types/consts.d.ts +1 -0
  234. package/build-tsc/types/errors.d.ts +1 -0
  235. package/build-tsc/types/events.d.ts +1 -0
  236. package/build-tsc/types/index.d.ts +114 -0
  237. package/build-tsc/types/storage.d.ts +1 -0
  238. package/build-tsc/types/submittable.d.ts +1 -0
  239. package/build-tsc/util/augmentObject.d.ts +9 -0
  240. package/build-tsc/util/decorate.d.ts +16 -0
  241. package/build-tsc/util/filterEvents.d.ts +6 -0
  242. package/build-tsc/util/index.d.ts +4 -0
  243. package/build-tsc/util/isKeyringPair.d.ts +3 -0
  244. package/build-tsc/util/logging.d.ts +1 -0
  245. package/build-tsc/util/validate.d.ts +3 -0
  246. package/build-tsc-cjs/augment.js +3 -0
  247. package/build-tsc-cjs/base/Decorate.js +756 -0
  248. package/build-tsc-cjs/base/Events.js +82 -0
  249. package/build-tsc-cjs/base/Getters.js +211 -0
  250. package/build-tsc-cjs/base/Init.js +404 -0
  251. package/build-tsc-cjs/base/find.js +11 -0
  252. package/build-tsc-cjs/base/index.js +61 -0
  253. package/build-tsc-cjs/base/types.js +2 -0
  254. package/build-tsc-cjs/bundle.js +17 -0
  255. package/build-tsc-cjs/index.js +5 -0
  256. package/build-tsc-cjs/packageDetect.js +10 -0
  257. package/build-tsc-cjs/packageInfo.js +4 -0
  258. package/build-tsc-cjs/promise/Api.js +195 -0
  259. package/build-tsc-cjs/promise/Combinator.js +72 -0
  260. package/build-tsc-cjs/promise/decorateMethod.js +75 -0
  261. package/build-tsc-cjs/promise/index.js +7 -0
  262. package/build-tsc-cjs/promise/types.js +2 -0
  263. package/build-tsc-cjs/rx/Api.js +173 -0
  264. package/build-tsc-cjs/rx/decorateMethod.js +6 -0
  265. package/build-tsc-cjs/rx/index.js +7 -0
  266. package/build-tsc-cjs/submittable/Result.js +84 -0
  267. package/build-tsc-cjs/submittable/createClass.js +277 -0
  268. package/build-tsc-cjs/submittable/createSubmittable.js +8 -0
  269. package/build-tsc-cjs/submittable/index.js +7 -0
  270. package/build-tsc-cjs/submittable/types.js +2 -0
  271. package/build-tsc-cjs/types/calls.js +4 -0
  272. package/build-tsc-cjs/types/consts.js +4 -0
  273. package/build-tsc-cjs/types/errors.js +4 -0
  274. package/build-tsc-cjs/types/events.js +4 -0
  275. package/build-tsc-cjs/types/index.js +13 -0
  276. package/build-tsc-cjs/types/storage.js +4 -0
  277. package/build-tsc-cjs/types/submittable.js +4 -0
  278. package/build-tsc-cjs/util/augmentObject.js +84 -0
  279. package/build-tsc-cjs/util/decorate.js +17 -0
  280. package/build-tsc-cjs/util/filterEvents.js +25 -0
  281. package/build-tsc-cjs/util/index.js +11 -0
  282. package/build-tsc-cjs/util/isKeyringPair.js +7 -0
  283. package/build-tsc-cjs/util/logging.js +5 -0
  284. package/build-tsc-cjs/util/validate.js +26 -0
  285. package/build-tsc-esm/augment.js +1 -0
  286. package/build-tsc-esm/base/Decorate.js +752 -0
  287. package/build-tsc-esm/base/Events.js +78 -0
  288. package/build-tsc-esm/base/Getters.js +207 -0
  289. package/build-tsc-esm/base/Init.js +400 -0
  290. package/build-tsc-esm/base/find.js +7 -0
  291. package/build-tsc-esm/base/index.js +57 -0
  292. package/build-tsc-esm/base/types.js +1 -0
  293. package/build-tsc-esm/bundle.js +7 -0
  294. package/build-tsc-esm/index.js +2 -0
  295. package/build-tsc-esm/packageDetect.js +8 -0
  296. package/build-tsc-esm/packageInfo.js +1 -0
  297. package/build-tsc-esm/promise/Api.js +191 -0
  298. package/build-tsc-esm/promise/Combinator.js +68 -0
  299. package/build-tsc-esm/promise/decorateMethod.js +71 -0
  300. package/build-tsc-esm/promise/index.js +2 -0
  301. package/build-tsc-esm/promise/types.js +1 -0
  302. package/build-tsc-esm/rx/Api.js +169 -0
  303. package/build-tsc-esm/rx/decorateMethod.js +3 -0
  304. package/build-tsc-esm/rx/index.js +2 -0
  305. package/build-tsc-esm/submittable/Result.js +80 -0
  306. package/build-tsc-esm/submittable/createClass.js +274 -0
  307. package/build-tsc-esm/submittable/createSubmittable.js +5 -0
  308. package/build-tsc-esm/submittable/index.js +2 -0
  309. package/build-tsc-esm/submittable/types.js +1 -0
  310. package/build-tsc-esm/types/calls.js +1 -0
  311. package/build-tsc-esm/types/consts.js +1 -0
  312. package/build-tsc-esm/types/errors.js +1 -0
  313. package/build-tsc-esm/types/events.js +1 -0
  314. package/build-tsc-esm/types/index.js +8 -0
  315. package/build-tsc-esm/types/storage.js +1 -0
  316. package/build-tsc-esm/types/submittable.js +1 -0
  317. package/build-tsc-esm/util/augmentObject.js +81 -0
  318. package/build-tsc-esm/util/decorate.js +14 -0
  319. package/build-tsc-esm/util/filterEvents.js +22 -0
  320. package/build-tsc-esm/util/index.js +4 -0
  321. package/build-tsc-esm/util/isKeyringPair.js +4 -0
  322. package/build-tsc-esm/util/logging.js +2 -0
  323. package/build-tsc-esm/util/validate.js +23 -0
  324. package/bundle-pezkuwi-api.js +26240 -26231
  325. package/cjs/packageInfo.js +1 -1
  326. package/package.json +12 -12
  327. package/packageInfo.js +1 -1
  328. package/src/augment.ts +4 -0
  329. package/src/base/Decorate.ts +1103 -0
  330. package/src/base/Events.ts +91 -0
  331. package/src/base/Getters.ts +245 -0
  332. package/src/base/Init.ts +525 -0
  333. package/src/base/find.ts +14 -0
  334. package/src/base/index.ts +85 -0
  335. package/src/base/types.ts +19 -0
  336. package/src/bundle.ts +16 -0
  337. package/src/checkTypes.manual.ts +323 -0
  338. package/src/index.ts +6 -0
  339. package/src/mod.ts +4 -0
  340. package/src/packageDetect.ts +16 -0
  341. package/src/packageInfo.ts +6 -0
  342. package/src/promise/Api.ts +214 -0
  343. package/src/promise/Combinator.ts +91 -0
  344. package/src/promise/Combinators.spec.ts +109 -0
  345. package/src/promise/decorateMethod.ts +118 -0
  346. package/src/promise/index.spec.ts +167 -0
  347. package/src/promise/index.ts +5 -0
  348. package/src/promise/types.ts +9 -0
  349. package/src/rx/Api.ts +186 -0
  350. package/src/rx/decorateMethod.ts +9 -0
  351. package/src/rx/index.ts +5 -0
  352. package/src/submittable/Result.ts +111 -0
  353. package/src/submittable/createClass.ts +438 -0
  354. package/src/submittable/createSubmittable.ts +19 -0
  355. package/src/submittable/index.ts +5 -0
  356. package/src/submittable/types.ts +4 -0
  357. package/src/test/SingleAccountSigner.ts +53 -0
  358. package/src/test/index.ts +5 -0
  359. package/src/test/logEvents.ts +24 -0
  360. package/src/types/calls.ts +4 -0
  361. package/src/types/consts.ts +4 -0
  362. package/src/types/errors.ts +4 -0
  363. package/src/types/events.ts +4 -0
  364. package/src/types/index.ts +137 -0
  365. package/src/types/storage.ts +4 -0
  366. package/src/types/submittable.ts +4 -0
  367. package/src/util/augmentObject.spec.ts +54 -0
  368. package/src/util/augmentObject.ts +112 -0
  369. package/src/util/decorate.ts +43 -0
  370. package/src/util/filterEvents.ts +34 -0
  371. package/src/util/index.ts +10 -0
  372. package/src/util/isKeyringPair.ts +11 -0
  373. package/src/util/logging.ts +6 -0
  374. package/src/util/validate.spec.ts +72 -0
  375. package/src/util/validate.ts +36 -0
  376. package/tsconfig.build.json +25 -0
  377. package/tsconfig.build.tsbuildinfo +1 -0
  378. package/tsconfig.spec.json +26 -0
  379. package/tsconfig.spec.tsbuildinfo +1 -0
@@ -0,0 +1,320 @@
1
+
2
+
3
+ import 'https://deno.land/x/pezkuwi/api-augment/mod.ts';
4
+
5
+ import type { HeaderExtended } from 'https://deno.land/x/pezkuwi/api-derive/types.ts';
6
+ import type { TestKeyringMapBizinikiwi } from 'https://deno.land/x/pezkuwi/keyring/testingPairs.ts';
7
+ import type { StorageKey } from 'https://deno.land/x/pezkuwi/types/mod.ts';
8
+ import type { AccountId, Balance, DispatchErrorModule, Event, Header, Index } from 'https://deno.land/x/pezkuwi/types/interfaces/index.ts';
9
+ import type { PezframeSystemAccountInfo } from 'https://deno.land/x/pezkuwi/types/lookup.ts';
10
+ import type { AnyTuple, IExtrinsic, IMethod } from 'https://deno.land/x/pezkuwi/types/types/index.ts';
11
+ import type { SubmittableResult } from './index.ts';
12
+
13
+ import { ApiPromise } from 'https://deno.land/x/pezkuwi/api/mod.ts';
14
+ import { createTestPairs } from 'https://deno.land/x/pezkuwi/keyring/testingPairs.ts';
15
+ import { createTypeUnsafe, TypeRegistry } from 'https://deno.land/x/pezkuwi/types/create/index.ts';
16
+
17
+ const registry = new TypeRegistry();
18
+
19
+ async function calls (api: ApiPromise): Promise<void> {
20
+ // it allows defaults
21
+ const testSetId = await api.call.grandpaApi.currentSetId();
22
+
23
+ // it allows type overrides (generally shouldn't be used, but available)
24
+ const testSetIdO = await api.call.grandpaApi.currentSetId<AccountId>();
25
+
26
+ // it allows actual params
27
+ const nonce = await api.call.accountNonceApi.accountNonce('5Test');
28
+
29
+ console.log(testSetId.toNumber(), testSetIdO.isAscii, nonce.toNumber());
30
+ }
31
+
32
+ function consts (api: ApiPromise): void {
33
+ // constants has actual value & metadata
34
+ console.log(
35
+ api.consts['notIn']['augmentation'],
36
+ api.consts.balances.existentialDeposit.toNumber(),
37
+ api.consts.balances.existentialDeposit.meta.docs.map((s) => s.toString()).join(''),
38
+ api.consts.system.blockWeights.maxBlock.refTime.toNumber()
39
+ );
40
+ }
41
+
42
+ async function derive (api: ApiPromise): Promise<void> {
43
+ await api.derive.chain.subscribeNewHeads((header: HeaderExtended): void => {
44
+ console.log('current author:', header.author);
45
+ });
46
+
47
+ const info = await api.derive.balances.account('0x1234');
48
+
49
+ console.log('info', info);
50
+ }
51
+
52
+ function errors (api: ApiPromise): void {
53
+ const someError = {} as DispatchErrorModule;
54
+
55
+ // existing
56
+ console.log(api.errors.vesting.AmountLow.is(someError));
57
+
58
+ // non-existing error, existing module
59
+ console.log(api.errors.vesting['NonAugmented'].is(someError));
60
+
61
+ // something random
62
+ console.log(api.errors['thisIsNot']['Augmented'].is(someError));
63
+ }
64
+
65
+ function events (api: ApiPromise): void {
66
+ const event = {} as Event;
67
+
68
+ // existing
69
+ if (api.events.balances.Transfer.is(event)) {
70
+ // the types are correctly expanded
71
+ const [afrom, ato, aamount] = event.data;
72
+
73
+ console.log(
74
+ afrom.toHuman(),
75
+ ato.toHuman(),
76
+ aamount.toBn()
77
+ );
78
+
79
+ // the types have getters
80
+ const { amount, from, to } = event.data;
81
+
82
+ console.log(
83
+ from.toHuman(),
84
+ to.toHuman(),
85
+ amount.toBn()
86
+ );
87
+ }
88
+
89
+ // something with only tuple data
90
+ if (api.events.staking.Bonded.is(event)) {
91
+ const [account, amount] = event.data;
92
+
93
+ console.log(account.toHuman(), amount.toBn());
94
+ }
95
+
96
+ // something random, just codec[]
97
+ if (api.events['not']['Augmented'].is(event)) {
98
+ const [a, b] = event.data;
99
+
100
+ console.log(a.toHuman(), b.toHuman());
101
+ }
102
+ }
103
+
104
+ async function query (api: ApiPromise, pairs: TestKeyringMapBizinikiwi): Promise<void> {
105
+ const intentions = await api.query.staking.bonded();
106
+
107
+ console.log('intentions:', intentions);
108
+
109
+ // api.query.*.* is well-typed
110
+ const bar = await api.query['notIn']['augmentation'](); // bar is Codec (unknown module)
111
+ const bal = await api.query.balances.totalIssuance(); // bal is Balance
112
+ const bal2 = await api.query.balances.totalIssuance('WRONG_ARG'); // bal2 is Codec (wrong args)
113
+ const override = await api.query.balances.totalIssuance<Header>(); // override is still available
114
+
115
+ // eslint-disable-next-line deprecation/deprecation
116
+ const oldBal = await api.query.balances.totalIssuance.at('abcd');
117
+
118
+ // For older queries we can cast with `<Balance>` (newer chain have multi typed)
119
+ const multia = await api.query.balances['freeBalance'].multi<Balance>([pairs.alice.address, pairs.bob.address]);
120
+ const multib = await api.query.system.account.multi([pairs.alice.address, pairs.bob.address]);
121
+
122
+ await api.query.system.account(pairs.alice.address);
123
+ await api.query.system.account<PezframeSystemAccountInfo>(pairs.alice.address);
124
+
125
+ console.log('query types:', bar, bal, bal2, override, oldBal, multia, multib);
126
+ }
127
+
128
+ async function queryExtra (api: ApiPromise): Promise<void> {
129
+ // events destructing
130
+ await api.query.system.events((records): void => {
131
+ records.forEach(({ event, phase }): void => {
132
+ if (phase.isApplyExtrinsic) {
133
+ // Dunno... this should work
134
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
135
+ // @ts-ignore
136
+ const [accountId, value]: [AccountId, Balance] = event.data;
137
+
138
+ console.log(`${accountId.toString()} has ${value.toHuman()}`);
139
+ }
140
+ });
141
+ });
142
+
143
+ // at queries
144
+ // eslint-disable-next-line deprecation/deprecation
145
+ const events = await api.query.system.events.at('0x12345');
146
+
147
+ console.log(`Received ${events.length} events:`);
148
+
149
+ // check entries()
150
+ await api.query.system.account.entries(); // should not take a param
151
+ await api.query.staking.nominatorSlashInEra.entries(123); // should take a param
152
+
153
+ // nmap with keys
154
+ await api.query.assets.approvals.keys(123, 'blah');
155
+ await api.query.assets.account.keys(123);
156
+ await api.query.assets.account.entries(123);
157
+ await api.query.assets['notAugmented'].keys();
158
+
159
+ // is
160
+ const key = {} as StorageKey;
161
+
162
+ if (api.query.balances.account.is(key)) {
163
+ const [accountId] = key.args;
164
+
165
+ // should be AccountId type
166
+ console.log(accountId.toHuman());
167
+ }
168
+ }
169
+
170
+ async function queryMulti (api: ApiPromise, pairs: TestKeyringMapBizinikiwi): Promise<void> {
171
+ // check multi for unsub
172
+ const multiUnsub = await api.queryMulti([
173
+ [api.query.staking.validators],
174
+ [api.query.system.events]
175
+ ], (values): void => {
176
+ console.log('values', values);
177
+
178
+ multiUnsub();
179
+ });
180
+
181
+ // check multi , Promise result
182
+ const multiRes = await api.queryMulti([
183
+ [api.query.system.account, pairs.eve.address],
184
+ // older chains only
185
+ [api.query.system['accountNonce'], pairs.eve.address]
186
+ ]);
187
+
188
+ console.log(multiRes);
189
+
190
+ // check multi, via at
191
+ const apiAt = await api.at('0x12345678');
192
+ const multiResAt = await apiAt.queryMulti([
193
+ api.query.timestamp.now,
194
+ [apiAt.query.staking.validators],
195
+ [apiAt.query.system.account, pairs.eve.address]
196
+ ]);
197
+
198
+ console.log(multiResAt);
199
+ }
200
+
201
+ async function rpc (api: ApiPromise): Promise<void> {
202
+ // defaults
203
+ await api.rpc.chain.subscribeNewHeads((header): void => {
204
+ console.log('current header #', header.number.toNumber());
205
+ });
206
+
207
+ // with generic params
208
+ await api.rpc.state.subscribeStorage<[Balance]>(['my_balance_key'], ([balance]): void => {
209
+ console.log('current balance:', balance.toString());
210
+ });
211
+
212
+ // using json & raw
213
+ await api.rpc.chain.getBlock.raw('0x123456');
214
+
215
+ // using raw subs
216
+ await api.rpc.chain.subscribeNewHeads.raw((result: Uint8Array): void => {
217
+ console.log(result);
218
+ });
219
+
220
+ // deprecated methods
221
+ // eslint-disable-next-line deprecation/deprecation
222
+ await api.rpc.state.getPairs('123');
223
+ }
224
+
225
+ function types (api: ApiPromise): void {
226
+ // check correct types with `createType`
227
+ const balance = registry.createType('Balance', 2);
228
+ const gas = registry.createType('Gas', 2);
229
+ const compact = registry.createType('Compact<u32>', 2);
230
+ const f32 = registry.createType('f32');
231
+ const u32 = registry.createType('u32');
232
+ const raw = registry.createType('Raw');
233
+ // const random = registry.createType('RandomType', 2); // This one should deliberately show a TS error
234
+
235
+ const gasUnsafe = createTypeUnsafe(registry, 'Gas', [2]);
236
+ const overriddenUnsafe = createTypeUnsafe<Header>(registry, 'Gas', [2]);
237
+
238
+ console.log(balance, gas, compact, gasUnsafe, overriddenUnsafe, u32.toNumber(), f32.toNumber(), api.createType('AccountData'), raw.subarray(0, 10));
239
+ }
240
+
241
+ async function tx (api: ApiPromise, pairs: TestKeyringMapBizinikiwi): Promise<void> {
242
+ // transfer, also allows for bigint inputs here
243
+ const transfer = api.tx.balances.transferAllowDeath(pairs.bob.address, BigInt(123456789));
244
+
245
+ console.log('transfer casted', transfer as IMethod<AnyTuple>, transfer as IExtrinsic<AnyTuple>);
246
+
247
+ // simple "return the hash" variant
248
+ console.log('hash:', (await transfer.signAndSend(pairs.alice)).toHex());
249
+
250
+ // passing options, but waiting for hash
251
+ const nonce = await api.query.system['accountNonce']<Index>(pairs.alice.address);
252
+
253
+ (await api.tx.balances
254
+ .transferAllowDeath(pairs.bob.address, 12345)
255
+ .signAndSend(pairs.alice, { nonce })
256
+ ).toHex();
257
+
258
+ // just with the callback
259
+ await api.tx.balances
260
+ .transferAllowDeath(pairs.bob.address, 12345)
261
+ .signAndSend(pairs.alice, ({ status }: SubmittableResult) => console.log(status.type));
262
+
263
+ // with options and the callback
264
+ const nonce2 = await api.query.system['accountNonce'](pairs.alice.address);
265
+ const unsub2 = await api.tx.balances
266
+ .transferAllowDeath(pairs.bob.address, 12345)
267
+ .signAndSend(pairs.alice, { nonce: nonce2 }, ({ status }: SubmittableResult): void => {
268
+ console.log('transfer status:', status.type);
269
+
270
+ unsub2();
271
+ });
272
+
273
+ // it allows for query & then using the submittable
274
+ const second = api.tx.democracy.second(123);
275
+
276
+ await second.signAndSend('123', (result) => console.log(result));
277
+
278
+ // it handles enum inputs correctly
279
+ await api.tx.democracy['proxyVote'](123, { Split: { nay: 456, yay: 123 } }).signAndSend(pairs.alice);
280
+
281
+ // is
282
+ if (api.tx.balances.transferAllowDeath.is(second)) {
283
+ const [recipientId, balance] = second.args;
284
+
285
+ // should be LookupSource & Balance types
286
+ console.log(recipientId.toHuman(), balance.toNumber());
287
+ }
288
+ }
289
+
290
+ async function at (api: ApiPromise): Promise<void> {
291
+ const apiAt = await api.at('0x1234');
292
+
293
+ // get old balances
294
+ console.log(await apiAt.query.balances['freeBalance']('0x1234'));
295
+
296
+ // get some constants
297
+ console.log(apiAt.consts.balances.existentialDeposit);
298
+ }
299
+
300
+ async function main (): Promise<void> {
301
+ const api = await ApiPromise.create();
302
+ const pairs = createTestPairs();
303
+
304
+ await Promise.all([
305
+ calls(api),
306
+ consts(api),
307
+ derive(api),
308
+ errors(api),
309
+ events(api),
310
+ query(api, pairs),
311
+ queryExtra(api),
312
+ queryMulti(api, pairs),
313
+ rpc(api),
314
+ types(api),
315
+ tx(api, pairs),
316
+ at(api)
317
+ ]);
318
+ }
319
+
320
+ main().catch(console.error);
@@ -0,0 +1,4 @@
1
+
2
+ import './packageDetect.ts';
3
+
4
+ export * from './bundle.ts';
@@ -0,0 +1,2 @@
1
+
2
+ export * from './index.ts';
@@ -0,0 +1,12 @@
1
+
2
+
3
+ import { packageInfo as deriveInfo } from 'https://deno.land/x/pezkuwi/api-derive/packageInfo.ts';
4
+ import { packageInfo as coreInfo } from 'https://deno.land/x/pezkuwi/rpc-core/packageInfo.ts';
5
+ import { packageInfo as providerInfo } from 'https://deno.land/x/pezkuwi/rpc-provider/packageInfo.ts';
6
+ import { packageInfo as typesInfo } from 'https://deno.land/x/pezkuwi/types/packageInfo.ts';
7
+ import { packageInfo as knownInfo } from 'https://deno.land/x/pezkuwi/types-known/packageInfo.ts';
8
+ import { detectPackage } from 'https://deno.land/x/pezkuwi/util/mod.ts';
9
+
10
+ import { packageInfo } from './packageInfo.ts';
11
+
12
+ detectPackage(packageInfo, null, [coreInfo, deriveInfo, knownInfo, providerInfo, typesInfo]);
@@ -0,0 +1,3 @@
1
+
2
+
3
+ export const packageInfo = { name: '@pezkuwi/api', path: new URL(import.meta.url).pathname, type: 'deno', version: '16.5.8' };
@@ -0,0 +1,212 @@
1
+
2
+ import type { ApiOptions, UnsubscribePromise } from '../types/index.ts';
3
+ import type { CombinatorCallback, CombinatorFunction } from './Combinator.ts';
4
+
5
+ import { noop, objectSpread } from 'https://deno.land/x/pezkuwi/util/mod.ts';
6
+
7
+ import { ApiBase } from '../base/index.ts';
8
+ import { Combinator } from './Combinator.ts';
9
+ import { promiseTracker, toPromiseMethod } from './decorateMethod.ts';
10
+
11
+ /**
12
+ * # @pezkuwi/api/promise
13
+ *
14
+ * ## Overview
15
+ *
16
+ * @name ApiPromise
17
+ * @description
18
+ * ApiPromise is a standard JavaScript wrapper around the RPC and interfaces on the Pezkuwi network. As a full Promise-based, all interface calls return Promises, including the static `.create(...)`. Subscription calls utilise `(value) => {}` callbacks to pass through the latest values.
19
+ *
20
+ * The API is well suited to real-time applications where either the single-shot state is needed or use is to be made of the subscription-based features of Pezkuwi (and Bizinikiwi) clients.
21
+ *
22
+ * @see [[ApiRx]]
23
+ *
24
+ * ## Usage
25
+ *
26
+ * Making rpc calls -
27
+ * <BR>
28
+ *
29
+ * ```javascript
30
+ * import ApiPromise from 'https://deno.land/x/pezkuwi/api/promise/index.ts';
31
+ *
32
+ * // initialise via static create
33
+ * const api = await ApiPromise.create();
34
+ *
35
+ * // make a subscription to the network head
36
+ * api.rpc.chain.subscribeNewHeads((header) => {
37
+ * console.log(`Chain is at #${header.number}`);
38
+ * });
39
+ * ```
40
+ * <BR>
41
+ *
42
+ * Subscribing to chain state -
43
+ * <BR>
44
+ *
45
+ * ```javascript
46
+ * import { ApiPromise, WsProvider } from 'https://deno.land/x/pezkuwi/api/mod.ts';
47
+ *
48
+ * // initialise a provider with a specific endpoint
49
+ * const provider = new WsProvider('wss://example.com:9944')
50
+ *
51
+ * // initialise via isReady & new with specific provider
52
+ * const api = await new ApiPromise({ provider }).isReady;
53
+ *
54
+ * // retrieve the block target time
55
+ * const blockPeriod = await api.query.timestamp.blockPeriod().toNumber();
56
+ * let last = 0;
57
+ *
58
+ * // subscribe to the current block timestamp, updates automatically (callback provided)
59
+ * api.query.timestamp.now((timestamp) => {
60
+ * const elapsed = last
61
+ * ? `, ${timestamp.toNumber() - last}s since last`
62
+ * : '';
63
+ *
64
+ * last = timestamp.toNumber();
65
+ * console.log(`timestamp ${timestamp}${elapsed} (${blockPeriod}s target)`);
66
+ * });
67
+ * ```
68
+ * <BR>
69
+ *
70
+ * Submitting a transaction -
71
+ * <BR>
72
+ *
73
+ * ```javascript
74
+ * import ApiPromise from 'https://deno.land/x/pezkuwi/api/promise/index.ts';
75
+ *
76
+ * ApiPromise.create().then((api) => {
77
+ * const [nonce] = await api.query.system.account(keyring.alice.address);
78
+ *
79
+ * api.tx.balances
80
+ * // create transfer
81
+ * transfer(keyring.bob.address, 12345)
82
+ * // sign the transcation
83
+ * .sign(keyring.alice, { nonce })
84
+ * // send the transaction (optional status callback)
85
+ * .send((status) => {
86
+ * console.log(`current status ${status.type}`);
87
+ * })
88
+ * // retrieve the submitted extrinsic hash
89
+ * .then((hash) => {
90
+ * console.log(`submitted with hash ${hash}`);
91
+ * });
92
+ * });
93
+ * ```
94
+ */
95
+ export class ApiPromise extends ApiBase<'promise'> {
96
+ #isReadyPromise: Promise<ApiPromise>;
97
+ #isReadyOrErrorPromise: Promise<ApiPromise>;
98
+
99
+ /**
100
+ * @description Creates an instance of the ApiPromise class
101
+ * @param options Options to create an instance. This can be either [[ApiOptions]] or
102
+ * an [[WsProvider]].
103
+ * @example
104
+ * <BR>
105
+ *
106
+ * ```javascript
107
+ * import Api from 'https://deno.land/x/pezkuwi/api/promise/index.ts';
108
+ *
109
+ * new Api().isReady.then((api) => {
110
+ * api.rpc.subscribeNewHeads((header) => {
111
+ * console.log(`new block #${header.number.toNumber()}`);
112
+ * });
113
+ * });
114
+ * ```
115
+ */
116
+ constructor (options?: ApiOptions) {
117
+ super(options, 'promise', toPromiseMethod);
118
+
119
+ this.#isReadyPromise = new Promise((resolve): void => {
120
+ super.once('ready', () => resolve(this));
121
+ });
122
+
123
+ this.#isReadyOrErrorPromise = new Promise((resolve, reject): void => {
124
+ const tracker = promiseTracker(resolve, reject);
125
+
126
+ super.once('ready', () => tracker.resolve(this));
127
+ super.once('error', (error: Error) => tracker.reject(error));
128
+ });
129
+ }
130
+
131
+ /**
132
+ * @description Creates an ApiPromise instance using the supplied provider. Returns an Promise containing the actual Api instance.
133
+ * @param options options that is passed to the class contructor. Can be either [[ApiOptions]] or a
134
+ * provider (see the constructor arguments)
135
+ * @example
136
+ * <BR>
137
+ *
138
+ * ```javascript
139
+ * import Api from 'https://deno.land/x/pezkuwi/api/promise/index.ts';
140
+ *
141
+ * Api.create().then(async (api) => {
142
+ * const timestamp = await api.query.timestamp.now();
143
+ *
144
+ * console.log(`lastest block timestamp ${timestamp}`);
145
+ * });
146
+ * ```
147
+ */
148
+ public static create (options?: ApiOptions): Promise<ApiPromise> {
149
+ const instance = new ApiPromise(options);
150
+
151
+ if (options && options.throwOnConnect) {
152
+ return instance.isReadyOrError;
153
+ }
154
+
155
+ // Swallow any rejections on isReadyOrError
156
+ // (in Node 15.x this creates issues, when not being looked at)
157
+ instance.isReadyOrError.catch(noop);
158
+
159
+ return instance.isReady;
160
+ }
161
+
162
+ /**
163
+ * @description Promise that resolves the first time we are connected and loaded
164
+ */
165
+ public get isReady (): Promise<ApiPromise> {
166
+ return this.#isReadyPromise;
167
+ }
168
+
169
+ /**
170
+ * @description Promise that resolves if we can connect, or reject if there is an error
171
+ */
172
+ public get isReadyOrError (): Promise<ApiPromise> {
173
+ return this.#isReadyOrErrorPromise;
174
+ }
175
+
176
+ /**
177
+ * @description Returns a clone of this ApiPromise instance (new underlying provider connection)
178
+ */
179
+ public clone (): ApiPromise {
180
+ return new ApiPromise(
181
+ objectSpread({}, this._options, { source: this })
182
+ );
183
+ }
184
+
185
+ /**
186
+ * @description Creates a combinator that can be used to combine the latest results from multiple subscriptions
187
+ * @param fns An array of function to combine, each in the form of `(cb: (value: void)) => void`
188
+ * @param callback A callback that will return an Array of all the values this combinator has been applied to
189
+ * @example
190
+ * <BR>
191
+ *
192
+ * ```javascript
193
+ * const address = '5DTestUPts3kjeXSTMyerHihn1uwMfLj8vU8sqF7qYrFacT7';
194
+ *
195
+ * // combines values from balance & nonce as it updates
196
+ * api.combineLatest([
197
+ * api.rpc.chain.subscribeNewHeads,
198
+ * (cb) => api.query.system.account(address, cb)
199
+ * ], ([head, [balance, nonce]]) => {
200
+ * console.log(`#${head.number}: You have ${balance.free} units, with ${nonce} transactions sent`);
201
+ * });
202
+ * ```
203
+ */
204
+ // eslint-disable-next-line @typescript-eslint/require-await
205
+ public async combineLatest <T extends any[] = any[]> (fns: (CombinatorFunction | [CombinatorFunction, ...any[]])[], callback: CombinatorCallback<T>): UnsubscribePromise {
206
+ const combinator = new Combinator(fns, callback);
207
+
208
+ return (): void => {
209
+ combinator.unsubscribe();
210
+ };
211
+ }
212
+ }
@@ -0,0 +1,89 @@
1
+
2
+ import type { Callback } from 'https://deno.land/x/pezkuwi/types/types/index.ts';
3
+ import type { UnsubscribePromise } from '../types/index.ts';
4
+
5
+ import { isFunction, noop } from 'https://deno.land/x/pezkuwi/util/mod.ts';
6
+
7
+ export type CombinatorCallback <T extends unknown[]> = Callback<T>;
8
+
9
+ export type CombinatorFunction = (cb: Callback<any>) => UnsubscribePromise;
10
+
11
+ export class Combinator<T extends unknown[] = unknown[]> {
12
+ #allHasFired = false;
13
+ #callback: CombinatorCallback<T>;
14
+ #fired: boolean[] = [];
15
+ #fns: CombinatorFunction[] = [];
16
+ #isActive = true;
17
+ #results: unknown[] = [];
18
+ #subscriptions: UnsubscribePromise[] = [];
19
+
20
+ constructor (fns: (CombinatorFunction | [CombinatorFunction, ...unknown[]])[], callback: CombinatorCallback<T>) {
21
+ this.#callback = callback;
22
+
23
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises, @typescript-eslint/require-await
24
+ this.#subscriptions = fns.map(async (input, index): UnsubscribePromise => {
25
+ const [fn, ...args] = Array.isArray(input)
26
+ ? input
27
+ : [input];
28
+
29
+ this.#fired.push(false);
30
+ this.#fns.push(fn);
31
+
32
+ // Not quite 100% how to have a variable number at the front here
33
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return,@typescript-eslint/ban-types
34
+ return (fn as Function)(...args, this._createCallback(index));
35
+ });
36
+ }
37
+
38
+ protected _allHasFired (): boolean {
39
+ this.#allHasFired ||= this.#fired.filter((hasFired): boolean => !hasFired).length === 0;
40
+
41
+ return this.#allHasFired;
42
+ }
43
+
44
+ protected _createCallback (index: number): (value: any) => void {
45
+ return (value: unknown): void => {
46
+ this.#fired[index] = true;
47
+ this.#results[index] = value;
48
+
49
+ this._triggerUpdate();
50
+ };
51
+ }
52
+
53
+ protected _triggerUpdate (): void {
54
+ if (!this.#isActive || !isFunction(this.#callback) || !this._allHasFired()) {
55
+ return;
56
+ }
57
+
58
+ try {
59
+ Promise
60
+ .resolve(this.#callback(this.#results as T))
61
+ .catch(noop);
62
+ } catch {
63
+ // swallow, we don't want the handler to trip us up
64
+ }
65
+ }
66
+
67
+ public unsubscribe (): void {
68
+ if (!this.#isActive) {
69
+ return;
70
+ }
71
+
72
+ this.#isActive = false;
73
+
74
+ Promise
75
+ .all(this.#subscriptions.map(async (subscription): Promise<void> => {
76
+ try {
77
+ const unsubscribe = await subscription;
78
+
79
+ if (isFunction(unsubscribe)) {
80
+ unsubscribe();
81
+ }
82
+ } catch {
83
+ // ignore
84
+ }
85
+ })).catch(() => {
86
+ // ignore, already ignored above, should never throw
87
+ });
88
+ }
89
+ }