@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,7 @@
1
+ import { u8aToU8a } from '@pezkuwi/util';
2
+ export function findCall(registry, callIndex) {
3
+ return registry.findMetaCall(u8aToU8a(callIndex));
4
+ }
5
+ export function findError(registry, errorIndex) {
6
+ return registry.findMetaError(u8aToU8a(errorIndex));
7
+ }
@@ -0,0 +1,57 @@
1
+ import { isString, objectSpread, u8aToHex, u8aToU8a } from '@pezkuwi/util';
2
+ import { Getters } from './Getters.js';
3
+ export class ApiBase extends Getters {
4
+ /**
5
+ * @description Create an instance of the class
6
+ *
7
+ * @param options Options object to create API instance or a Provider instance
8
+ *
9
+ * @example
10
+ * <BR>
11
+ *
12
+ * ```javascript
13
+ * import Api from '@pezkuwi/api/promise';
14
+ *
15
+ * const api = new Api().isReady();
16
+ *
17
+ * api.rpc.subscribeNewHeads((header) => {
18
+ * console.log(`new block #${header.number.toNumber()}`);
19
+ * });
20
+ * ```
21
+ */
22
+ constructor(options = {}, type, decorateMethod) {
23
+ super(options, type, decorateMethod);
24
+ }
25
+ /**
26
+ * @description Connect from the underlying provider, halting all network traffic
27
+ */
28
+ connect() {
29
+ return this._rpcCore.connect();
30
+ }
31
+ /**
32
+ * @description Disconnect from the underlying provider, halting all network traffic
33
+ */
34
+ disconnect() {
35
+ this._unsubscribe();
36
+ return this._rpcCore.disconnect();
37
+ }
38
+ /**
39
+ * @description Set an external signer which will be used to sign extrinsic when account passed in is not KeyringPair
40
+ */
41
+ setSigner(signer) {
42
+ this._rx.signer = signer;
43
+ }
44
+ /**
45
+ * @description Signs a raw signer payload, string or Uint8Array
46
+ */
47
+ async sign(address, data, { signer } = {}) {
48
+ if (isString(address)) {
49
+ const _signer = signer || this._rx.signer;
50
+ if (!_signer?.signRaw) {
51
+ throw new Error('No signer exists with a signRaw interface. You possibly need to pass through an explicit keypair for the origin so it can be used for signing.');
52
+ }
53
+ return (await _signer.signRaw(objectSpread({ type: 'bytes' }, data, { address }))).signature;
54
+ }
55
+ return u8aToHex(address.sign(u8aToU8a(data.data)));
56
+ }
57
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,7 @@
1
+ import '@pezkuwi/rpc-augment';
2
+ export { Keyring } from '@pezkuwi/keyring';
3
+ export { HttpProvider, ScProvider, WsProvider } from '@pezkuwi/rpc-provider';
4
+ export { packageInfo } from './packageInfo.js';
5
+ export { SubmittableResult } from './submittable/index.js';
6
+ export * from './promise/index.js';
7
+ export * from './rx/index.js';
@@ -0,0 +1,2 @@
1
+ import './packageDetect.js';
2
+ export * from './bundle.js';
@@ -0,0 +1,8 @@
1
+ import { packageInfo as deriveInfo } from '@pezkuwi/api-derive/packageInfo';
2
+ import { packageInfo as coreInfo } from '@pezkuwi/rpc-core/packageInfo';
3
+ import { packageInfo as providerInfo } from '@pezkuwi/rpc-provider/packageInfo';
4
+ import { packageInfo as typesInfo } from '@pezkuwi/types/packageInfo';
5
+ import { packageInfo as knownInfo } from '@pezkuwi/types-known/packageInfo';
6
+ import { detectPackage } from '@pezkuwi/util';
7
+ import { packageInfo } from './packageInfo.js';
8
+ detectPackage(packageInfo, null, [coreInfo, deriveInfo, knownInfo, providerInfo, typesInfo]);
@@ -0,0 +1 @@
1
+ export const packageInfo = { name: '@pezkuwi/api', path: (import.meta && import.meta.url) ? new URL(import.meta.url).pathname.substring(0, new URL(import.meta.url).pathname.lastIndexOf('/') + 1) : 'auto', type: 'esm', version: '16.5.8' };
@@ -0,0 +1,191 @@
1
+ import { noop, objectSpread } from '@pezkuwi/util';
2
+ import { ApiBase } from '../base/index.js';
3
+ import { Combinator } from './Combinator.js';
4
+ import { promiseTracker, toPromiseMethod } from './decorateMethod.js';
5
+ /**
6
+ * # @pezkuwi/api/promise
7
+ *
8
+ * ## Overview
9
+ *
10
+ * @name ApiPromise
11
+ * @description
12
+ * 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.
13
+ *
14
+ * 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.
15
+ *
16
+ * @see [[ApiRx]]
17
+ *
18
+ * ## Usage
19
+ *
20
+ * Making rpc calls -
21
+ * <BR>
22
+ *
23
+ * ```javascript
24
+ * import ApiPromise from '@pezkuwi/api/promise';
25
+ *
26
+ * // initialise via static create
27
+ * const api = await ApiPromise.create();
28
+ *
29
+ * // make a subscription to the network head
30
+ * api.rpc.chain.subscribeNewHeads((header) => {
31
+ * console.log(`Chain is at #${header.number}`);
32
+ * });
33
+ * ```
34
+ * <BR>
35
+ *
36
+ * Subscribing to chain state -
37
+ * <BR>
38
+ *
39
+ * ```javascript
40
+ * import { ApiPromise, WsProvider } from '@pezkuwi/api';
41
+ *
42
+ * // initialise a provider with a specific endpoint
43
+ * const provider = new WsProvider('wss://example.com:9944')
44
+ *
45
+ * // initialise via isReady & new with specific provider
46
+ * const api = await new ApiPromise({ provider }).isReady;
47
+ *
48
+ * // retrieve the block target time
49
+ * const blockPeriod = await api.query.timestamp.blockPeriod().toNumber();
50
+ * let last = 0;
51
+ *
52
+ * // subscribe to the current block timestamp, updates automatically (callback provided)
53
+ * api.query.timestamp.now((timestamp) => {
54
+ * const elapsed = last
55
+ * ? `, ${timestamp.toNumber() - last}s since last`
56
+ * : '';
57
+ *
58
+ * last = timestamp.toNumber();
59
+ * console.log(`timestamp ${timestamp}${elapsed} (${blockPeriod}s target)`);
60
+ * });
61
+ * ```
62
+ * <BR>
63
+ *
64
+ * Submitting a transaction -
65
+ * <BR>
66
+ *
67
+ * ```javascript
68
+ * import ApiPromise from '@pezkuwi/api/promise';
69
+ *
70
+ * ApiPromise.create().then((api) => {
71
+ * const [nonce] = await api.query.system.account(keyring.alice.address);
72
+ *
73
+ * api.tx.balances
74
+ * // create transfer
75
+ * transfer(keyring.bob.address, 12345)
76
+ * // sign the transcation
77
+ * .sign(keyring.alice, { nonce })
78
+ * // send the transaction (optional status callback)
79
+ * .send((status) => {
80
+ * console.log(`current status ${status.type}`);
81
+ * })
82
+ * // retrieve the submitted extrinsic hash
83
+ * .then((hash) => {
84
+ * console.log(`submitted with hash ${hash}`);
85
+ * });
86
+ * });
87
+ * ```
88
+ */
89
+ export class ApiPromise extends ApiBase {
90
+ #isReadyPromise;
91
+ #isReadyOrErrorPromise;
92
+ /**
93
+ * @description Creates an instance of the ApiPromise class
94
+ * @param options Options to create an instance. This can be either [[ApiOptions]] or
95
+ * an [[WsProvider]].
96
+ * @example
97
+ * <BR>
98
+ *
99
+ * ```javascript
100
+ * import Api from '@pezkuwi/api/promise';
101
+ *
102
+ * new Api().isReady.then((api) => {
103
+ * api.rpc.subscribeNewHeads((header) => {
104
+ * console.log(`new block #${header.number.toNumber()}`);
105
+ * });
106
+ * });
107
+ * ```
108
+ */
109
+ constructor(options) {
110
+ super(options, 'promise', toPromiseMethod);
111
+ this.#isReadyPromise = new Promise((resolve) => {
112
+ super.once('ready', () => resolve(this));
113
+ });
114
+ this.#isReadyOrErrorPromise = new Promise((resolve, reject) => {
115
+ const tracker = promiseTracker(resolve, reject);
116
+ super.once('ready', () => tracker.resolve(this));
117
+ super.once('error', (error) => tracker.reject(error));
118
+ });
119
+ }
120
+ /**
121
+ * @description Creates an ApiPromise instance using the supplied provider. Returns an Promise containing the actual Api instance.
122
+ * @param options options that is passed to the class contructor. Can be either [[ApiOptions]] or a
123
+ * provider (see the constructor arguments)
124
+ * @example
125
+ * <BR>
126
+ *
127
+ * ```javascript
128
+ * import Api from '@pezkuwi/api/promise';
129
+ *
130
+ * Api.create().then(async (api) => {
131
+ * const timestamp = await api.query.timestamp.now();
132
+ *
133
+ * console.log(`lastest block timestamp ${timestamp}`);
134
+ * });
135
+ * ```
136
+ */
137
+ static create(options) {
138
+ const instance = new ApiPromise(options);
139
+ if (options && options.throwOnConnect) {
140
+ return instance.isReadyOrError;
141
+ }
142
+ // Swallow any rejections on isReadyOrError
143
+ // (in Node 15.x this creates issues, when not being looked at)
144
+ instance.isReadyOrError.catch(noop);
145
+ return instance.isReady;
146
+ }
147
+ /**
148
+ * @description Promise that resolves the first time we are connected and loaded
149
+ */
150
+ get isReady() {
151
+ return this.#isReadyPromise;
152
+ }
153
+ /**
154
+ * @description Promise that resolves if we can connect, or reject if there is an error
155
+ */
156
+ get isReadyOrError() {
157
+ return this.#isReadyOrErrorPromise;
158
+ }
159
+ /**
160
+ * @description Returns a clone of this ApiPromise instance (new underlying provider connection)
161
+ */
162
+ clone() {
163
+ return new ApiPromise(objectSpread({}, this._options, { source: this }));
164
+ }
165
+ /**
166
+ * @description Creates a combinator that can be used to combine the latest results from multiple subscriptions
167
+ * @param fns An array of function to combine, each in the form of `(cb: (value: void)) => void`
168
+ * @param callback A callback that will return an Array of all the values this combinator has been applied to
169
+ * @example
170
+ * <BR>
171
+ *
172
+ * ```javascript
173
+ * const address = '5DTestUPts3kjeXSTMyerHihn1uwMfLj8vU8sqF7qYrFacT7';
174
+ *
175
+ * // combines values from balance & nonce as it updates
176
+ * api.combineLatest([
177
+ * api.rpc.chain.subscribeNewHeads,
178
+ * (cb) => api.query.system.account(address, cb)
179
+ * ], ([head, [balance, nonce]]) => {
180
+ * console.log(`#${head.number}: You have ${balance.free} units, with ${nonce} transactions sent`);
181
+ * });
182
+ * ```
183
+ */
184
+ // eslint-disable-next-line @typescript-eslint/require-await
185
+ async combineLatest(fns, callback) {
186
+ const combinator = new Combinator(fns, callback);
187
+ return () => {
188
+ combinator.unsubscribe();
189
+ };
190
+ }
191
+ }
@@ -0,0 +1,68 @@
1
+ import { isFunction, noop } from '@pezkuwi/util';
2
+ export class Combinator {
3
+ #allHasFired = false;
4
+ #callback;
5
+ #fired = [];
6
+ #fns = [];
7
+ #isActive = true;
8
+ #results = [];
9
+ #subscriptions = [];
10
+ constructor(fns, callback) {
11
+ this.#callback = callback;
12
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises, @typescript-eslint/require-await
13
+ this.#subscriptions = fns.map(async (input, index) => {
14
+ const [fn, ...args] = Array.isArray(input)
15
+ ? input
16
+ : [input];
17
+ this.#fired.push(false);
18
+ this.#fns.push(fn);
19
+ // Not quite 100% how to have a variable number at the front here
20
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return,@typescript-eslint/ban-types
21
+ return fn(...args, this._createCallback(index));
22
+ });
23
+ }
24
+ _allHasFired() {
25
+ this.#allHasFired ||= this.#fired.filter((hasFired) => !hasFired).length === 0;
26
+ return this.#allHasFired;
27
+ }
28
+ _createCallback(index) {
29
+ return (value) => {
30
+ this.#fired[index] = true;
31
+ this.#results[index] = value;
32
+ this._triggerUpdate();
33
+ };
34
+ }
35
+ _triggerUpdate() {
36
+ if (!this.#isActive || !isFunction(this.#callback) || !this._allHasFired()) {
37
+ return;
38
+ }
39
+ try {
40
+ Promise
41
+ .resolve(this.#callback(this.#results))
42
+ .catch(noop);
43
+ }
44
+ catch {
45
+ // swallow, we don't want the handler to trip us up
46
+ }
47
+ }
48
+ unsubscribe() {
49
+ if (!this.#isActive) {
50
+ return;
51
+ }
52
+ this.#isActive = false;
53
+ Promise
54
+ .all(this.#subscriptions.map(async (subscription) => {
55
+ try {
56
+ const unsubscribe = await subscription;
57
+ if (isFunction(unsubscribe)) {
58
+ unsubscribe();
59
+ }
60
+ }
61
+ catch {
62
+ // ignore
63
+ }
64
+ })).catch(() => {
65
+ // ignore, already ignored above, should never throw
66
+ });
67
+ }
68
+ }
@@ -0,0 +1,71 @@
1
+ import { catchError, EMPTY, tap } from 'rxjs';
2
+ import { isFunction, nextTick } from '@pezkuwi/util';
3
+ export function promiseTracker(resolve, reject) {
4
+ let isCompleted = false;
5
+ return {
6
+ reject: (error) => {
7
+ if (!isCompleted) {
8
+ isCompleted = true;
9
+ reject(error);
10
+ }
11
+ return EMPTY;
12
+ },
13
+ resolve: (value) => {
14
+ if (!isCompleted) {
15
+ isCompleted = true;
16
+ resolve(value);
17
+ }
18
+ }
19
+ };
20
+ }
21
+ function extractArgs(args, needsCallback) {
22
+ const actualArgs = args.slice();
23
+ // If the last arg is a function, we pop it, put it into callback.
24
+ // actualArgs will then hold the actual arguments to be passed to `method`
25
+ const callback = (args.length && isFunction(args[args.length - 1]))
26
+ ? actualArgs.pop()
27
+ : undefined;
28
+ // When we need a subscription, ensure that a valid callback is actually passed
29
+ if (needsCallback && !isFunction(callback)) {
30
+ throw new Error('Expected a callback to be passed with subscriptions');
31
+ }
32
+ return [actualArgs, callback];
33
+ }
34
+ function decorateCall(method, args) {
35
+ return new Promise((resolve, reject) => {
36
+ // single result tracker - either reject with Error or resolve with Codec result
37
+ const tracker = promiseTracker(resolve, reject);
38
+ // encoding errors reject immediately, any result unsubscribes and resolves
39
+ const subscription = method(...args)
40
+ .pipe(catchError((error) => tracker.reject(error)))
41
+ .subscribe((result) => {
42
+ tracker.resolve(result);
43
+ nextTick(() => subscription.unsubscribe());
44
+ });
45
+ });
46
+ }
47
+ function decorateSubscribe(method, args, resultCb) {
48
+ return new Promise((resolve, reject) => {
49
+ // either reject with error or resolve with unsubscribe callback
50
+ const tracker = promiseTracker(resolve, reject);
51
+ // errors reject immediately, the first result resolves with an unsubscribe promise, all results via callback
52
+ const subscription = method(...args)
53
+ .pipe(catchError((error) => tracker.reject(error)), tap(() => tracker.resolve(() => subscription.unsubscribe())))
54
+ .subscribe((result) => {
55
+ // queue result (back of queue to clear current)
56
+ nextTick(() => resultCb(result));
57
+ });
58
+ });
59
+ }
60
+ /**
61
+ * @description Decorate method for ApiPromise, where the results are converted to the Promise equivalent
62
+ */
63
+ export function toPromiseMethod(method, options) {
64
+ const needsCallback = !!(options?.methodName && options.methodName.includes('subscribe'));
65
+ return function (...args) {
66
+ const [actualArgs, resultCb] = extractArgs(args, needsCallback);
67
+ return resultCb
68
+ ? decorateSubscribe(method, actualArgs, resultCb)
69
+ : decorateCall(options?.overrideNoSub || method, actualArgs);
70
+ };
71
+ }
@@ -0,0 +1,2 @@
1
+ export { ApiPromise } from './Api.js';
2
+ export { toPromiseMethod } from './decorateMethod.js';
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,169 @@
1
+ import { from } from 'rxjs';
2
+ import { objectSpread } from '@pezkuwi/util';
3
+ import { ApiBase } from '../base/index.js';
4
+ import { toRxMethod } from './decorateMethod.js';
5
+ /**
6
+ * # @pezkuwi/api/rx
7
+ *
8
+ * ## Overview
9
+ *
10
+ * @name ApiRx
11
+ *
12
+ * @description
13
+ * ApiRx is a powerful RxJS Observable wrapper around the RPC and interfaces on the Pezkuwi network. As a full Observable API, all interface calls return RxJS Observables, including the static `.create(...)`. In the same fashion and subscription-based methods return long-running Observables that update with the latest values.
14
+ *
15
+ * The API is well suited to real-time applications where the latest state is needed, unlocking the subscription-based features of Pezkuwi (and Bizinikiwi) clients. Some familiarity with RxJS is a requirement to use the API, however just understanding `.subscribe` and `.pipe` on Observables will unlock full-scale use thereof.
16
+ *
17
+ * @see [[ApiPromise]]
18
+ *
19
+ * ## Usage
20
+ *
21
+ * Making rpc calls -
22
+ * <BR>
23
+ *
24
+ * ```javascript
25
+ * import ApiRx from '@pezkuwi/api/rx';
26
+ *
27
+ * // initialize via Promise & static create
28
+ * const api = await ApiRx.create().toPromise();
29
+ *
30
+ * // make a call to retrieve the current network head
31
+ * api.rpc.chain.subscribeNewHeads().subscribe((header) => {
32
+ * console.log(`Chain is at #${header.number}`);
33
+ * });
34
+ * ```
35
+ * <BR>
36
+ *
37
+ * Subscribing to chain state -
38
+ * <BR>
39
+ *
40
+ * ```javascript
41
+ * import { combineLatest, pairwise, switchMap } from 'rxjs';
42
+ * import { ApiRx, WsProvider } from '@pezkuwi/api';
43
+ *
44
+ *
45
+ * // initialize a provider with a specific endpoint
46
+ * const provider = new WsProvider('wss://example.com:9944')
47
+ *
48
+ * // initialize via isReady & new with specific provider
49
+ * new ApiRx({ provider })
50
+ * .isReady
51
+ * .pipe(
52
+ * switchMap((api) =>
53
+ * combineLatest([
54
+ * api.query.timestamp.blockPeriod(),
55
+ * api.query.timestamp.now().pipe(pairwise())
56
+ * ])
57
+ * )
58
+ * )
59
+ * .subscribe(([blockPeriod, timestamp]) => {
60
+ * const elapsed = timestamp[1].toNumber() - timestamp[0].toNumber();
61
+ * console.log(`timestamp ${timestamp[1]} \nelapsed ${elapsed} \n(${blockPeriod}s target)`);
62
+ * });
63
+ * ```
64
+ * <BR>
65
+ *
66
+ * Submitting a transaction -
67
+ * <BR>
68
+ *
69
+ * ```javascript
70
+ * import { first, switchMap } from 'rxjs';
71
+ * import ApiRx from '@pezkuwi/api/rx';
72
+ *
73
+ * // import the test keyring (already has dev keys for Alice, Bob, Charlie, Eve & Ferdie)
74
+ * import testingPairs from '@pezkuwi/keyring/testingPairs';
75
+ * const keyring = testingPairs();
76
+ *
77
+ * // get api via Promise
78
+ * const api = await ApiRx.create().toPromise();
79
+ *
80
+ * // retrieve nonce for the account
81
+ * api.query.system
82
+ * .account(keyring.alice.address)
83
+ * .pipe(
84
+ * first(),
85
+ * // pipe nonce into transfer
86
+ * switchMap(([nonce]) =>
87
+ * api.tx.balances
88
+ * // create transfer
89
+ * .transferAllowDeath(keyring.bob.address, 12345)
90
+ * // sign the transaction
91
+ * .sign(keyring.alice, { nonce })
92
+ * // send the transaction
93
+ * .send()
94
+ * )
95
+ * )
96
+ * // subscribe to overall result
97
+ * .subscribe(({ status }) => {
98
+ * if (status.isInBlock) {
99
+ * console.log('Completed at block hash', status.asFinalized.toHex());
100
+ * }
101
+ * });
102
+ * ```
103
+ */
104
+ export class ApiRx extends ApiBase {
105
+ #isReadyRx;
106
+ /**
107
+ * @description Create an instance of the ApiRx class
108
+ * @param options Options to create an instance. Can be either [[ApiOptions]] or [[WsProvider]]
109
+ * @example
110
+ * <BR>
111
+ *
112
+ * ```javascript
113
+ * import { switchMap } from 'rxjs';
114
+ * import Api from '@pezkuwi/api/rx';
115
+ *
116
+ * new Api().isReady
117
+ * .pipe(
118
+ * switchMap((api) =>
119
+ * api.rpc.chain.subscribeNewHeads()
120
+ * ))
121
+ * .subscribe((header) => {
122
+ * console.log(`new block #${header.number.toNumber()}`);
123
+ * });
124
+ * ```
125
+ */
126
+ constructor(options) {
127
+ super(options, 'rxjs', toRxMethod);
128
+ this.#isReadyRx = from(
129
+ // You can create an observable from an event, however my mind groks this form better
130
+ new Promise((resolve) => {
131
+ super.on('ready', () => resolve(this));
132
+ }));
133
+ }
134
+ /**
135
+ * @description Creates an ApiRx instance using the supplied provider. Returns an Observable containing the actual Api instance.
136
+ * @param options options that is passed to the class constructor. Can be either [[ApiOptions]] or [[WsProvider]]
137
+ * @example
138
+ * <BR>
139
+ *
140
+ * ```javascript
141
+ * import { switchMap } from 'rxjs';
142
+ * import Api from '@pezkuwi/api/rx';
143
+ *
144
+ * Api.create()
145
+ * .pipe(
146
+ * switchMap((api) =>
147
+ * api.rpc.chain.subscribeNewHeads()
148
+ * ))
149
+ * .subscribe((header) => {
150
+ * console.log(`new block #${header.number.toNumber()}`);
151
+ * });
152
+ * ```
153
+ */
154
+ static create(options) {
155
+ return new ApiRx(options).isReady;
156
+ }
157
+ /**
158
+ * @description Observable that returns the first time we are connected and loaded
159
+ */
160
+ get isReady() {
161
+ return this.#isReadyRx;
162
+ }
163
+ /**
164
+ * @description Returns a clone of this ApiRx instance (new underlying provider connection)
165
+ */
166
+ clone() {
167
+ return new ApiRx(objectSpread({}, this._options, { source: this }));
168
+ }
169
+ }
@@ -0,0 +1,3 @@
1
+ export function toRxMethod(method) {
2
+ return method;
3
+ }
@@ -0,0 +1,2 @@
1
+ export { ApiRx } from './Api.js';
2
+ export { toRxMethod } from './decorateMethod.js';