@dedot/api 0.8.2-next.6cfafabd.24 → 0.9.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.
@@ -318,24 +318,19 @@ class BaseSubstrateClient extends index_js_2.JsonRpcClient {
318
318
  // Decode the value
319
319
  return entry.decodeValue(rawValue);
320
320
  };
321
- // Create service directly when needed
322
- let service;
323
- if (this.rpcVersion === 'v2') {
324
- service = new index_js_3.NewStorageQuery(this);
325
- }
326
- else {
327
- service = new index_js_3.LegacyStorageQuery(this);
328
- }
329
321
  // If a callback is provided, set up a subscription
330
322
  if (callback) {
331
- return service.subscribe(keys, (results) => {
323
+ return this.getStorageQuery().subscribe(keys, (results) => {
332
324
  callback(queries.map((q, i) => decodeValue(q.fn, results[keys[i]])));
333
325
  });
334
326
  }
335
327
  else {
336
- const results = await service.query(keys);
328
+ const results = await this.getStorageQuery().query(keys);
337
329
  return queries.map((q, i) => decodeValue(q.fn, results[keys[i]]));
338
330
  }
339
331
  }
332
+ getStorageQuery() {
333
+ throw new Error('Unimplemented!');
334
+ }
340
335
  }
341
336
  exports.BaseSubstrateClient = BaseSubstrateClient;
@@ -7,6 +7,7 @@ const utils_1 = require("@dedot/utils");
7
7
  const index_js_1 = require("../executor/index.js");
8
8
  const index_js_2 = require("../json-rpc/index.js");
9
9
  const proxychain_js_1 = require("../proxychain.js");
10
+ const index_js_3 = require("../storage/index.js");
10
11
  const BaseSubstrateClient_js_1 = require("./BaseSubstrateClient.js");
11
12
  /**
12
13
  * @name DedotClient
@@ -183,5 +184,8 @@ class DedotClient// prettier-end-here
183
184
  this.#apiAtCache[hash] = api;
184
185
  return api;
185
186
  }
187
+ getStorageQuery() {
188
+ return new index_js_3.NewStorageQuery(this);
189
+ }
186
190
  }
187
191
  exports.DedotClient = DedotClient;
@@ -4,6 +4,7 @@ exports.LegacyClient = void 0;
4
4
  const codecs_1 = require("@dedot/codecs");
5
5
  const index_js_1 = require("../executor/index.js");
6
6
  const proxychain_js_1 = require("../proxychain.js");
7
+ const index_js_2 = require("../storage/index.js");
7
8
  const BaseSubstrateClient_js_1 = require("./BaseSubstrateClient.js");
8
9
  const KEEP_ALIVE_INTERVAL = 10_000; // in ms
9
10
  /**
@@ -250,5 +251,8 @@ class LegacyClient// prettier-end-here
250
251
  this.#apiAtCache[hash] = api;
251
252
  return api;
252
253
  }
254
+ getStorageQuery() {
255
+ return new index_js_2.LegacyStorageQuery(this);
256
+ }
253
257
  }
254
258
  exports.LegacyClient = LegacyClient;
@@ -23,14 +23,15 @@ class LegacyStorageQuery extends BaseStorageQuery_js_1.BaseStorageQuery {
23
23
  * @returns Promise resolving to a record mapping storage keys to their values
24
24
  */
25
25
  async query(keys, at) {
26
+ const client = this.client;
26
27
  // Query storage at the specified block or current block
27
28
  const changeSets = at
28
- ? await this.client.rpc.state_queryStorageAt(keys, at)
29
- : await this.client.rpc.state_queryStorageAt(keys);
29
+ ? await client.rpc.state_queryStorageAt(keys, at)
30
+ : await client.rpc.state_queryStorageAt(keys);
30
31
  // Create a map of key -> value for easy lookup
31
32
  const results = {};
32
33
  // Initialize all keys with undefined
33
- keys.forEach(key => results[key] = undefined);
34
+ keys.forEach((key) => (results[key] = undefined));
34
35
  // Update with actual values from the response
35
36
  if (changeSets && changeSets.length > 0) {
36
37
  changeSets[0].changes.forEach(([key, value]) => {
@@ -50,9 +51,10 @@ class LegacyStorageQuery extends BaseStorageQuery_js_1.BaseStorageQuery {
50
51
  // Track the latest changes for each key
51
52
  const lastChanges = {};
52
53
  // Initialize all keys with undefined
53
- keys.forEach(key => lastChanges[key] = undefined);
54
+ keys.forEach((key) => (lastChanges[key] = undefined));
54
55
  // Subscribe to storage changes
55
- return this.client.rpc.state_subscribeStorage(keys, (changeSet) => {
56
+ const client = this.client;
57
+ return client.rpc.state_subscribeStorage(keys, (changeSet) => {
56
58
  // Update the latest changes
57
59
  changeSet.changes.forEach(([key, value]) => {
58
60
  if (lastChanges[key] !== value) {
@@ -5,6 +5,7 @@ import { Callback, GenericStorageQuery, GenericSubstrateApi, InjectedSigner, Que
5
5
  import { Deferred } from '@dedot/utils';
6
6
  import type { SubstrateApi } from '../chaintypes/index.js';
7
7
  import { JsonRpcClient } from '../json-rpc/index.js';
8
+ import { BaseStorageQuery } from '../storage/index.js';
8
9
  import type { ApiEvent, ApiOptions, ISubstrateClient, ISubstrateClientAt, JsonRpcClientOptions, MetadataKey, SubstrateRuntimeVersion } from '../types.js';
9
10
  export declare function ensurePresence<T>(value: T): NonNullable<T>;
10
11
  /**
@@ -104,4 +105,5 @@ export declare abstract class BaseSubstrateClient<Rv extends RpcVersion, ChainAp
104
105
  }, callback: Callback<{
105
106
  [K in keyof Fns]: QueryFnResult<Fns[K]>;
106
107
  }>): Promise<Unsub>;
108
+ protected getStorageQuery(): BaseStorageQuery<RpcVersion>;
107
109
  }
@@ -4,7 +4,7 @@ import { calcRuntimeApiHash, deferred, ensurePresence as _ensurePresence, u8aToH
4
4
  import { ConstantExecutor, ErrorExecutor, EventExecutor } from '../executor/index.js';
5
5
  import { isJsonRpcProvider, JsonRpcClient } from '../json-rpc/index.js';
6
6
  import { newProxyChain } from '../proxychain.js';
7
- import { LegacyStorageQuery, NewStorageQuery, QueryableStorage } from '../storage/index.js';
7
+ import { QueryableStorage } from '../storage/index.js';
8
8
  const SUPPORTED_METADATA_VERSIONS = [15, 14];
9
9
  const MetadataApiHash = calcRuntimeApiHash('Metadata'); // 0x37e397fc7c91f5e4
10
10
  const MESSAGE = 'Make sure to call `.connect()` method first before using the API interfaces.';
@@ -314,23 +314,18 @@ export class BaseSubstrateClient extends JsonRpcClient {
314
314
  // Decode the value
315
315
  return entry.decodeValue(rawValue);
316
316
  };
317
- // Create service directly when needed
318
- let service;
319
- if (this.rpcVersion === 'v2') {
320
- service = new NewStorageQuery(this);
321
- }
322
- else {
323
- service = new LegacyStorageQuery(this);
324
- }
325
317
  // If a callback is provided, set up a subscription
326
318
  if (callback) {
327
- return service.subscribe(keys, (results) => {
319
+ return this.getStorageQuery().subscribe(keys, (results) => {
328
320
  callback(queries.map((q, i) => decodeValue(q.fn, results[keys[i]])));
329
321
  });
330
322
  }
331
323
  else {
332
- const results = await service.query(keys);
324
+ const results = await this.getStorageQuery().query(keys);
333
325
  return queries.map((q, i) => decodeValue(q.fn, results[keys[i]]));
334
326
  }
335
327
  }
328
+ getStorageQuery() {
329
+ throw new Error('Unimplemented!');
330
+ }
336
331
  }
@@ -1,8 +1,9 @@
1
1
  import { BlockHash } from '@dedot/codecs';
2
2
  import type { JsonRpcProvider } from '@dedot/providers';
3
- import { GenericSubstrateApi, RpcV2, VersionedGenericSubstrateApi } from '@dedot/types';
3
+ import { GenericSubstrateApi, RpcV2, RpcVersion, VersionedGenericSubstrateApi } from '@dedot/types';
4
4
  import type { SubstrateApi } from '../chaintypes/index.js';
5
5
  import { ChainHead, ChainSpec, PinnedBlock } from '../json-rpc/index.js';
6
+ import { BaseStorageQuery } from '../storage/index.js';
6
7
  import type { ApiOptions, ISubstrateClientAt, TxBroadcaster } from '../types.js';
7
8
  import { BaseSubstrateClient } from './BaseSubstrateClient.js';
8
9
  /**
@@ -58,4 +59,5 @@ export declare class DedotClient<ChainApi extends VersionedGenericSubstrateApi =
58
59
  * @param hash
59
60
  */
60
61
  at<ChainApiAt extends GenericSubstrateApi = ChainApi[RpcV2]>(hash: BlockHash): Promise<ISubstrateClientAt<ChainApiAt>>;
62
+ protected getStorageQuery(): BaseStorageQuery<RpcVersion>;
61
63
  }
@@ -1,9 +1,10 @@
1
1
  import { $H256, PortableRegistry } from '@dedot/codecs';
2
2
  import { u32 } from '@dedot/shape';
3
3
  import { assert, concatU8a, noop, twox64Concat, u8aToHex, xxhashAsU8a } from '@dedot/utils';
4
- import { ConstantExecutor, ErrorExecutor, EventExecutor, RuntimeApiExecutorV2, StorageQueryExecutorV2, TxExecutorV2 } from '../executor/index.js';
4
+ import { ConstantExecutor, ErrorExecutor, EventExecutor, RuntimeApiExecutorV2, StorageQueryExecutorV2, TxExecutorV2, } from '../executor/index.js';
5
5
  import { ChainHead, ChainSpec, Transaction, TransactionWatch } from '../json-rpc/index.js';
6
6
  import { newProxyChain } from '../proxychain.js';
7
+ import { NewStorageQuery } from '../storage/index.js';
7
8
  import { BaseSubstrateClient, ensurePresence } from './BaseSubstrateClient.js';
8
9
  /**
9
10
  * @name DedotClient
@@ -180,4 +181,7 @@ export class DedotClient// prettier-end-here
180
181
  this.#apiAtCache[hash] = api;
181
182
  return api;
182
183
  }
184
+ getStorageQuery() {
185
+ return new NewStorageQuery(this);
186
+ }
183
187
  }
@@ -1,7 +1,8 @@
1
1
  import { BlockHash } from '@dedot/codecs';
2
2
  import type { JsonRpcProvider } from '@dedot/providers';
3
- import { GenericSubstrateApi, RpcLegacy, VersionedGenericSubstrateApi } from '@dedot/types';
3
+ import { GenericSubstrateApi, RpcLegacy, RpcVersion, VersionedGenericSubstrateApi } from '@dedot/types';
4
4
  import type { SubstrateApi } from '../chaintypes/index.js';
5
+ import { BaseStorageQuery } from '../storage/index.js';
5
6
  import type { ApiOptions, ISubstrateClientAt } from '../types.js';
6
7
  import { BaseSubstrateClient } from './BaseSubstrateClient.js';
7
8
  /**
@@ -129,4 +130,5 @@ export declare class LegacyClient<ChainApi extends VersionedGenericSubstrateApi
129
130
  * @param hash
130
131
  */
131
132
  at<ChainApiAt extends GenericSubstrateApi = ChainApi[RpcLegacy]>(hash: BlockHash): Promise<ISubstrateClientAt<ChainApiAt>>;
133
+ protected getStorageQuery(): BaseStorageQuery<RpcVersion>;
132
134
  }
@@ -1,6 +1,7 @@
1
1
  import { PortableRegistry } from '@dedot/codecs';
2
2
  import { ConstantExecutor, ErrorExecutor, EventExecutor, RuntimeApiExecutor, StorageQueryExecutor, TxExecutor, } from '../executor/index.js';
3
3
  import { newProxyChain } from '../proxychain.js';
4
+ import { LegacyStorageQuery } from '../storage/index.js';
4
5
  import { BaseSubstrateClient } from './BaseSubstrateClient.js';
5
6
  const KEEP_ALIVE_INTERVAL = 10_000; // in ms
6
7
  /**
@@ -247,4 +248,7 @@ export class LegacyClient// prettier-end-here
247
248
  this.#apiAtCache[hash] = api;
248
249
  return api;
249
250
  }
251
+ getStorageQuery() {
252
+ return new LegacyStorageQuery(this);
253
+ }
250
254
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dedot/api",
3
- "version": "0.8.2-next.6cfafabd.24+6cfafab",
3
+ "version": "0.9.0",
4
4
  "description": "A delightful JavaScript/TypeScript client for Polkadot & Substrate",
5
5
  "author": "Thang X. Vu <thang@coongcrafts.io>",
6
6
  "homepage": "https://github.com/dedotdev/dedot/tree/main/packages/api",
@@ -13,13 +13,13 @@
13
13
  "type": "module",
14
14
  "sideEffects": false,
15
15
  "dependencies": {
16
- "@dedot/codecs": "0.8.2-next.6cfafabd.24+6cfafab",
17
- "@dedot/providers": "0.8.2-next.6cfafabd.24+6cfafab",
18
- "@dedot/runtime-specs": "0.8.2-next.6cfafabd.24+6cfafab",
19
- "@dedot/shape": "0.8.2-next.6cfafabd.24+6cfafab",
20
- "@dedot/storage": "0.8.2-next.6cfafabd.24+6cfafab",
21
- "@dedot/types": "0.8.2-next.6cfafabd.24+6cfafab",
22
- "@dedot/utils": "0.8.2-next.6cfafabd.24+6cfafab"
16
+ "@dedot/codecs": "0.9.0",
17
+ "@dedot/providers": "0.9.0",
18
+ "@dedot/runtime-specs": "0.9.0",
19
+ "@dedot/shape": "0.9.0",
20
+ "@dedot/storage": "0.9.0",
21
+ "@dedot/types": "0.9.0",
22
+ "@dedot/utils": "0.9.0"
23
23
  },
24
24
  "scripts": {
25
25
  "build": "tsc --project tsconfig.build.json && tsc --project tsconfig.build.cjs.json",
@@ -48,7 +48,7 @@
48
48
  "node": ">=18"
49
49
  },
50
50
  "license": "Apache-2.0",
51
- "gitHead": "6cfafabd52dbc7e5bd3ded135e9617fc412bba2b",
51
+ "gitHead": "cebae55a3525e2c9bcdd70322027855a594a287d",
52
52
  "module": "./index.js",
53
53
  "types": "./index.d.ts"
54
54
  }
@@ -20,14 +20,15 @@ export class LegacyStorageQuery extends BaseStorageQuery {
20
20
  * @returns Promise resolving to a record mapping storage keys to their values
21
21
  */
22
22
  async query(keys, at) {
23
+ const client = this.client;
23
24
  // Query storage at the specified block or current block
24
25
  const changeSets = at
25
- ? await this.client.rpc.state_queryStorageAt(keys, at)
26
- : await this.client.rpc.state_queryStorageAt(keys);
26
+ ? await client.rpc.state_queryStorageAt(keys, at)
27
+ : await client.rpc.state_queryStorageAt(keys);
27
28
  // Create a map of key -> value for easy lookup
28
29
  const results = {};
29
30
  // Initialize all keys with undefined
30
- keys.forEach(key => results[key] = undefined);
31
+ keys.forEach((key) => (results[key] = undefined));
31
32
  // Update with actual values from the response
32
33
  if (changeSets && changeSets.length > 0) {
33
34
  changeSets[0].changes.forEach(([key, value]) => {
@@ -47,9 +48,10 @@ export class LegacyStorageQuery extends BaseStorageQuery {
47
48
  // Track the latest changes for each key
48
49
  const lastChanges = {};
49
50
  // Initialize all keys with undefined
50
- keys.forEach(key => lastChanges[key] = undefined);
51
+ keys.forEach((key) => (lastChanges[key] = undefined));
51
52
  // Subscribe to storage changes
52
- return this.client.rpc.state_subscribeStorage(keys, (changeSet) => {
53
+ const client = this.client;
54
+ return client.rpc.state_subscribeStorage(keys, (changeSet) => {
53
55
  // Update the latest changes
54
56
  changeSet.changes.forEach(([key, value]) => {
55
57
  if (lastChanges[key] !== value) {