@dedot/api 0.18.8 → 1.0.0

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 (102) hide show
  1. package/chaintypes/substrate/consts.d.ts +2 -2
  2. package/chaintypes/substrate/consts.js +1 -0
  3. package/chaintypes/substrate/errors.d.ts +909 -909
  4. package/chaintypes/substrate/errors.js +1 -0
  5. package/chaintypes/substrate/events.d.ts +664 -664
  6. package/chaintypes/substrate/events.js +1 -0
  7. package/chaintypes/substrate/index.d.ts +13 -16
  8. package/chaintypes/substrate/index.js +1 -0
  9. package/chaintypes/substrate/json-rpc.d.ts +2 -2
  10. package/chaintypes/substrate/json-rpc.js +1 -0
  11. package/chaintypes/substrate/query.d.ts +509 -527
  12. package/chaintypes/substrate/query.js +1 -0
  13. package/chaintypes/substrate/runtime.d.ts +123 -123
  14. package/chaintypes/substrate/runtime.js +1 -0
  15. package/chaintypes/substrate/tx.d.ts +1311 -1311
  16. package/chaintypes/substrate/tx.js +1 -0
  17. package/chaintypes/substrate/types.js +1 -0
  18. package/chaintypes/substrate/view-functions.d.ts +2 -2
  19. package/chaintypes/substrate/view-functions.js +1 -0
  20. package/cjs/chaintypes/substrate/consts.js +1 -0
  21. package/cjs/chaintypes/substrate/errors.js +1 -0
  22. package/cjs/chaintypes/substrate/events.js +1 -0
  23. package/cjs/chaintypes/substrate/index.js +1 -0
  24. package/cjs/chaintypes/substrate/json-rpc.js +1 -0
  25. package/cjs/chaintypes/substrate/query.js +1 -0
  26. package/cjs/chaintypes/substrate/runtime.js +1 -0
  27. package/cjs/chaintypes/substrate/tx.js +1 -0
  28. package/cjs/chaintypes/substrate/types.js +1 -0
  29. package/cjs/chaintypes/substrate/view-functions.js +1 -0
  30. package/cjs/client/BaseSubstrateClient.js +45 -2
  31. package/cjs/client/DedotClient.js +356 -224
  32. package/cjs/client/LegacyClient.js +99 -23
  33. package/cjs/client/V2Client.js +316 -0
  34. package/cjs/client/explorer/LegacyBlockExplorer.js +263 -0
  35. package/cjs/client/explorer/V2BlockExplorer.js +74 -0
  36. package/cjs/client/explorer/index.js +18 -0
  37. package/cjs/client/utils.js +57 -0
  38. package/cjs/executor/EventExecutor.js +1 -0
  39. package/cjs/executor/RuntimeApiExecutor.js +49 -2
  40. package/cjs/executor/StorageQueryExecutor.js +114 -2
  41. package/cjs/executor/ViewFunctionExecutor.js +21 -2
  42. package/cjs/executor/v2/StorageQueryExecutorV2.js +7 -1
  43. package/cjs/executor/validation-helpers.js +181 -0
  44. package/cjs/extrinsic/submittable/BaseSubmittableExtrinsic.js +86 -2
  45. package/cjs/extrinsic/submittable/SubmittableExtrinsic.js +38 -16
  46. package/cjs/extrinsic/submittable/SubmittableExtrinsicV2.js +12 -2
  47. package/cjs/json-rpc/group/ChainHead/ChainHead.js +226 -21
  48. package/cjs/storage/QueryableStorage.js +1 -0
  49. package/client/BaseSubstrateClient.d.ts +34 -18
  50. package/client/BaseSubstrateClient.js +47 -4
  51. package/client/DedotClient.d.ts +346 -49
  52. package/client/DedotClient.js +356 -224
  53. package/client/LegacyClient.d.ts +22 -17
  54. package/client/LegacyClient.js +101 -25
  55. package/client/V2Client.d.ts +75 -0
  56. package/client/V2Client.js +312 -0
  57. package/client/explorer/LegacyBlockExplorer.d.ts +68 -0
  58. package/client/explorer/LegacyBlockExplorer.js +259 -0
  59. package/client/explorer/V2BlockExplorer.d.ts +40 -0
  60. package/client/explorer/V2BlockExplorer.js +70 -0
  61. package/client/explorer/index.d.ts +2 -0
  62. package/client/explorer/index.js +2 -0
  63. package/client/utils.d.ts +18 -0
  64. package/client/utils.js +52 -0
  65. package/executor/ConstantExecutor.d.ts +1 -2
  66. package/executor/ErrorExecutor.d.ts +2 -2
  67. package/executor/EventExecutor.d.ts +2 -2
  68. package/executor/EventExecutor.js +1 -0
  69. package/executor/Executor.d.ts +4 -5
  70. package/executor/RuntimeApiExecutor.d.ts +2 -2
  71. package/executor/RuntimeApiExecutor.js +27 -3
  72. package/executor/StorageQueryExecutor.d.ts +3 -2
  73. package/executor/StorageQueryExecutor.js +92 -3
  74. package/executor/TxExecutor.d.ts +2 -2
  75. package/executor/ViewFunctionExecutor.d.ts +2 -2
  76. package/executor/ViewFunctionExecutor.js +22 -3
  77. package/executor/v2/RuntimeApiExecutorV2.d.ts +2 -3
  78. package/executor/v2/StorageQueryExecutorV2.d.ts +3 -3
  79. package/executor/v2/StorageQueryExecutorV2.js +8 -2
  80. package/executor/v2/TxExecutorV2.d.ts +5 -5
  81. package/executor/v2/ViewFunctionExecutorV2.d.ts +2 -3
  82. package/executor/validation-helpers.d.ts +36 -0
  83. package/executor/validation-helpers.js +174 -0
  84. package/extrinsic/extensions/SignedExtension.d.ts +1 -1
  85. package/extrinsic/submittable/BaseSubmittableExtrinsic.d.ts +7 -3
  86. package/extrinsic/submittable/BaseSubmittableExtrinsic.js +64 -3
  87. package/extrinsic/submittable/SubmittableExtrinsic.d.ts +4 -1
  88. package/extrinsic/submittable/SubmittableExtrinsic.js +39 -17
  89. package/extrinsic/submittable/SubmittableExtrinsicV2.d.ts +6 -3
  90. package/extrinsic/submittable/SubmittableExtrinsicV2.js +13 -3
  91. package/json-rpc/JsonRpcClient.d.ts +6 -6
  92. package/json-rpc/group/Archive.d.ts +1 -1
  93. package/json-rpc/group/ChainHead/ChainHead.d.ts +18 -2
  94. package/json-rpc/group/ChainHead/ChainHead.js +226 -21
  95. package/json-rpc/group/ChainSpec.d.ts +3 -3
  96. package/json-rpc/group/Transaction.d.ts +1 -1
  97. package/json-rpc/group/TransactionWatch.d.ts +1 -1
  98. package/package.json +9 -9
  99. package/proxychain.d.ts +3 -4
  100. package/storage/NewStorageQuery.d.ts +3 -3
  101. package/storage/QueryableStorage.js +1 -0
  102. package/types.d.ts +94 -6
@@ -1 +1,2 @@
1
+ // Generated by dedot cli
1
2
  export {};
@@ -1 +1,2 @@
1
+ // Generated by dedot cli
1
2
  export {};
@@ -1,3 +1,3 @@
1
- import type { GenericChainViewFunctions, RpcVersion } from '@dedot/types';
2
- export interface ChainViewFunctions<Rv extends RpcVersion> extends GenericChainViewFunctions<Rv> {
1
+ import type { GenericChainViewFunctions } from '@dedot/types';
2
+ export interface ChainViewFunctions extends GenericChainViewFunctions {
3
3
  }
@@ -1 +1,2 @@
1
+ // Generated by dedot cli
1
2
  export {};
@@ -1,2 +1,3 @@
1
1
  "use strict";
2
+ // Generated by dedot cli
2
3
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,2 +1,3 @@
1
1
  "use strict";
2
+ // Generated by dedot cli
2
3
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,2 +1,3 @@
1
1
  "use strict";
2
+ // Generated by dedot cli
2
3
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,4 +1,5 @@
1
1
  "use strict";
2
+ // Generated by dedot cli
2
3
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
4
  if (k2 === undefined) k2 = k;
4
5
  var desc = Object.getOwnPropertyDescriptor(m, k);
@@ -1,2 +1,3 @@
1
1
  "use strict";
2
+ // Generated by dedot cli
2
3
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,2 +1,3 @@
1
1
  "use strict";
2
+ // Generated by dedot cli
2
3
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,2 +1,3 @@
1
1
  "use strict";
2
+ // Generated by dedot cli
2
3
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,2 +1,3 @@
1
1
  "use strict";
2
+ // Generated by dedot cli
2
3
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,2 +1,3 @@
1
1
  "use strict";
2
+ // Generated by dedot cli
2
3
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,2 +1,3 @@
1
1
  "use strict";
2
+ // Generated by dedot cli
2
3
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.BaseSubstrateClient = exports.ensurePresence = void 0;
4
4
  const codecs_1 = require("@dedot/codecs");
5
+ const providers_1 = require("@dedot/providers");
5
6
  const storage_1 = require("@dedot/storage");
6
7
  const utils_1 = require("@dedot/utils");
7
8
  const index_js_1 = require("../executor/index.js");
@@ -31,6 +32,7 @@ class BaseSubstrateClient extends index_js_2.JsonRpcClient {
31
32
  _localCache;
32
33
  _runtimeUpgrading;
33
34
  _apiAtCache;
35
+ #stalingWatchdogTimer;
34
36
  constructor(rpcVersion, options) {
35
37
  super(options);
36
38
  this.rpcVersion = rpcVersion;
@@ -98,7 +100,7 @@ class BaseSubstrateClient extends index_js_2.JsonRpcClient {
98
100
  if (!metadata) {
99
101
  throw new Error('Cannot load metadata');
100
102
  }
101
- this.setMetadata(metadata);
103
+ await this.setMetadata(metadata);
102
104
  }
103
105
  /**
104
106
  * Safely set metadata to cache with fallback cleanup if storage limit is exceeded
@@ -130,7 +132,7 @@ class BaseSubstrateClient extends index_js_2.JsonRpcClient {
130
132
  }
131
133
  }
132
134
  }
133
- setMetadata(metadata) {
135
+ async setMetadata(metadata) {
134
136
  this._metadata = metadata;
135
137
  this._registry = new codecs_1.PortableRegistry(metadata.latest, this.options.hasher);
136
138
  }
@@ -203,6 +205,34 @@ class BaseSubstrateClient extends index_js_2.JsonRpcClient {
203
205
  return await this.rpc.state_getMetadata();
204
206
  }
205
207
  }
208
+ /**
209
+ * Set up staling detection with timeout reset logic.
210
+ * Returns a callback function that should be called on each activity (block/event).
211
+ *
212
+ * @returns A function to call on each activity to reset the timeout
213
+ */
214
+ getStalingDetectionFn() {
215
+ const timeout = this._options.stalingDetectionTimeout ?? 30_000; // default to 30 seconds
216
+ if (timeout === 0 || !(this.provider instanceof providers_1.WsProvider)) {
217
+ return;
218
+ }
219
+ return () => {
220
+ this.cleanupStalingDetection();
221
+ this.#stalingWatchdogTimer = setTimeout(() => {
222
+ console.warn(`No new blocks received for over ${timeout}ms, triggering reconnection with endpoint switch...`);
223
+ this.provider.disconnect(true).catch(utils_1.noop);
224
+ }, timeout);
225
+ };
226
+ }
227
+ /**
228
+ * Clean up staling detection timer
229
+ */
230
+ cleanupStalingDetection() {
231
+ if (this.#stalingWatchdogTimer) {
232
+ clearTimeout(this.#stalingWatchdogTimer);
233
+ this.#stalingWatchdogTimer = undefined;
234
+ }
235
+ }
206
236
  cleanUp() {
207
237
  this._registry = undefined;
208
238
  this._metadata = undefined;
@@ -210,6 +240,7 @@ class BaseSubstrateClient extends index_js_2.JsonRpcClient {
210
240
  this._runtimeVersion = undefined;
211
241
  this._localCache = undefined;
212
242
  this._apiAtCache.clear();
243
+ this.cleanupStalingDetection();
213
244
  }
214
245
  /**
215
246
  * @description Clear local cache and API at-block cache
@@ -310,6 +341,9 @@ class BaseSubstrateClient extends index_js_2.JsonRpcClient {
310
341
  await this.ensureRuntimeUpgraded();
311
342
  return this.runtimeVersion;
312
343
  }
344
+ get block() {
345
+ throw new Error('Unimplemented!');
346
+ }
313
347
  get consts() {
314
348
  return (0, proxychain_js_1.newProxyChain)({ executor: new index_js_1.ConstantExecutor(this) });
315
349
  }
@@ -373,5 +407,14 @@ class BaseSubstrateClient extends index_js_2.JsonRpcClient {
373
407
  getStorageQuery() {
374
408
  throw new Error('Unimplemented!');
375
409
  }
410
+ sendTx(tx, callback) {
411
+ throw new Error('Unimplemented!');
412
+ }
413
+ get chainSpec() {
414
+ throw new Error('Unimplemented!');
415
+ }
416
+ on(event, handler) {
417
+ return super.on(event, handler);
418
+ }
376
419
  }
377
420
  exports.BaseSubstrateClient = BaseSubstrateClient;