@acala-network/chopsticks 0.10.2 → 0.12.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 (47) hide show
  1. package/dist/cjs/cli.js +4 -1
  2. package/dist/cjs/context.d.ts +11 -0
  3. package/dist/cjs/context.js +14 -2
  4. package/dist/cjs/logger.d.ts +3 -0
  5. package/dist/cjs/logger.js +45 -0
  6. package/dist/cjs/plugins/dry-run/index.d.ts +3 -0
  7. package/dist/cjs/plugins/dry-run/rpc.d.ts +4 -4
  8. package/dist/cjs/plugins/fetch-storage/cli.d.ts +2 -0
  9. package/dist/cjs/plugins/fetch-storage/cli.js +49 -0
  10. package/dist/cjs/plugins/fetch-storage/index.d.ts +1 -0
  11. package/dist/cjs/plugins/fetch-storage/index.js +18 -0
  12. package/dist/cjs/plugins/index.d.ts +3 -1
  13. package/dist/cjs/plugins/index.js +30 -2
  14. package/dist/cjs/rpc/index.js +3 -3
  15. package/dist/cjs/schema/index.d.ts +3 -0
  16. package/dist/cjs/schema/index.js +4 -1
  17. package/dist/cjs/setup-with-server.d.ts +11 -0
  18. package/dist/cjs/setup-with-server.js +1 -0
  19. package/dist/cjs/utils/fetch-storages-worker.js +62 -0
  20. package/dist/cjs/utils/fetch-storages.d.ts +26 -0
  21. package/dist/cjs/utils/fetch-storages.js +213 -0
  22. package/dist/cjs/utils/index.d.ts +1 -0
  23. package/dist/cjs/utils/index.js +1 -0
  24. package/dist/esm/cli.js +5 -2
  25. package/dist/esm/context.d.ts +11 -0
  26. package/dist/esm/context.js +14 -2
  27. package/dist/esm/logger.d.ts +3 -0
  28. package/dist/esm/logger.js +34 -0
  29. package/dist/esm/plugins/dry-run/index.d.ts +3 -0
  30. package/dist/esm/plugins/dry-run/rpc.d.ts +4 -4
  31. package/dist/esm/plugins/fetch-storage/cli.d.ts +2 -0
  32. package/dist/esm/plugins/fetch-storage/cli.js +34 -0
  33. package/dist/esm/plugins/fetch-storage/index.d.ts +1 -0
  34. package/dist/esm/plugins/fetch-storage/index.js +1 -0
  35. package/dist/esm/plugins/index.d.ts +3 -1
  36. package/dist/esm/plugins/index.js +25 -2
  37. package/dist/esm/rpc/index.js +4 -4
  38. package/dist/esm/schema/index.d.ts +3 -0
  39. package/dist/esm/schema/index.js +4 -1
  40. package/dist/esm/setup-with-server.d.ts +11 -0
  41. package/dist/esm/setup-with-server.js +1 -0
  42. package/dist/esm/utils/fetch-storages-worker.js +12 -0
  43. package/dist/esm/utils/fetch-storages.d.ts +26 -0
  44. package/dist/esm/utils/fetch-storages.js +188 -0
  45. package/dist/esm/utils/index.d.ts +1 -0
  46. package/dist/esm/utils/index.js +1 -0
  47. package/package.json +3 -3
package/dist/cjs/cli.js CHANGED
@@ -17,6 +17,9 @@ function _interop_require_default(obj) {
17
17
  }
18
18
  (0, _dotenv.config)();
19
19
  const processArgv = async (argv)=>{
20
+ if (argv.unsafeRpcMethods) {
21
+ await (0, _index1.loadRpcMethodsByScripts)(argv.unsafeRpcMethods);
22
+ }
20
23
  if (argv.config) {
21
24
  Object.assign(argv, _lodash.default.defaults(argv, await (0, _index.fetchConfig)(argv.config)));
22
25
  }
@@ -52,7 +55,7 @@ const commands = (0, _yargs.default)((0, _helpers.hideBin)(process.argv)).script
52
55
  await (0, _chopstickscore.connectVertical)(relaychain, parachain);
53
56
  }
54
57
  }
55
- }).strict().help().alias('help', 'h').alias('version', 'v').alias('config', 'c').alias('endpoint', 'e').alias('port', 'p').alias('block', 'b').alias('import-storage', 's').alias('wasm-override', 'w').usage('Usage: $0 <command> [options]').example('$0', '-c acala');
58
+ }).strict().help().alias('help', 'h').alias('version', 'v').alias('config', 'c').alias('endpoint', 'e').alias('port', 'p').alias('block', 'b').alias('unsafe-rpc-methods', 'ur').alias('import-storage', 's').alias('wasm-override', 'w').usage('Usage: $0 <command> [options]').example('$0', '-c acala');
56
59
  if (!_chopstickscore.environment.DISABLE_PLUGINS) {
57
60
  (0, _index1.pluginExtendCli)(commands.config('config', 'Path to config file with default options', ()=>({}))).then(()=>commands.parse());
58
61
  } else {
@@ -4,4 +4,15 @@ import { Config } from './schema/index.js';
4
4
  export declare const genesisFromUrl: (url: string) => Promise<GenesisProvider>;
5
5
  export declare const setupContext: (argv: Config, overrideParent?: boolean) => Promise<{
6
6
  chain: import("@acala-network/chopsticks-core").Blockchain;
7
+ fetchStorageWorker: {
8
+ worker: import("comlink").Remote<{
9
+ startFetch: (options: {
10
+ block?: string | number | null | undefined;
11
+ endpoint?: string | string[] | undefined;
12
+ dbPath?: string | undefined;
13
+ config: import("./utils/fetch-storages.js").FetchStorageConfig;
14
+ }) => Promise<void>;
15
+ }>;
16
+ terminate: () => Promise<void>;
17
+ } | null;
7
18
  }>;
@@ -19,7 +19,9 @@ _export(exports, {
19
19
  require("./utils/tunnel.js");
20
20
  const _chopstickscore = require("@acala-network/chopsticks-core");
21
21
  const _chopsticksdb = require("@acala-network/chopsticks-db");
22
+ const _logger = require("./logger.js");
22
23
  const _override = require("./utils/override.js");
24
+ const _fetchstorages = require("./utils/fetch-storages.js");
23
25
  const _axios = /*#__PURE__*/ _interop_require_default(require("axios"));
24
26
  function _interop_require_default(obj) {
25
27
  return obj && obj.__esModule ? obj : {
@@ -105,7 +107,10 @@ const setupContext = async (argv, overrideParent = false)=>{
105
107
  registeredTypes: argv['registered-types'],
106
108
  offchainWorker: argv['offchain-worker'],
107
109
  maxMemoryBlockCount: argv['max-memory-block-count'],
108
- processQueuedMessages: argv['process-queued-messages']
110
+ processQueuedMessages: argv['process-queued-messages'],
111
+ hooks: {
112
+ apiFetching: _logger.apiFetching
113
+ }
109
114
  });
110
115
  // load block from db
111
116
  if (chain.db) {
@@ -141,7 +146,14 @@ const setupContext = async (argv, overrideParent = false)=>{
141
146
  // added that have storage imports
142
147
  await (0, _override.overrideWasm)(chain, argv['wasm-override'], at);
143
148
  await (0, _override.overrideStorage)(chain, argv['import-storage'], at);
149
+ const fetchStorageWorker = await (0, _fetchstorages.startFetchStorageWorker)({
150
+ config: argv['prefetch-storages'],
151
+ dbPath: argv.db,
152
+ block: argv.block,
153
+ endpoint: argv.endpoint
154
+ });
144
155
  return {
145
- chain
156
+ chain,
157
+ fetchStorageWorker
146
158
  };
147
159
  };
@@ -1 +1,4 @@
1
+ import _ from 'lodash';
1
2
  export { defaultLogger, truncate } from '@acala-network/chopsticks-core';
3
+ export declare const spinnerFrames: string[];
4
+ export declare const apiFetching: _.DebouncedFunc<() => void>;
@@ -9,11 +9,56 @@ function _export(target, all) {
9
9
  });
10
10
  }
11
11
  _export(exports, {
12
+ apiFetching: function() {
13
+ return apiFetching;
14
+ },
12
15
  defaultLogger: function() {
13
16
  return _chopstickscore.defaultLogger;
14
17
  },
18
+ spinnerFrames: function() {
19
+ return spinnerFrames;
20
+ },
15
21
  truncate: function() {
16
22
  return _chopstickscore.truncate;
17
23
  }
18
24
  });
25
+ const _lodash = /*#__PURE__*/ _interop_require_default(require("lodash"));
19
26
  const _chopstickscore = require("@acala-network/chopsticks-core");
27
+ function _interop_require_default(obj) {
28
+ return obj && obj.__esModule ? obj : {
29
+ default: obj
30
+ };
31
+ }
32
+ const showProgress = process.stdout.isTTY && !process.env['CI'] && !process.env['TEST'];
33
+ const spinnerFrames = process.platform === 'win32' ? [
34
+ '-',
35
+ '\\',
36
+ '|',
37
+ '/'
38
+ ] : [
39
+ '⠋',
40
+ '⠙',
41
+ '⠹',
42
+ '⠸',
43
+ '⠼',
44
+ '⠴',
45
+ '⠦',
46
+ '⠧',
47
+ '⠇',
48
+ '⠏'
49
+ ];
50
+ let index = 0;
51
+ // clear to the right from cursor
52
+ const clearStatus = _lodash.default.debounce(()=>process.stdout.clearLine(1), 500, {
53
+ trailing: true
54
+ });
55
+ const apiFetching = _lodash.default.throttle(()=>{
56
+ if (!showProgress) return;
57
+ // print ` ⠋ Fetching|` and move cursor at position 0 of the line `| ⠋ Fetching`
58
+ process.stdout.write(` ${spinnerFrames[index++]} Fetching`);
59
+ process.stdout.cursorTo(0);
60
+ index = ++index % spinnerFrames.length;
61
+ clearStatus();
62
+ }, 50, {
63
+ leading: true
64
+ });
@@ -83,6 +83,7 @@ export declare const dryRunSchema: z.ZodObject<{
83
83
  'offchain-worker': z.ZodOptional<z.ZodBoolean>;
84
84
  resume: z.ZodOptional<z.ZodUnion<[z.ZodIntersection<z.ZodString, z.ZodType<`0x${string}`, z.ZodTypeDef, `0x${string}`>>, z.ZodNumber, z.ZodBoolean]>>;
85
85
  'process-queued-messages': z.ZodOptional<z.ZodBoolean>;
86
+ 'prefetch-storages': z.ZodOptional<z.ZodAny>;
86
87
  }, "strip", z.ZodTypeAny, {
87
88
  port: number;
88
89
  'build-block-mode': import("@acala-network/chopsticks-core").BuildBlockMode;
@@ -121,6 +122,7 @@ export declare const dryRunSchema: z.ZodObject<{
121
122
  'offchain-worker'?: boolean | undefined;
122
123
  resume?: number | boolean | `0x${string}` | undefined;
123
124
  'process-queued-messages'?: boolean | undefined;
125
+ 'prefetch-storages'?: any;
124
126
  }, {
125
127
  extrinsic?: string | undefined;
126
128
  address?: string | undefined;
@@ -159,6 +161,7 @@ export declare const dryRunSchema: z.ZodObject<{
159
161
  'offchain-worker'?: boolean | undefined;
160
162
  resume?: number | boolean | `0x${string}` | undefined;
161
163
  'process-queued-messages'?: boolean | undefined;
164
+ 'prefetch-storages'?: any;
162
165
  }>;
163
166
  export type DryRunSchemaType = z.infer<typeof dryRunSchema>;
164
167
  export * from './cli.js';
@@ -7,11 +7,11 @@ declare const schema: z.ZodObject<{
7
7
  call: z.ZodType<`0x${string}`, z.ZodTypeDef, `0x${string}`>;
8
8
  address: z.ZodType<`0x${string}`, z.ZodTypeDef, `0x${string}`>;
9
9
  }, "strip", z.ZodTypeAny, {
10
- address: `0x${string}`;
11
10
  call: `0x${string}`;
12
- }, {
13
11
  address: `0x${string}`;
12
+ }, {
14
13
  call: `0x${string}`;
14
+ address: `0x${string}`;
15
15
  }>]>>;
16
16
  hrmp: z.ZodOptional<z.ZodRecord<z.ZodEffects<z.ZodString, number, string>, z.ZodArray<z.ZodObject<{
17
17
  sentAt: z.ZodNumber;
@@ -39,8 +39,8 @@ declare const schema: z.ZodObject<{
39
39
  raw?: boolean | undefined;
40
40
  html?: boolean | undefined;
41
41
  extrinsic?: `0x${string}` | {
42
- address: `0x${string}`;
43
42
  call: `0x${string}`;
43
+ address: `0x${string}`;
44
44
  } | undefined;
45
45
  hrmp?: Record<number, {
46
46
  data: `0x${string}`;
@@ -56,8 +56,8 @@ declare const schema: z.ZodObject<{
56
56
  raw?: boolean | undefined;
57
57
  html?: boolean | undefined;
58
58
  extrinsic?: `0x${string}` | {
59
- address: `0x${string}`;
60
59
  call: `0x${string}`;
60
+ address: `0x${string}`;
61
61
  } | undefined;
62
62
  hrmp?: Record<string, {
63
63
  data: `0x${string}`;
@@ -0,0 +1,2 @@
1
+ import type { Argv } from 'yargs';
2
+ export declare const cli: (y: Argv) => void;
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "cli", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return cli;
9
+ }
10
+ });
11
+ const _zod = require("zod");
12
+ const _lodash = /*#__PURE__*/ _interop_require_default(require("lodash"));
13
+ const _index = require("../../schema/index.js");
14
+ const _fetchstorages = require("../../utils/fetch-storages.js");
15
+ function _interop_require_default(obj) {
16
+ return obj && obj.__esModule ? obj : {
17
+ default: obj
18
+ };
19
+ }
20
+ const schema = _zod.z.object(_lodash.default.pick(_index.configSchema.shape, [
21
+ 'endpoint',
22
+ 'block',
23
+ 'db'
24
+ ]));
25
+ const cli = (y)=>{
26
+ y.command({
27
+ command: 'fetch-storages [items..]',
28
+ aliases: [
29
+ 'fetch-storage'
30
+ ],
31
+ describe: 'Fetch and save storages',
32
+ builder: (yargs)=>yargs.options((0, _index.getYargsOptions)(schema.shape)),
33
+ handler: async (argv)=>{
34
+ const config = schema.parse(argv);
35
+ if (!argv.items) throw new Error('fetch-storages items are required');
36
+ try {
37
+ await (0, _fetchstorages.fetchStorages)({
38
+ block: config.block,
39
+ endpoint: config.endpoint,
40
+ dbPath: config.db,
41
+ config: argv.items
42
+ });
43
+ process.exit(0);
44
+ } catch (e) {
45
+ process.exit(1);
46
+ }
47
+ }
48
+ });
49
+ };
@@ -0,0 +1 @@
1
+ export * from './cli.js';
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ _export_star(require("./cli.js"), exports);
6
+ function _export_star(from, to) {
7
+ Object.keys(from).forEach(function(k) {
8
+ if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
9
+ Object.defineProperty(to, k, {
10
+ enumerable: true,
11
+ get: function() {
12
+ return from[k];
13
+ }
14
+ });
15
+ }
16
+ });
17
+ return from;
18
+ }
@@ -2,5 +2,7 @@ import { Handlers } from '@acala-network/chopsticks-core';
2
2
  import type { Argv } from 'yargs';
3
3
  export declare const rpcPluginHandlers: Handlers;
4
4
  export declare const rpcPluginMethods: string[];
5
- export declare const loadRpcPlugin: (method: string) => Promise<any>;
5
+ export declare const loadRpcMethodsByScripts: (path: string) => Promise<void>;
6
+ export declare const getRpcExtensionMethods: () => string[];
7
+ export declare const loadRpcExtensionMethod: (method: string) => Promise<any>;
6
8
  export declare const pluginExtendCli: (y: Argv) => Promise<void>;
@@ -9,8 +9,14 @@ function _export(target, all) {
9
9
  });
10
10
  }
11
11
  _export(exports, {
12
- loadRpcPlugin: function() {
13
- return loadRpcPlugin;
12
+ getRpcExtensionMethods: function() {
13
+ return getRpcExtensionMethods;
14
+ },
15
+ loadRpcExtensionMethod: function() {
16
+ return loadRpcExtensionMethod;
17
+ },
18
+ loadRpcMethodsByScripts: function() {
19
+ return loadRpcMethodsByScripts;
14
20
  },
15
21
  pluginExtendCli: function() {
16
22
  return pluginExtendCli;
@@ -26,6 +32,7 @@ const _chopstickscore = require("@acala-network/chopsticks-core");
26
32
  const _fs = require("fs");
27
33
  const _lodash = /*#__PURE__*/ _interop_require_default(require("lodash"));
28
34
  const _logger = require("../logger.js");
35
+ const _path = require("path");
29
36
  function _interop_require_default(obj) {
30
37
  return obj && obj.__esModule ? obj : {
31
38
  default: obj
@@ -93,6 +100,27 @@ const loadRpcPlugin = async (method)=>{
93
100
  logger.debug(`Registered plugin ${plugin} RPC`);
94
101
  return rpc;
95
102
  };
103
+ // store the loaded methods by cli
104
+ let rpcScriptMethods = {};
105
+ const loadRpcMethodsByScripts = async (path)=>{
106
+ try {
107
+ const scriptContent = (0, _fs.readFileSync)((0, _path.resolve)(path), 'utf8');
108
+ rpcScriptMethods = new Function(scriptContent)();
109
+ logger.info(`${Object.keys(rpcScriptMethods).length} extension rpc methods loaded from ${path}`);
110
+ } catch (error) {
111
+ console.log('Failed to load rpc extension methods');
112
+ }
113
+ };
114
+ const getRpcExtensionMethods = ()=>{
115
+ return [
116
+ ...Object.keys(rpcScriptMethods),
117
+ ...rpcPluginMethods
118
+ ];
119
+ };
120
+ const loadRpcExtensionMethod = async (method)=>{
121
+ if (rpcScriptMethods[method]) return rpcScriptMethods[method];
122
+ return loadRpcPlugin(method);
123
+ };
96
124
  const pluginExtendCli = async (y)=>{
97
125
  for (const plugin of plugins){
98
126
  const location = new URL(`${plugin}/index.js`, require("url").pathToFileURL(__filename).toString());
@@ -19,15 +19,15 @@ const allHandlers = {
19
19
  version: 1,
20
20
  methods: [
21
21
  ...Object.keys(allHandlers),
22
- ..._index.rpcPluginMethods
22
+ ...(0, _index.getRpcExtensionMethods)()
23
23
  ].sort()
24
24
  })
25
25
  };
26
26
  const getHandler = async (method)=>{
27
27
  const handler = allHandlers[method];
28
28
  if (!handler) {
29
- // no handler for this method, check if it's a plugin
30
- return (0, _index.loadRpcPlugin)(method);
29
+ // no handler for this method, check if it's a plugin or a script loaded
30
+ return (0, _index.loadRpcExtensionMethod)(method);
31
31
  }
32
32
  return handler;
33
33
  };
@@ -79,6 +79,7 @@ export declare const configSchema: z.ZodObject<{
79
79
  'offchain-worker': z.ZodOptional<z.ZodBoolean>;
80
80
  resume: z.ZodOptional<z.ZodUnion<[z.ZodIntersection<z.ZodString, z.ZodType<`0x${string}`, z.ZodTypeDef, `0x${string}`>>, z.ZodNumber, z.ZodBoolean]>>;
81
81
  'process-queued-messages': z.ZodOptional<z.ZodBoolean>;
82
+ 'prefetch-storages': z.ZodOptional<z.ZodAny>;
82
83
  }, "strip", ZodTypeAny, {
83
84
  port: number;
84
85
  'build-block-mode': BuildBlockMode;
@@ -110,6 +111,7 @@ export declare const configSchema: z.ZodObject<{
110
111
  'offchain-worker'?: boolean | undefined;
111
112
  resume?: number | boolean | `0x${string}` | undefined;
112
113
  'process-queued-messages'?: boolean | undefined;
114
+ 'prefetch-storages'?: any;
113
115
  }, {
114
116
  port?: number | undefined;
115
117
  endpoint?: string | string[] | undefined;
@@ -141,6 +143,7 @@ export declare const configSchema: z.ZodObject<{
141
143
  'offchain-worker'?: boolean | undefined;
142
144
  resume?: number | boolean | `0x${string}` | undefined;
143
145
  'process-queued-messages'?: boolean | undefined;
146
+ 'prefetch-storages'?: any;
144
147
  }>;
145
148
  export type Config = z.infer<typeof configSchema>;
146
149
  export declare const getYargsOptions: (zodShape: ZodRawShape) => {
@@ -51,7 +51,7 @@ const configSchema = _zod.z.object({
51
51
  }).optional(),
52
52
  block: _zod.z.union([
53
53
  _zod.z.string(),
54
- _zod.z.number().max(Number.MAX_SAFE_INTEGER, 'Number is too big, please make it a string if you are uing a hex string'),
54
+ _zod.z.number().max(Number.MAX_SAFE_INTEGER, 'Number is too big, please make it a string if you are using a hex string'),
55
55
  _zod.z.null()
56
56
  ], {
57
57
  description: 'Block hash or block number. Default to latest block'
@@ -94,6 +94,9 @@ const configSchema = _zod.z.object({
94
94
  }).optional(),
95
95
  'process-queued-messages': _zod.z.boolean({
96
96
  description: 'Produce extra block when queued messages are detected. Default to true. Set to false to disable it.'
97
+ }).optional(),
98
+ 'prefetch-storages': _zod.z.any({
99
+ description: 'Storage key prefixes config for fetching storage, useful for testing big migrations, see README for examples'
97
100
  }).optional()
98
101
  });
99
102
  const getZodType = (option)=>{
@@ -3,4 +3,15 @@ export declare const setupWithServer: (argv: Config) => Promise<{
3
3
  listenPort: number;
4
4
  close(): Promise<void>;
5
5
  chain: import("@acala-network/chopsticks-core").Blockchain;
6
+ fetchStorageWorker: {
7
+ worker: import("comlink").Remote<{
8
+ startFetch: (options: {
9
+ block?: string | number | null | undefined;
10
+ endpoint?: string | string[] | undefined;
11
+ dbPath?: string | undefined;
12
+ config: import("./utils/fetch-storages.js").FetchStorageConfig;
13
+ }) => Promise<void>;
14
+ }>;
15
+ terminate: () => Promise<void>;
16
+ } | null;
6
17
  }>;
@@ -21,6 +21,7 @@ const setupWithServer = async (argv)=>{
21
21
  listenPort,
22
22
  async close () {
23
23
  await context.chain.close();
24
+ await context.fetchStorageWorker?.terminate();
24
25
  await close();
25
26
  }
26
27
  };
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ const _comlink = /*#__PURE__*/ _interop_require_wildcard(require("comlink"));
6
+ const _nodeworker_threads = require("node:worker_threads");
7
+ const _nodeadapter = /*#__PURE__*/ _interop_require_default(require("comlink/dist/umd/node-adapter.js"));
8
+ const _fetchstorages = require("./fetch-storages.js");
9
+ function _interop_require_default(obj) {
10
+ return obj && obj.__esModule ? obj : {
11
+ default: obj
12
+ };
13
+ }
14
+ function _getRequireWildcardCache(nodeInterop) {
15
+ if (typeof WeakMap !== "function") return null;
16
+ var cacheBabelInterop = new WeakMap();
17
+ var cacheNodeInterop = new WeakMap();
18
+ return (_getRequireWildcardCache = function(nodeInterop) {
19
+ return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
20
+ })(nodeInterop);
21
+ }
22
+ function _interop_require_wildcard(obj, nodeInterop) {
23
+ if (!nodeInterop && obj && obj.__esModule) {
24
+ return obj;
25
+ }
26
+ if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
27
+ return {
28
+ default: obj
29
+ };
30
+ }
31
+ var cache = _getRequireWildcardCache(nodeInterop);
32
+ if (cache && cache.has(obj)) {
33
+ return cache.get(obj);
34
+ }
35
+ var newObj = {
36
+ __proto__: null
37
+ };
38
+ var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
39
+ for(var key in obj){
40
+ if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
41
+ var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
42
+ if (desc && (desc.get || desc.set)) {
43
+ Object.defineProperty(newObj, key, desc);
44
+ } else {
45
+ newObj[key] = obj[key];
46
+ }
47
+ }
48
+ }
49
+ newObj.default = obj;
50
+ if (cache) {
51
+ cache.set(obj, newObj);
52
+ }
53
+ return newObj;
54
+ }
55
+ const api = {
56
+ startFetch: async ({ ...options })=>{
57
+ await (0, _fetchstorages.fetchStorages)({
58
+ ...options
59
+ });
60
+ }
61
+ };
62
+ _comlink.expose(api, (0, _nodeadapter.default)(_nodeworker_threads.parentPort));
@@ -0,0 +1,26 @@
1
+ import { ApiPromise } from '@polkadot/api';
2
+ import { HexString } from '@polkadot/util/types';
3
+ export declare const logger: import("pino").default.Logger<never>;
4
+ type FetchStorageConfigItem = HexString | string | Record<string, string | Record<string, any[]> | Record<string, any>[] | (string | any)[]>;
5
+ export type FetchStorageConfig = FetchStorageConfigItem[];
6
+ /**
7
+ * Convert fetch-storage configs to prefixes for fetching.
8
+ */
9
+ export declare const getPrefixesFromConfig: (config: FetchStorageConfig, api: ApiPromise) => Promise<string[]>;
10
+ type FetchStoragesParams = {
11
+ block?: number | string | null;
12
+ endpoint?: string | string[];
13
+ dbPath?: string;
14
+ config: FetchStorageConfig;
15
+ };
16
+ /**
17
+ * Fetch storages and save in a local db
18
+ */
19
+ export declare const fetchStorages: ({ block, endpoint, dbPath, config }: FetchStoragesParams) => Promise<void>;
20
+ export declare const startFetchStorageWorker: (options: FetchStoragesParams) => Promise<{
21
+ worker: import("comlink").Remote<{
22
+ startFetch: (options: FetchStoragesParams) => Promise<void>;
23
+ }>;
24
+ terminate: () => Promise<void>;
25
+ } | null>;
26
+ export {};