@acala-network/chopsticks-core 0.11.0 → 0.12.1-1

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/dist/cjs/api.d.ts CHANGED
@@ -22,6 +22,8 @@ export declare class Api {
22
22
  get isReady(): Promise<void> | undefined;
23
23
  get chain(): Promise<string>;
24
24
  get chainProperties(): Promise<ChainProperties>;
25
+ onFetching(fetching?: () => void): void;
26
+ send<T = any>(method: string, params: unknown[], isCacheable?: boolean): Promise<T>;
25
27
  getSystemName(): Promise<string>;
26
28
  getSystemProperties(): Promise<ChainProperties>;
27
29
  getSystemChain(): Promise<string>;
package/dist/cjs/api.js CHANGED
@@ -68,7 +68,7 @@ function _interop_require_default(obj) {
68
68
  default: obj
69
69
  };
70
70
  }
71
- var _provider = /*#__PURE__*/ new WeakMap(), _ready = /*#__PURE__*/ new WeakMap(), _chain = /*#__PURE__*/ new WeakMap(), _chainProperties = /*#__PURE__*/ new WeakMap();
71
+ var _provider = /*#__PURE__*/ new WeakMap(), _ready = /*#__PURE__*/ new WeakMap(), _chain = /*#__PURE__*/ new WeakMap(), _chainProperties = /*#__PURE__*/ new WeakMap(), _apiHooks = /*#__PURE__*/ new WeakMap();
72
72
  class Api {
73
73
  async disconnect() {
74
74
  return _class_private_field_get(this, _provider).disconnect();
@@ -102,27 +102,35 @@ class Api {
102
102
  }
103
103
  return _class_private_field_get(this, _chainProperties);
104
104
  }
105
+ // Set the hook function to be called when api fetch endpoint.
106
+ onFetching(fetching) {
107
+ _class_private_field_get(this, _apiHooks).fetching = fetching;
108
+ }
109
+ async send(method, params, isCacheable) {
110
+ _class_private_field_get(this, _apiHooks)?.fetching?.();
111
+ return _class_private_field_get(this, _provider).send(method, params, isCacheable);
112
+ }
105
113
  async getSystemName() {
106
- return _class_private_field_get(this, _provider).send('system_name', []);
114
+ return this.send('system_name', []);
107
115
  }
108
116
  async getSystemProperties() {
109
- return _class_private_field_get(this, _provider).send('system_properties', []);
117
+ return this.send('system_properties', []);
110
118
  }
111
119
  async getSystemChain() {
112
- return _class_private_field_get(this, _provider).send('system_chain', []);
120
+ return this.send('system_chain', []);
113
121
  }
114
122
  async getBlockHash(blockNumber) {
115
- return _class_private_field_get(this, _provider).send('chain_getBlockHash', Number.isInteger(blockNumber) ? [
123
+ return this.send('chain_getBlockHash', Number.isInteger(blockNumber) ? [
116
124
  blockNumber
117
125
  ] : [], !!blockNumber);
118
126
  }
119
127
  async getHeader(hash) {
120
- return _class_private_field_get(this, _provider).send('chain_getHeader', hash ? [
128
+ return this.send('chain_getHeader', hash ? [
121
129
  hash
122
130
  ] : [], !!hash);
123
131
  }
124
132
  async getBlock(hash) {
125
- return _class_private_field_get(this, _provider).send('chain_getBlock', hash ? [
133
+ return this.send('chain_getBlock', hash ? [
126
134
  hash
127
135
  ] : [], !!hash);
128
136
  }
@@ -135,14 +143,14 @@ class Api {
135
143
  storageKey
136
144
  ];
137
145
  if (hash) params.push(hash);
138
- return _class_private_field_get(this, _provider).send('childstate_getStorage', params, !!hash);
146
+ return this.send('childstate_getStorage', params, !!hash);
139
147
  } else {
140
148
  // main storage key, use state_getStorage
141
149
  const params = [
142
150
  key
143
151
  ];
144
152
  if (hash) params.push(hash);
145
- return _class_private_field_get(this, _provider).send('state_getStorage', params, !!hash);
153
+ return this.send('state_getStorage', params, !!hash);
146
154
  }
147
155
  }
148
156
  async getKeysPaged(prefix, pageSize, startKey, hash) {
@@ -166,7 +174,7 @@ class Api {
166
174
  startKey
167
175
  ];
168
176
  if (hash) params.push(hash);
169
- return _class_private_field_get(this, _provider).send('state_getKeysPaged', params, !!hash);
177
+ return this.send('state_getKeysPaged', params, !!hash);
170
178
  }
171
179
  }
172
180
  async getStorageBatch(prefix, keys, hash) {
@@ -219,6 +227,10 @@ class Api {
219
227
  value: void 0
220
228
  });
221
229
  _define_property(this, "signedExtensions", void 0);
230
+ _class_private_field_init(this, _apiHooks, {
231
+ writable: true,
232
+ value: {}
233
+ });
222
234
  _class_private_field_set(this, _provider, provider);
223
235
  this.signedExtensions = signedExtensions || {};
224
236
  }
@@ -22,5 +22,6 @@ export declare class Database {
22
22
  deleteBlock: (hash: HexString) => Promise<void>;
23
23
  blocksCount: () => Promise<number>;
24
24
  saveStorage: (blockHash: HexString, key: HexString, value: HexString | null) => Promise<void>;
25
+ saveStorageBatch?: (entries: KeyValueEntry[]) => Promise<void>;
25
26
  queryStorage: (blockHash: HexString, key: HexString) => Promise<KeyValueEntry | null>;
26
27
  }
@@ -18,6 +18,9 @@ export type SetupOptions = {
18
18
  offchainWorker?: boolean;
19
19
  maxMemoryBlockCount?: number;
20
20
  processQueuedMessages?: boolean;
21
+ hooks?: {
22
+ apiFetching?: () => void;
23
+ };
21
24
  };
22
25
  export declare const processOptions: (options: SetupOptions) => Promise<{
23
26
  blockHash: string;
@@ -34,5 +37,8 @@ export declare const processOptions: (options: SetupOptions) => Promise<{
34
37
  offchainWorker?: boolean | undefined;
35
38
  maxMemoryBlockCount?: number | undefined;
36
39
  processQueuedMessages?: boolean | undefined;
40
+ hooks?: {
41
+ apiFetching?: (() => void) | undefined;
42
+ } | undefined;
37
43
  }>;
38
44
  export declare const setup: (options: SetupOptions) => Promise<Blockchain>;
package/dist/cjs/setup.js CHANGED
@@ -33,6 +33,8 @@ const processOptions = async (options)=>{
33
33
  provider = new _rpcprovider.WsProvider(options.endpoint, 3_000);
34
34
  }
35
35
  const api = new _api.Api(provider);
36
+ // setup api hooks
37
+ api.onFetching(options.hooks?.apiFetching);
36
38
  await api.isReady;
37
39
  let blockHash;
38
40
  if (options.block == null) {
@@ -59,7 +59,7 @@ const createProof = async (nodes, updates)=>{
59
59
  return _chopsticksexecutor.create_proof(nodes, updates);
60
60
  };
61
61
  const runTask = async (task, callback)=>{
62
- return _chopsticksexecutor.run_task(task, callback, 'info');
62
+ return _chopsticksexecutor.run_task(task, callback);
63
63
  };
64
64
  const testing = async (callback, key)=>{
65
65
  return _chopsticksexecutor.testing(callback, key);
@@ -66,7 +66,7 @@ const createProof = async (nodes, updates)=>{
66
66
  return _chopsticksexecutor.create_proof(nodes, updates);
67
67
  };
68
68
  const runTask = async (task, callback)=>{
69
- return _chopsticksexecutor.run_task(task, callback, process.env.RUST_LOG);
69
+ return _chopsticksexecutor.run_task(task, callback);
70
70
  };
71
71
  const testing = async (callback, key)=>{
72
72
  return _chopsticksexecutor.testing(callback, key);
package/dist/esm/api.d.ts CHANGED
@@ -22,6 +22,8 @@ export declare class Api {
22
22
  get isReady(): Promise<void> | undefined;
23
23
  get chain(): Promise<string>;
24
24
  get chainProperties(): Promise<ChainProperties>;
25
+ onFetching(fetching?: () => void): void;
26
+ send<T = any>(method: string, params: unknown[], isCacheable?: boolean): Promise<T>;
25
27
  getSystemName(): Promise<string>;
26
28
  getSystemProperties(): Promise<ChainProperties>;
27
29
  getSystemChain(): Promise<string>;
package/dist/esm/api.js CHANGED
@@ -17,6 +17,7 @@ import { prefixedChildKey, splitChildKey, stripChildPrefix } from './utils/index
17
17
  #chain;
18
18
  #chainProperties;
19
19
  signedExtensions;
20
+ #apiHooks = {};
20
21
  constructor(provider, signedExtensions){
21
22
  this.#provider = provider;
22
23
  this.signedExtensions = signedExtensions || {};
@@ -53,27 +54,35 @@ import { prefixedChildKey, splitChildKey, stripChildPrefix } from './utils/index
53
54
  }
54
55
  return this.#chainProperties;
55
56
  }
57
+ // Set the hook function to be called when api fetch endpoint.
58
+ onFetching(fetching) {
59
+ this.#apiHooks.fetching = fetching;
60
+ }
61
+ async send(method, params, isCacheable) {
62
+ this.#apiHooks?.fetching?.();
63
+ return this.#provider.send(method, params, isCacheable);
64
+ }
56
65
  async getSystemName() {
57
- return this.#provider.send('system_name', []);
66
+ return this.send('system_name', []);
58
67
  }
59
68
  async getSystemProperties() {
60
- return this.#provider.send('system_properties', []);
69
+ return this.send('system_properties', []);
61
70
  }
62
71
  async getSystemChain() {
63
- return this.#provider.send('system_chain', []);
72
+ return this.send('system_chain', []);
64
73
  }
65
74
  async getBlockHash(blockNumber) {
66
- return this.#provider.send('chain_getBlockHash', Number.isInteger(blockNumber) ? [
75
+ return this.send('chain_getBlockHash', Number.isInteger(blockNumber) ? [
67
76
  blockNumber
68
77
  ] : [], !!blockNumber);
69
78
  }
70
79
  async getHeader(hash) {
71
- return this.#provider.send('chain_getHeader', hash ? [
80
+ return this.send('chain_getHeader', hash ? [
72
81
  hash
73
82
  ] : [], !!hash);
74
83
  }
75
84
  async getBlock(hash) {
76
- return this.#provider.send('chain_getBlock', hash ? [
85
+ return this.send('chain_getBlock', hash ? [
77
86
  hash
78
87
  ] : [], !!hash);
79
88
  }
@@ -86,14 +95,14 @@ import { prefixedChildKey, splitChildKey, stripChildPrefix } from './utils/index
86
95
  storageKey
87
96
  ];
88
97
  if (hash) params.push(hash);
89
- return this.#provider.send('childstate_getStorage', params, !!hash);
98
+ return this.send('childstate_getStorage', params, !!hash);
90
99
  } else {
91
100
  // main storage key, use state_getStorage
92
101
  const params = [
93
102
  key
94
103
  ];
95
104
  if (hash) params.push(hash);
96
- return this.#provider.send('state_getStorage', params, !!hash);
105
+ return this.send('state_getStorage', params, !!hash);
97
106
  }
98
107
  }
99
108
  async getKeysPaged(prefix, pageSize, startKey, hash) {
@@ -117,7 +126,7 @@ import { prefixedChildKey, splitChildKey, stripChildPrefix } from './utils/index
117
126
  startKey
118
127
  ];
119
128
  if (hash) params.push(hash);
120
- return this.#provider.send('state_getKeysPaged', params, !!hash);
129
+ return this.send('state_getKeysPaged', params, !!hash);
121
130
  }
122
131
  }
123
132
  async getStorageBatch(prefix, keys, hash) {
@@ -22,5 +22,6 @@ export declare class Database {
22
22
  deleteBlock: (hash: HexString) => Promise<void>;
23
23
  blocksCount: () => Promise<number>;
24
24
  saveStorage: (blockHash: HexString, key: HexString, value: HexString | null) => Promise<void>;
25
+ saveStorageBatch?: (entries: KeyValueEntry[]) => Promise<void>;
25
26
  queryStorage: (blockHash: HexString, key: HexString) => Promise<KeyValueEntry | null>;
26
27
  }
@@ -18,6 +18,9 @@ export type SetupOptions = {
18
18
  offchainWorker?: boolean;
19
19
  maxMemoryBlockCount?: number;
20
20
  processQueuedMessages?: boolean;
21
+ hooks?: {
22
+ apiFetching?: () => void;
23
+ };
21
24
  };
22
25
  export declare const processOptions: (options: SetupOptions) => Promise<{
23
26
  blockHash: string;
@@ -34,5 +37,8 @@ export declare const processOptions: (options: SetupOptions) => Promise<{
34
37
  offchainWorker?: boolean | undefined;
35
38
  maxMemoryBlockCount?: number | undefined;
36
39
  processQueuedMessages?: boolean | undefined;
40
+ hooks?: {
41
+ apiFetching?: (() => void) | undefined;
42
+ } | undefined;
37
43
  }>;
38
44
  export declare const setup: (options: SetupOptions) => Promise<Blockchain>;
package/dist/esm/setup.js CHANGED
@@ -15,6 +15,8 @@ export const processOptions = async (options)=>{
15
15
  provider = new WsProvider(options.endpoint, 3_000);
16
16
  }
17
17
  const api = new Api(provider);
18
+ // setup api hooks
19
+ api.onFetching(options.hooks?.apiFetching);
18
20
  await api.isReady;
19
21
  let blockHash;
20
22
  if (options.block == null) {
@@ -14,7 +14,7 @@ const createProof = async (nodes, updates)=>{
14
14
  return pkg.create_proof(nodes, updates);
15
15
  };
16
16
  const runTask = async (task, callback)=>{
17
- return pkg.run_task(task, callback, 'info');
17
+ return pkg.run_task(task, callback);
18
18
  };
19
19
  const testing = async (callback, key)=>{
20
20
  return pkg.testing(callback, key);
@@ -16,7 +16,7 @@ const createProof = async (nodes, updates)=>{
16
16
  return pkg.create_proof(nodes, updates);
17
17
  };
18
18
  const runTask = async (task, callback)=>{
19
- return pkg.run_task(task, callback, process.env.RUST_LOG);
19
+ return pkg.run_task(task, callback);
20
20
  };
21
21
  const testing = async (callback, key)=>{
22
22
  return pkg.testing(callback, key);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@acala-network/chopsticks-core",
3
- "version": "0.11.0",
3
+ "version": "0.12.1-1",
4
4
  "author": "Acala Developers <hello@acala.network>",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
@@ -9,10 +9,11 @@
9
9
  "build": "yarn clean && yarn build:cjs && yarn build:esm",
10
10
  "build:cjs": "swc ./src --config-file ../../.cjsswcrc -d dist/cjs && tsc -p tsconfig.json --declarationDir dist/cjs && echo '{\"type\": \"commonjs\"}' > dist/cjs/package.json",
11
11
  "build:esm": "swc ./src --config-file ../../.esmswcrc -d dist/esm && tsc -p tsconfig.json --declarationDir dist/esm",
12
- "docs:prep": "typedoc"
12
+ "docs:prep": "typedoc",
13
+ "depcheck": "npx depcheck --ignores=pino-pretty"
13
14
  },
14
15
  "dependencies": {
15
- "@acala-network/chopsticks-executor": "0.11.0",
16
+ "@acala-network/chopsticks-executor": "0.12.1-1",
16
17
  "@polkadot/rpc-provider": "^10.11.2",
17
18
  "@polkadot/types": "^10.11.2",
18
19
  "@polkadot/types-codec": "^10.11.2",