@dedot/api 0.0.1-alpha.35 → 0.0.1-alpha.37

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.
@@ -40,20 +40,20 @@ class StorageQueryExecutorV2 extends StorageQueryExecutor_js_1.StorageQueryExecu
40
40
  // TODO subscribe to finalized data source
41
41
  // initialHash = this.chainHead.finalizedHash;
42
42
  // eventToListen = 'finalizedBlock';
43
- const latestChanges = {};
43
+ const latestChanges = new Map();
44
44
  const pull = async ({ hash }) => {
45
45
  const results = await this.queryStorage(keys, hash);
46
46
  let changed = false;
47
47
  keys.forEach((key) => {
48
48
  const newValue = results[key];
49
- if (latestChanges[key] === newValue)
49
+ if (latestChanges.size > 0 && latestChanges.get(key) === newValue)
50
50
  return;
51
51
  changed = true;
52
- latestChanges[key] = newValue;
52
+ latestChanges.set(key, newValue);
53
53
  });
54
54
  if (!changed)
55
55
  return;
56
- callback(keys.map((key) => latestChanges[key]));
56
+ callback(keys.map((key) => latestChanges.get(key)));
57
57
  };
58
58
  await pull(best);
59
59
  const unsub = this.chainHead.on(eventToListen, pull);
@@ -1,7 +1,8 @@
1
1
  import { BlockHash, Hash, Metadata, PortableRegistry, RuntimeVersion } from '@dedot/codecs';
2
2
  import type { JsonRpcProvider } from '@dedot/providers';
3
3
  import { type IStorage } from '@dedot/storage';
4
- import { GenericSubstrateApi, RpcVersion } from '@dedot/types';
4
+ import { GenericSubstrateApi, RpcVersion, VersionedGenericSubstrateApi } from '@dedot/types';
5
+ import type { SubstrateApi } from '../chaintypes/index.js';
5
6
  import { JsonRpcClient } from '../json-rpc/index.js';
6
7
  import type { ApiEvent, ApiOptions, ISubstrateClient, ISubstrateClientAt, JsonRpcClientOptions, MetadataKey, SubstrateRuntimeVersion } from '../types.js';
7
8
  export declare function ensurePresence<T>(value: T): NonNullable<T>;
@@ -9,7 +10,7 @@ export declare function ensurePresence<T>(value: T): NonNullable<T>;
9
10
  * @name BaseSubstrateClient
10
11
  * @description Base & shared abstraction for Substrate API Clients
11
12
  */
12
- export declare abstract class BaseSubstrateClient<ChainApi extends GenericSubstrateApi = GenericSubstrateApi> extends JsonRpcClient<ChainApi, ApiEvent> implements ISubstrateClient<ChainApi> {
13
+ export declare abstract class BaseSubstrateClient<Rv extends RpcVersion, ChainApi extends VersionedGenericSubstrateApi = SubstrateApi> extends JsonRpcClient<ChainApi, ApiEvent> implements ISubstrateClient<ChainApi[Rv]> {
13
14
  rpcVersion: RpcVersion;
14
15
  protected _options: ApiOptions;
15
16
  protected _registry?: PortableRegistry;
@@ -53,12 +54,12 @@ export declare abstract class BaseSubstrateClient<ChainApi extends GenericSubstr
53
54
  get registry(): PortableRegistry;
54
55
  get genesisHash(): Hash;
55
56
  get runtimeVersion(): SubstrateRuntimeVersion;
56
- get consts(): ChainApi['consts'];
57
- get errors(): ChainApi['errors'];
58
- get events(): ChainApi['events'];
59
- get query(): ChainApi['query'];
60
- get call(): ChainApi['call'];
61
- protected callAt(hash?: BlockHash): ChainApi['call'];
62
- get tx(): ChainApi['tx'];
63
- at<ChainApiAt extends GenericSubstrateApi = ChainApi>(hash: BlockHash): Promise<ISubstrateClientAt<ChainApiAt>>;
57
+ get consts(): ChainApi[Rv]['consts'];
58
+ get errors(): ChainApi[Rv]['errors'];
59
+ get events(): ChainApi[Rv]['events'];
60
+ get query(): ChainApi[Rv]['query'];
61
+ get call(): ChainApi[Rv]['call'];
62
+ protected callAt(hash?: BlockHash): ChainApi[Rv]['call'];
63
+ get tx(): ChainApi[Rv]['tx'];
64
+ at<ChainApiAt extends GenericSubstrateApi = ChainApi[Rv]>(hash: BlockHash): Promise<ISubstrateClientAt<ChainApiAt>>;
64
65
  }
@@ -12,7 +12,7 @@ import { BaseSubstrateClient } from './BaseSubstrateClient.js';
12
12
  * __Unstable, use with caution.__
13
13
  */
14
14
  export declare class DedotClient<ChainApi extends VersionedGenericSubstrateApi = SubstrateApi>// prettier-end-here
15
- extends BaseSubstrateClient<ChainApi[RpcV2]> {
15
+ extends BaseSubstrateClient<RpcV2, ChainApi> {
16
16
  #private;
17
17
  protected _chainHead?: ChainHead;
18
18
  protected _chainSpec?: ChainSpec;
@@ -43,7 +43,7 @@ import { BaseSubstrateClient } from './BaseSubstrateClient.js';
43
43
  * ```
44
44
  */
45
45
  export declare class LegacyClient<ChainApi extends VersionedGenericSubstrateApi = SubstrateApi>// prettier-end-here
46
- extends BaseSubstrateClient<ChainApi[RpcLegacy]> {
46
+ extends BaseSubstrateClient<RpcLegacy, ChainApi> {
47
47
  #private;
48
48
  /**
49
49
  * Use factory methods (`create`, `new`) to create `Dedot` instances.
@@ -37,20 +37,20 @@ export class StorageQueryExecutorV2 extends StorageQueryExecutor {
37
37
  // TODO subscribe to finalized data source
38
38
  // initialHash = this.chainHead.finalizedHash;
39
39
  // eventToListen = 'finalizedBlock';
40
- const latestChanges = {};
40
+ const latestChanges = new Map();
41
41
  const pull = async ({ hash }) => {
42
42
  const results = await this.queryStorage(keys, hash);
43
43
  let changed = false;
44
44
  keys.forEach((key) => {
45
45
  const newValue = results[key];
46
- if (latestChanges[key] === newValue)
46
+ if (latestChanges.size > 0 && latestChanges.get(key) === newValue)
47
47
  return;
48
48
  changed = true;
49
- latestChanges[key] = newValue;
49
+ latestChanges.set(key, newValue);
50
50
  });
51
51
  if (!changed)
52
52
  return;
53
- callback(keys.map((key) => latestChanges[key]));
53
+ callback(keys.map((key) => latestChanges.get(key)));
54
54
  };
55
55
  await pull(best);
56
56
  const unsub = this.chainHead.on(eventToListen, pull);
@@ -1,10 +1,11 @@
1
1
  import type { ConnectionStatus, JsonRpcProvider, ProviderEvent } from '@dedot/providers';
2
- import type { GenericSubstrateApi, RpcVersion } from '@dedot/types';
2
+ import type { RpcVersion, VersionedGenericSubstrateApi } from '@dedot/types';
3
3
  import { EventEmitter } from '@dedot/utils';
4
4
  import type { SubstrateApi } from '../chaintypes/index.js';
5
5
  import type { IJsonRpcClient, JsonRpcClientOptions } from '../types.js';
6
6
  export declare const isJsonRpcProvider: (provider: any) => provider is JsonRpcProvider;
7
- export declare class JsonRpcClient<ChainApi extends GenericSubstrateApi = SubstrateApi[RpcVersion], Events extends string = ProviderEvent> extends EventEmitter<Events> implements IJsonRpcClient<ChainApi, Events> {
7
+ export declare class JsonRpcClient<ChainApi extends VersionedGenericSubstrateApi = SubstrateApi, // prettier-end-here
8
+ Events extends string = ProviderEvent> extends EventEmitter<Events> implements IJsonRpcClient<ChainApi[RpcVersion], Events> {
8
9
  #private;
9
10
  constructor(options: JsonRpcClientOptions | JsonRpcProvider);
10
11
  /**
@@ -12,13 +13,13 @@ export declare class JsonRpcClient<ChainApi extends GenericSubstrateApi = Substr
12
13
  *
13
14
  * @param options
14
15
  */
15
- static create<ChainApi extends GenericSubstrateApi = SubstrateApi[RpcVersion]>(options: JsonRpcClientOptions | JsonRpcProvider): Promise<JsonRpcClient<ChainApi>>;
16
+ static create<ChainApi extends VersionedGenericSubstrateApi = SubstrateApi>(options: JsonRpcClientOptions | JsonRpcProvider): Promise<JsonRpcClient<ChainApi>>;
16
17
  /**
17
18
  * Alias for __JsonRpcClient.create__
18
19
  *
19
20
  * @param options
20
21
  */
21
- static new<ChainApi extends GenericSubstrateApi = SubstrateApi[RpcVersion]>(options: JsonRpcClientOptions | JsonRpcProvider): Promise<JsonRpcClient<ChainApi>>;
22
+ static new<ChainApi extends VersionedGenericSubstrateApi = SubstrateApi>(options: JsonRpcClientOptions | JsonRpcProvider): Promise<JsonRpcClient<ChainApi>>;
22
23
  get options(): JsonRpcClientOptions;
23
24
  /**
24
25
  * @description Check connection status of the api instance
@@ -46,5 +47,5 @@ export declare class JsonRpcClient<ChainApi extends GenericSubstrateApi = Substr
46
47
  * const result = await client.rpc.module_rpc_name();
47
48
  * ```
48
49
  */
49
- get rpc(): ChainApi['rpc'];
50
+ get rpc(): ChainApi[RpcVersion]['rpc'];
50
51
  }
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@dedot/api",
3
- "version": "0.0.1-alpha.35",
3
+ "version": "0.0.1-alpha.37",
4
4
  "description": "A delightful JavaScript/TypeScript client for Polkadot & Substrate",
5
5
  "author": "Thang X. Vu <thang@coongcrafts.io>",
6
- "homepage": "https://github.com/dedotdev/dedot",
6
+ "homepage": "https://github.com/dedotdev/dedot/tree/main/packages/api",
7
7
  "repository": {
8
8
  "directory": "packages/api",
9
9
  "type": "git",
@@ -13,13 +13,13 @@
13
13
  "type": "module",
14
14
  "sideEffects": false,
15
15
  "dependencies": {
16
- "@dedot/codecs": "0.0.1-alpha.35",
17
- "@dedot/providers": "0.0.1-alpha.35",
18
- "@dedot/runtime-specs": "0.0.1-alpha.35",
19
- "@dedot/shape": "0.0.1-alpha.35",
20
- "@dedot/storage": "0.0.1-alpha.35",
21
- "@dedot/types": "0.0.1-alpha.35",
22
- "@dedot/utils": "0.0.1-alpha.35"
16
+ "@dedot/codecs": "0.0.1-alpha.37",
17
+ "@dedot/providers": "0.0.1-alpha.37",
18
+ "@dedot/runtime-specs": "0.0.1-alpha.37",
19
+ "@dedot/shape": "0.0.1-alpha.37",
20
+ "@dedot/storage": "0.0.1-alpha.37",
21
+ "@dedot/types": "0.0.1-alpha.37",
22
+ "@dedot/utils": "0.0.1-alpha.37"
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
  "devDependencies": {
49
49
  "@polkadot/types": "^12.0.1"
50
50
  },
51
- "gitHead": "bf954b82ac4c8a8e1d989c0c708a099269eb4262",
51
+ "gitHead": "6ed023a9455476d39ef810da46928b3f05621879",
52
52
  "module": "./index.js",
53
53
  "types": "./index.d.ts"
54
54
  }