@steerprotocol/app-loader 1.0.2 → 1.0.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.
Files changed (2) hide show
  1. package/lib/index.js +39 -74
  2. package/package.json +1 -1
package/lib/index.js CHANGED
@@ -33,14 +33,14 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
33
33
  };
34
34
  Object.defineProperty(exports, "__esModule", { value: true });
35
35
  exports.loadWasm = exports.loadWasmSync = exports.RawTradeData = exports.Candle = void 0;
36
- /* eslint-disable @typescript-eslint/no-explicit-any */
37
- /* eslint-disable @typescript-eslint/ban-ts-comment */
38
- //import ccxt from "ccxt";
39
36
  const Candle_1 = require("./Candle");
40
37
  Object.defineProperty(exports, "Candle", { enumerable: true, get: function () { return Candle_1.Candle; } });
41
38
  const RawTradeData_1 = require("./RawTradeData");
42
39
  Object.defineProperty(exports, "RawTradeData", { enumerable: true, get: function () { return RawTradeData_1.RawTradeData; } });
40
+ let isNode = process || null;
43
41
  let fetchImpl = null;
42
+ let fsImpl = null;
43
+ let ccxt = null;
44
44
  if (globalThis["fetch"])
45
45
  fetchImpl = fetch;
46
46
  var State;
@@ -69,18 +69,16 @@ function loadWasm(input, imports = {}) {
69
69
  return __awaiter(this, void 0, void 0, function* () {
70
70
  const mod = instantiate(yield (() => __awaiter(this, void 0, void 0, function* () {
71
71
  if (typeof input === "string") {
72
- try {
73
- if (!globalThis["fetch"]) {
72
+ if (isNode) {
73
+ if (!fetchImpl)
74
74
  fetchImpl = (yield Promise.resolve().then(() => __importStar(require("undici")))).fetch;
75
- return WebAssembly.compile(yield (yield Promise.resolve().then(() => __importStar(require("fs/promises")))).readFile(input));
76
- }
77
- else {
78
- return yield WebAssembly.compileStreaming(fetchImpl(input));
79
- }
80
- }
81
- catch (_a) {
82
- return WebAssembly.compile(yield (yield Promise.resolve().then(() => __importStar(require("fs/promises")))).readFile(input));
75
+ if (!fsImpl)
76
+ fsImpl = yield Promise.resolve().then(() => __importStar(require("fs/promises")));
77
+ if (!ccxt)
78
+ ccxt = (yield Promise.resolve().then(() => __importStar(require("ccxt")))).default;
79
+ return WebAssembly.compile(yield fsImpl.readFile(input));
83
80
  }
81
+ return yield WebAssembly.compileStreaming(globalThis.fetch(input));
84
82
  }
85
83
  else {
86
84
  return WebAssembly.compile(input);
@@ -92,11 +90,9 @@ function loadWasm(input, imports = {}) {
92
90
  exports.loadWasm = loadWasm;
93
91
  function instantiate(module, imports = {}) {
94
92
  let WASM_MEMORY;
95
- // eslint-disable-next-line prefer-const
96
93
  let WASM_EXPORTS;
97
94
  let WASM_DV;
98
95
  let ASYNCIFY_PTR = 0;
99
- // eslint-disable-next-line prefer-const
100
96
  let ASYNCIFY_MEM;
101
97
  let ASYNCIFY_INITIALIZED = false;
102
98
  let fetchFn = null;
@@ -248,20 +244,14 @@ function instantiate(module, imports = {}) {
248
244
  const mod = new WebAssembly.Instance(module, adaptedImports);
249
245
  WASM_EXPORTS = mod.exports;
250
246
  // @ts-ignore
251
- // eslint-disable-next-line prefer-const
252
247
  WASM_MEMORY = WASM_EXPORTS.memory || adaptedImports.env.memory;
253
248
  ASYNCIFY_MEM = new Uint32Array(WASM_MEMORY.buffer);
254
249
  const handledExports = Object.setPrototypeOf({
255
250
  responseHandler(body, statusCode, redirected, callbackID) {
256
251
  if (!WASM_EXPORTS["responseHandler"])
257
252
  throw new Error("Unable to call .responseHandler on wasm module. Add the line export { responseHandler } from \"as-fetch/assembly\" to your entry file.");
258
- try {
259
- // @ts-ignore
260
- WASM_EXPORTS.responseHandler(__lowerBuffer(body), statusCode, redirected ? 1 : 0, callbackID);
261
- }
262
- catch (e) {
263
- console.error(e);
264
- }
253
+ // @ts-ignore
254
+ WASM_EXPORTS.responseHandler(__lowerBuffer(body), statusCode, redirected ? 1 : 0, callbackID);
265
255
  },
266
256
  initialize(config) {
267
257
  if (!WASM_EXPORTS["initialize"])
@@ -280,69 +270,46 @@ function instantiate(module, imports = {}) {
280
270
  return __awaiter(this, void 0, void 0, function* () {
281
271
  if (!WASM_EXPORTS["execute"])
282
272
  throw new Error("Unable to call .execute on wasm module. Are you sure this is a data connector?");
283
- try {
284
- const loweredArgs = new Array(params.length);
285
- for (let i = 0; i < params.length; i++) {
286
- loweredArgs[i] = __lower(params[i]);
287
- }
288
- let result = WASM_EXPORTS.execute(...loweredArgs);
289
- if (ASYNCIFY_INITIALIZED) {
273
+ const loweredArgs = new Array(params.length);
274
+ for (let i = 0; i < params.length; i++) {
275
+ loweredArgs[i] = __lower(params[i]);
276
+ }
277
+ let result = WASM_EXPORTS.execute(...loweredArgs);
278
+ if (ASYNCIFY_INITIALIZED) {
279
+ // @ts-ignore
280
+ while (WASM_EXPORTS.asyncify_get_state() === State.Unwinding) {
290
281
  // @ts-ignore
291
- while (WASM_EXPORTS.asyncify_get_state() === State.Unwinding) {
292
- // @ts-ignore
293
- WASM_EXPORTS.asyncify_stop_unwind();
294
- if (fetchFn)
295
- detachedValue = yield fetchFn();
296
- if (ccxtFn)
297
- detachedValue = yield ccxtFn();
298
- // @ts-ignore
299
- WASM_EXPORTS.asyncify_start_rewind(ASYNCIFY_PTR);
300
- result = WASM_EXPORTS.execute();
301
- }
282
+ WASM_EXPORTS.asyncify_stop_unwind();
283
+ if (fetchFn)
284
+ detachedValue = yield fetchFn();
285
+ if (ccxtFn)
286
+ detachedValue = yield ccxtFn();
287
+ // @ts-ignore
288
+ WASM_EXPORTS.asyncify_start_rewind(ASYNCIFY_PTR);
289
+ result = WASM_EXPORTS.execute();
302
290
  }
303
- if (fetchFn)
304
- fetchFn = null;
305
- if (ccxtFn)
306
- ccxtFn = null;
307
- // @ts-ignore
308
- return __liftString(result);
309
- }
310
- catch (e) {
311
- console.error(e);
312
- return null;
313
291
  }
292
+ if (fetchFn)
293
+ fetchFn = null;
294
+ if (ccxtFn)
295
+ ccxtFn = null;
296
+ // @ts-ignore
297
+ return __liftString(result);
314
298
  });
315
299
  },
316
300
  config() {
317
301
  if (!WASM_EXPORTS["config"])
318
302
  throw new Error("Unable to call .config on wasm module. Are you sure this is a data connector?");
319
- try {
320
- return __liftString(WASM_EXPORTS.config());
321
- }
322
- catch (e) {
323
- console.error(e);
324
- return null;
325
- }
303
+ return __liftString(WASM_EXPORTS.config());
326
304
  },
327
305
  transform() {
328
306
  if (!WASM_EXPORTS["transform"])
329
307
  throw new Error("Unable to call .transform on wasm module. Are you sure this is a data connector?");
330
- try {
331
- return __liftString(WASM_EXPORTS.transform());
332
- }
333
- catch (e) {
334
- console.error(e);
335
- return null;
336
- }
308
+ return __liftString(WASM_EXPORTS.transform());
337
309
  },
338
310
  reset() {
339
- try {
340
- if (WASM_EXPORTS["reset"])
341
- WASM_EXPORTS.reset();
342
- }
343
- catch (e) {
344
- console.error(e);
345
- }
311
+ if (WASM_EXPORTS["reset"])
312
+ WASM_EXPORTS.reset();
346
313
  }
347
314
  }, WASM_EXPORTS);
348
315
  WASM_DV = new DataView(WASM_MEMORY.buffer);
@@ -393,7 +360,6 @@ function instantiate(module, imports = {}) {
393
360
  new Uint8Array(WASM_MEMORY.buffer).set(new Uint8Array(value), ptr);
394
361
  return ptr;
395
362
  }
396
- // eslint-disable-next-line @typescript-eslint/ban-types
397
363
  function __liftArray(liftElement, align, ptr) {
398
364
  if (!ptr)
399
365
  return null;
@@ -404,7 +370,6 @@ function instantiate(module, imports = {}) {
404
370
  values[i] = liftElement(dataStart + (i << align >>> 0));
405
371
  return values;
406
372
  }
407
- // eslint-disable-next-line @typescript-eslint/ban-types
408
373
  function __lowerStaticArray(lowerElement, id, align, values, typedConstructor = null) {
409
374
  if (values == null)
410
375
  return 0;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@steerprotocol/app-loader",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "App Loader for Steer Protocol",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",