@pezkuwi/api 16.5.5 → 16.5.6

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