@dedot/api 0.17.0 → 0.17.1-next.9d03d21b.3
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.
- package/cjs/client/BaseSubstrateClient.js +11 -2
- package/cjs/client/DedotClient.js +4 -0
- package/cjs/client/LegacyClient.js +4 -0
- package/client/BaseSubstrateClient.d.ts +4 -0
- package/client/BaseSubstrateClient.js +11 -2
- package/client/DedotClient.js +6 -2
- package/client/LegacyClient.js +4 -0
- package/package.json +9 -9
- package/types.d.ts +46 -4
|
@@ -325,7 +325,7 @@ class BaseSubstrateClient extends index_js_2.JsonRpcClient {
|
|
|
325
325
|
setSigner(signer) {
|
|
326
326
|
this._options.signer = signer;
|
|
327
327
|
}
|
|
328
|
-
async
|
|
328
|
+
async internalQueryMulti(queries, callback, blockHash) {
|
|
329
329
|
// Extract keys from queries
|
|
330
330
|
const keys = queries.map((q) => q.fn.rawKey(...(q.args || [])));
|
|
331
331
|
const decodeValue = (query, rawValue) => {
|
|
@@ -341,10 +341,19 @@ class BaseSubstrateClient extends index_js_2.JsonRpcClient {
|
|
|
341
341
|
});
|
|
342
342
|
}
|
|
343
343
|
else {
|
|
344
|
-
const results = await this.getStorageQuery().query(keys);
|
|
344
|
+
const results = await this.getStorageQuery().query(keys, blockHash);
|
|
345
345
|
return queries.map((q, i) => decodeValue(q.fn, results[keys[i]]));
|
|
346
346
|
}
|
|
347
347
|
}
|
|
348
|
+
async queryMulti(queries, callback) {
|
|
349
|
+
// If a callback is provided, set up a subscription
|
|
350
|
+
if (callback) {
|
|
351
|
+
return this.internalQueryMulti(queries, callback);
|
|
352
|
+
}
|
|
353
|
+
else {
|
|
354
|
+
return this.internalQueryMulti(queries);
|
|
355
|
+
}
|
|
356
|
+
}
|
|
348
357
|
getStorageQuery() {
|
|
349
358
|
throw new Error('Unimplemented!');
|
|
350
359
|
}
|
|
@@ -235,6 +235,10 @@ class DedotClient// prettier-end-here
|
|
|
235
235
|
api.query = (0, proxychain_js_1.newProxyChain)({ executor: new index_js_1.StorageQueryExecutorV2(api, this.chainHead) });
|
|
236
236
|
api.call = (0, proxychain_js_1.newProxyChain)({ executor: new index_js_1.RuntimeApiExecutorV2(api, this.chainHead) });
|
|
237
237
|
api.view = (0, proxychain_js_1.newProxyChain)({ executor: new index_js_1.ViewFunctionExecutorV2(api, this.chainHead) });
|
|
238
|
+
// @ts-ignore Add queryMulti implementation for at-block queries
|
|
239
|
+
api.queryMulti = (queries) => {
|
|
240
|
+
return this.internalQueryMulti(queries, undefined, hash);
|
|
241
|
+
};
|
|
238
242
|
this._apiAtCache.set(hash, api);
|
|
239
243
|
return api;
|
|
240
244
|
}
|
|
@@ -255,6 +255,10 @@ class LegacyClient// prettier-end-here
|
|
|
255
255
|
api.call = (0, proxychain_js_1.newProxyChain)({ executor: new index_js_1.RuntimeApiExecutor(api) });
|
|
256
256
|
api.events = (0, proxychain_js_1.newProxyChain)({ executor: new index_js_1.EventExecutor(api) });
|
|
257
257
|
api.errors = (0, proxychain_js_1.newProxyChain)({ executor: new index_js_1.ErrorExecutor(api) });
|
|
258
|
+
// @ts-ignore Add queryMulti implementation for at-block queries
|
|
259
|
+
api.queryMulti = (queries) => {
|
|
260
|
+
return this.internalQueryMulti(queries, undefined, hash);
|
|
261
|
+
};
|
|
258
262
|
this._apiAtCache.set(hash, api);
|
|
259
263
|
return api;
|
|
260
264
|
}
|
|
@@ -77,6 +77,10 @@ export declare abstract class BaseSubstrateClient<Rv extends RpcVersion, ChainAp
|
|
|
77
77
|
get tx(): ChainApi[Rv]['tx'];
|
|
78
78
|
at<ChainApiAt extends GenericSubstrateApi = ChainApi[Rv]>(hash: BlockHash): Promise<ISubstrateClientAt<ChainApiAt>>;
|
|
79
79
|
setSigner(signer?: InjectedSigner): void;
|
|
80
|
+
protected internalQueryMulti(queries: {
|
|
81
|
+
fn: GenericStorageQuery;
|
|
82
|
+
args?: any[];
|
|
83
|
+
}[], callback?: Callback<any[]>, blockHash?: BlockHash): Promise<any[] | Unsub>;
|
|
80
84
|
/**
|
|
81
85
|
* Query multiple storage items in a single call
|
|
82
86
|
*
|
|
@@ -321,7 +321,7 @@ export class BaseSubstrateClient extends JsonRpcClient {
|
|
|
321
321
|
setSigner(signer) {
|
|
322
322
|
this._options.signer = signer;
|
|
323
323
|
}
|
|
324
|
-
async
|
|
324
|
+
async internalQueryMulti(queries, callback, blockHash) {
|
|
325
325
|
// Extract keys from queries
|
|
326
326
|
const keys = queries.map((q) => q.fn.rawKey(...(q.args || [])));
|
|
327
327
|
const decodeValue = (query, rawValue) => {
|
|
@@ -337,10 +337,19 @@ export class BaseSubstrateClient extends JsonRpcClient {
|
|
|
337
337
|
});
|
|
338
338
|
}
|
|
339
339
|
else {
|
|
340
|
-
const results = await this.getStorageQuery().query(keys);
|
|
340
|
+
const results = await this.getStorageQuery().query(keys, blockHash);
|
|
341
341
|
return queries.map((q, i) => decodeValue(q.fn, results[keys[i]]));
|
|
342
342
|
}
|
|
343
343
|
}
|
|
344
|
+
async queryMulti(queries, callback) {
|
|
345
|
+
// If a callback is provided, set up a subscription
|
|
346
|
+
if (callback) {
|
|
347
|
+
return this.internalQueryMulti(queries, callback);
|
|
348
|
+
}
|
|
349
|
+
else {
|
|
350
|
+
return this.internalQueryMulti(queries);
|
|
351
|
+
}
|
|
352
|
+
}
|
|
344
353
|
getStorageQuery() {
|
|
345
354
|
throw new Error('Unimplemented!');
|
|
346
355
|
}
|
package/client/DedotClient.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { $H256, $RuntimeVersion, PortableRegistry } from '@dedot/codecs';
|
|
2
2
|
import { u32 } from '@dedot/shape';
|
|
3
|
-
import { assert, concatU8a, noop, twox64Concat, u8aToHex, xxhashAsU8a
|
|
4
|
-
import { ConstantExecutor, ErrorExecutor, EventExecutor, RuntimeApiExecutorV2, StorageQueryExecutorV2,
|
|
3
|
+
import { assert, concatU8a, DedotError, noop, twox64Concat, u8aToHex, xxhashAsU8a } from '@dedot/utils';
|
|
4
|
+
import { ConstantExecutor, ErrorExecutor, EventExecutor, RuntimeApiExecutorV2, StorageQueryExecutorV2, TxExecutorV2, ViewFunctionExecutorV2, } from '../executor/index.js';
|
|
5
5
|
import { Archive, ChainHead, ChainSpec, Transaction, TransactionWatch } from '../json-rpc/index.js';
|
|
6
6
|
import { newProxyChain } from '../proxychain.js';
|
|
7
7
|
import { NewStorageQuery } from '../storage/index.js';
|
|
@@ -232,6 +232,10 @@ export class DedotClient// prettier-end-here
|
|
|
232
232
|
api.query = newProxyChain({ executor: new StorageQueryExecutorV2(api, this.chainHead) });
|
|
233
233
|
api.call = newProxyChain({ executor: new RuntimeApiExecutorV2(api, this.chainHead) });
|
|
234
234
|
api.view = newProxyChain({ executor: new ViewFunctionExecutorV2(api, this.chainHead) });
|
|
235
|
+
// @ts-ignore Add queryMulti implementation for at-block queries
|
|
236
|
+
api.queryMulti = (queries) => {
|
|
237
|
+
return this.internalQueryMulti(queries, undefined, hash);
|
|
238
|
+
};
|
|
235
239
|
this._apiAtCache.set(hash, api);
|
|
236
240
|
return api;
|
|
237
241
|
}
|
package/client/LegacyClient.js
CHANGED
|
@@ -252,6 +252,10 @@ export class LegacyClient// prettier-end-here
|
|
|
252
252
|
api.call = newProxyChain({ executor: new RuntimeApiExecutor(api) });
|
|
253
253
|
api.events = newProxyChain({ executor: new EventExecutor(api) });
|
|
254
254
|
api.errors = newProxyChain({ executor: new ErrorExecutor(api) });
|
|
255
|
+
// @ts-ignore Add queryMulti implementation for at-block queries
|
|
256
|
+
api.queryMulti = (queries) => {
|
|
257
|
+
return this.internalQueryMulti(queries, undefined, hash);
|
|
258
|
+
};
|
|
255
259
|
this._apiAtCache.set(hash, api);
|
|
256
260
|
return api;
|
|
257
261
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dedot/api",
|
|
3
|
-
"version": "0.17.
|
|
3
|
+
"version": "0.17.1-next.9d03d21b.3+9d03d21b",
|
|
4
4
|
"description": "A delightful JavaScript/TypeScript client for Polkadot & Substrate",
|
|
5
5
|
"author": "Thang X. Vu <thang@dedot.dev>",
|
|
6
6
|
"homepage": "https://dedot.dev",
|
|
@@ -13,13 +13,13 @@
|
|
|
13
13
|
"type": "module",
|
|
14
14
|
"sideEffects": false,
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@dedot/codecs": "0.17.
|
|
17
|
-
"@dedot/providers": "0.17.
|
|
18
|
-
"@dedot/runtime-specs": "0.17.
|
|
19
|
-
"@dedot/shape": "0.17.
|
|
20
|
-
"@dedot/storage": "0.17.
|
|
21
|
-
"@dedot/types": "0.17.
|
|
22
|
-
"@dedot/utils": "0.17.
|
|
16
|
+
"@dedot/codecs": "0.17.1-next.9d03d21b.3+9d03d21b",
|
|
17
|
+
"@dedot/providers": "0.17.1-next.9d03d21b.3+9d03d21b",
|
|
18
|
+
"@dedot/runtime-specs": "0.17.1-next.9d03d21b.3+9d03d21b",
|
|
19
|
+
"@dedot/shape": "0.17.1-next.9d03d21b.3+9d03d21b",
|
|
20
|
+
"@dedot/storage": "0.17.1-next.9d03d21b.3+9d03d21b",
|
|
21
|
+
"@dedot/types": "0.17.1-next.9d03d21b.3+9d03d21b",
|
|
22
|
+
"@dedot/utils": "0.17.1-next.9d03d21b.3+9d03d21b"
|
|
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": "
|
|
51
|
+
"gitHead": "9d03d21b0b652b14222301b64682940047514172",
|
|
52
52
|
"module": "./index.js",
|
|
53
53
|
"types": "./index.d.ts"
|
|
54
54
|
}
|
package/types.d.ts
CHANGED
|
@@ -99,6 +99,28 @@ export interface IGenericSubstrateClient<ChainApi extends GenericSubstrateApi =
|
|
|
99
99
|
events: ChainApi['events'];
|
|
100
100
|
errors: ChainApi['errors'];
|
|
101
101
|
view: ChainApi['view'];
|
|
102
|
+
/**
|
|
103
|
+
* Query multiple storage items in a single call
|
|
104
|
+
*
|
|
105
|
+
* This method allows you to query multiple storage items in a single call with type safety
|
|
106
|
+
* for both the query functions and their results.
|
|
107
|
+
*
|
|
108
|
+
* @example
|
|
109
|
+
* // One-time query with type-safe results
|
|
110
|
+
* const [balance, blockNumber] = await client.queryMulti([
|
|
111
|
+
* { fn: client.query.system.account, args: [ALICE] },
|
|
112
|
+
* { fn: client.query.system.number, args: [] }
|
|
113
|
+
* ]);
|
|
114
|
+
*
|
|
115
|
+
* @template Fns Array of storage query functions
|
|
116
|
+
* @param queries - Array of query specifications, each with a function and optional arguments
|
|
117
|
+
* @returns Array of decoded values with proper types
|
|
118
|
+
*/
|
|
119
|
+
queryMulti<Fns extends GenericStorageQuery[]>(queries: {
|
|
120
|
+
[K in keyof Fns]: Query<Fns[K]>;
|
|
121
|
+
}): Promise<{
|
|
122
|
+
[K in keyof Fns]: QueryFnResult<Fns[K]>;
|
|
123
|
+
}>;
|
|
102
124
|
}
|
|
103
125
|
/**
|
|
104
126
|
* A generic interface for Substrate clients at a specific block
|
|
@@ -128,10 +150,30 @@ export interface ISubstrateClient<ChainApi extends GenericSubstrateApi = Generic
|
|
|
128
150
|
*/
|
|
129
151
|
setSigner(signer?: InjectedSigner): void;
|
|
130
152
|
/**
|
|
131
|
-
*
|
|
132
|
-
*
|
|
133
|
-
*
|
|
134
|
-
*
|
|
153
|
+
* Query multiple storage items in a single call or subscribe to multiple storage items
|
|
154
|
+
*
|
|
155
|
+
* This method allows you to query multiple storage items in a single call or set up a subscription
|
|
156
|
+
* to multiple storage items. It provides type safety for both the query functions and their results.
|
|
157
|
+
*
|
|
158
|
+
* @example
|
|
159
|
+
* // One-time query with type-safe results
|
|
160
|
+
* const [balance, blockNumber] = await client.queryMulti([
|
|
161
|
+
* { fn: client.query.system.account, args: [ALICE] },
|
|
162
|
+
* { fn: client.query.system.number, args: [] }
|
|
163
|
+
* ]);
|
|
164
|
+
*
|
|
165
|
+
* // Subscription with callback
|
|
166
|
+
* const unsub = await client.queryMulti([
|
|
167
|
+
* { fn: client.query.system.account, args: [ALICE] },
|
|
168
|
+
* { fn: client.query.system.number, args: [] }
|
|
169
|
+
* ], (results) => {
|
|
170
|
+
* console.log('Balance:', results[0], 'Block number:', results[1]);
|
|
171
|
+
* });
|
|
172
|
+
*
|
|
173
|
+
* @template Fns Array of storage query functions
|
|
174
|
+
* @param queries - Array of query specifications, each with a function and optional arguments
|
|
175
|
+
* @param callback - Optional callback for subscription-based queries
|
|
176
|
+
* @returns For one-time queries: Array of decoded values with proper types; For subscriptions: Unsubscribe function
|
|
135
177
|
*/
|
|
136
178
|
queryMulti<Fns extends GenericStorageQuery[]>(queries: {
|
|
137
179
|
[K in keyof Fns]: Query<Fns[K]>;
|