@acala-network/chopsticks-core 0.8.0-1 → 0.8.0-2

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.
@@ -1,2 +1,2 @@
1
1
  import { DataSource } from 'typeorm';
2
- export declare const openDb: (dbPath: string) => Promise<DataSource>;
2
+ export declare const openDb: (sqlWasmUrl: URL) => Promise<DataSource>;
package/lib/db/browser.js CHANGED
@@ -40,17 +40,14 @@ const typeorm_1 = require("typeorm");
40
40
  const localforage_1 = require("localforage");
41
41
  const sql_js_1 = __importDefault(require("sql.js"));
42
42
  const entities = __importStar(require("./entities"));
43
- const openDb = (dbPath) => __awaiter(void 0, void 0, void 0, function* () {
43
+ const openDb = (sqlWasmUrl) => __awaiter(void 0, void 0, void 0, function* () {
44
44
  if (!globalThis.localforage) {
45
45
  globalThis.localforage = (0, localforage_1.createInstance)({ name: 'chopsticks' });
46
46
  }
47
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
48
- // @ts-ignore
49
- const wasmUrl = new URL('../../../../node_modules/sql.js/dist/sql-wasm.wasm', import.meta.url);
50
- const wasmBinary = yield fetch(wasmUrl).then((response) => response.arrayBuffer());
47
+ const wasmBinary = yield fetch(sqlWasmUrl).then((response) => response.arrayBuffer());
51
48
  const source = new typeorm_1.DataSource({
52
49
  type: 'sqljs',
53
- location: dbPath,
50
+ location: 'cache',
54
51
  entities: Object.values(entities),
55
52
  synchronize: true,
56
53
  autoSave: true,
package/lib/db/index.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const openDb: (dbPath: string) => Promise<import("typeorm").DataSource>;
1
+ export declare const openDb: (dbPath: string | URL) => Promise<import("typeorm").DataSource>;
package/lib/db/index.js CHANGED
@@ -34,11 +34,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
34
34
  Object.defineProperty(exports, "__esModule", { value: true });
35
35
  exports.openDb = void 0;
36
36
  const openDb = (dbPath) => __awaiter(void 0, void 0, void 0, function* () {
37
- if (typeof window === 'undefined') {
38
- return (yield Promise.resolve().then(() => __importStar(require('./node')))).openDb(dbPath);
37
+ if (dbPath instanceof URL) {
38
+ return (yield Promise.resolve().then(() => __importStar(require('./browser')))).openDb(dbPath);
39
39
  }
40
40
  else {
41
- return (yield Promise.resolve().then(() => __importStar(require('./browser')))).openDb(dbPath);
41
+ return (yield Promise.resolve().then(() => __importStar(require('./node')))).openDb(dbPath);
42
42
  }
43
43
  });
44
44
  exports.openDb = openDb;
package/lib/executor.js CHANGED
@@ -1,27 +1,4 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
2
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
3
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
4
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -39,14 +16,10 @@ exports.getAuraSlotDuration = exports.emptyTaskHandler = exports.taskHandler = e
39
16
  const util_1 = require("@polkadot/util");
40
17
  const util_crypto_1 = require("@polkadot/util-crypto");
41
18
  const key_cache_1 = require("./utils/key-cache");
19
+ const chopsticks_executor_1 = require("@acala-network/chopsticks-executor");
42
20
  const logger_1 = require("./logger");
43
21
  const lodash_1 = __importDefault(require("lodash"));
44
- const chopsticks_executor_1 = __importStar(require("@acala-network/chopsticks-executor"));
45
22
  const logger = logger_1.defaultLogger.child({ name: 'executor' });
46
- // init wasm on browser
47
- if (typeof chopsticks_executor_1.default === 'function') {
48
- (0, chopsticks_executor_1.default)();
49
- }
50
23
  const getRuntimeVersion = (code) => __awaiter(void 0, void 0, void 0, function* () {
51
24
  return (0, chopsticks_executor_1.get_runtime_version)(code).then((version) => {
52
25
  version.specName = (0, util_1.hexToString)(version.specName);
package/lib/setup.d.ts CHANGED
@@ -8,7 +8,7 @@ type Options = {
8
8
  block?: string | number | null;
9
9
  genesis?: string | Genesis;
10
10
  buildBlockMode?: BuildBlockMode;
11
- db?: string;
11
+ db?: string | URL;
12
12
  mockSignatureHost?: boolean;
13
13
  allowUnresolvedImports?: boolean;
14
14
  runtimeLogLevel?: number;
package/lib/setup.js CHANGED
@@ -49,6 +49,11 @@ const setup = (options) => __awaiter(void 0, void 0, void 0, function* () {
49
49
  logger_1.defaultLogger.debug(Object.assign(Object.assign({}, options), { blockHash }), 'Args');
50
50
  let db;
51
51
  if (options.db) {
52
+ if (typeof window !== 'undefined') {
53
+ if (!(options.db instanceof URL)) {
54
+ throw new Error('options.db must be an URL to sql-wasm.wasm when running in browser');
55
+ }
56
+ }
52
57
  db = yield (0, db_1.openDb)(options.db);
53
58
  }
54
59
  const header = yield api.getHeader(blockHash);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@acala-network/chopsticks-core",
3
- "version": "0.8.0-1",
3
+ "version": "0.8.0-2",
4
4
  "author": "Bryan Chen <xlchen1291@gmail.com>",
5
5
  "license": "Apache-2.0",
6
6
  "scripts": {
@@ -8,7 +8,7 @@
8
8
  "build": "tsc -p ./tsconfig.json"
9
9
  },
10
10
  "dependencies": {
11
- "@acala-network/chopsticks-executor": "0.8.0-1",
11
+ "@acala-network/chopsticks-executor": "0.8.0-2",
12
12
  "@polkadot/api": "^10.9.1",
13
13
  "axios": "^1.4.0",
14
14
  "eventemitter3": "^5.0.1",