@steerprotocol/app-loader 1.0.0 → 1.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.
- package/lib/WasmModule.d.ts +3 -1
- package/lib/index.d.ts +9 -3
- package/lib/index.js +264 -303
- package/package.json +14 -13
package/lib/WasmModule.d.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
declare function responseHandler(body: ArrayBuffer, statusCode: number, redirected: number, callbackID: number): void;
|
|
2
2
|
declare function initialize(config: string): void;
|
|
3
3
|
declare function config(): string;
|
|
4
|
-
declare function version():
|
|
4
|
+
declare function version(): number;
|
|
5
5
|
declare function transform(): string;
|
|
6
6
|
declare function execute(...params: number[] | string[] | ArrayBuffer[] | null[]): string;
|
|
7
7
|
declare function __new(size: number, id: number): number;
|
|
8
8
|
declare function __pin(ptr: number): number;
|
|
9
9
|
declare function __unpin(ptr: number): number;
|
|
10
|
+
declare function reset(): void;
|
|
10
11
|
export type WasmModule = {
|
|
11
12
|
responseHandler: typeof responseHandler;
|
|
12
13
|
initialize: typeof initialize;
|
|
@@ -18,5 +19,6 @@ export type WasmModule = {
|
|
|
18
19
|
__new: typeof __new;
|
|
19
20
|
__pin: typeof __pin;
|
|
20
21
|
__unpin: typeof __unpin;
|
|
22
|
+
reset: typeof reset;
|
|
21
23
|
};
|
|
22
24
|
export {};
|
package/lib/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Candle } from
|
|
2
|
-
import { RawTradeData } from
|
|
3
|
-
import { WasmModule } from
|
|
1
|
+
import { Candle } from "./Candle";
|
|
2
|
+
import { RawTradeData } from "./RawTradeData";
|
|
3
|
+
import { WasmModule } from "./WasmModule";
|
|
4
4
|
export { Candle, RawTradeData, WasmModule };
|
|
5
5
|
/**
|
|
6
6
|
* Load a wasm bundle synchronously. Only accepts the actual binary data.
|
|
@@ -9,4 +9,10 @@ export { Candle, RawTradeData, WasmModule };
|
|
|
9
9
|
* @returns
|
|
10
10
|
*/
|
|
11
11
|
export declare function loadWasmSync(input: ArrayBuffer, imports?: {}): WasmModule;
|
|
12
|
+
/**
|
|
13
|
+
* Load a wasm bundle asynchronously. Accepts the actual binary data or file path.
|
|
14
|
+
* @param input - Wasm bundle data or path
|
|
15
|
+
* @param imports - Imports
|
|
16
|
+
* @returns
|
|
17
|
+
*/
|
|
12
18
|
export declare function loadWasm(input: string | ArrayBuffer, imports?: {}): Promise<WasmModule>;
|
package/lib/index.js
CHANGED
|
@@ -31,31 +31,24 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
31
31
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
32
|
});
|
|
33
33
|
};
|
|
34
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
35
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
36
|
-
};
|
|
37
34
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
35
|
exports.loadWasm = exports.loadWasmSync = exports.RawTradeData = exports.Candle = void 0;
|
|
36
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
39
37
|
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
|
40
|
-
|
|
38
|
+
//import ccxt from "ccxt";
|
|
41
39
|
const Candle_1 = require("./Candle");
|
|
42
40
|
Object.defineProperty(exports, "Candle", { enumerable: true, get: function () { return Candle_1.Candle; } });
|
|
43
41
|
const RawTradeData_1 = require("./RawTradeData");
|
|
44
42
|
Object.defineProperty(exports, "RawTradeData", { enumerable: true, get: function () { return RawTradeData_1.RawTradeData; } });
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
let WASM_DV;
|
|
55
|
-
// Constants required by Asyncify
|
|
56
|
-
let ASYNCIFY_PTR = 0;
|
|
57
|
-
let ASYNCIFY_MEM;
|
|
58
|
-
let ASYNCIFY_INITIALIZED = false;
|
|
43
|
+
let fetchImpl = null;
|
|
44
|
+
if (globalThis["fetch"])
|
|
45
|
+
fetchImpl = fetch;
|
|
46
|
+
var State;
|
|
47
|
+
(function (State) {
|
|
48
|
+
State[State["None"] = 0] = "None";
|
|
49
|
+
State[State["Unwinding"] = 1] = "Unwinding";
|
|
50
|
+
State[State["Rewinding"] = 2] = "Rewinding";
|
|
51
|
+
})(State || (State = {}));
|
|
59
52
|
/**
|
|
60
53
|
* Load a wasm bundle synchronously. Only accepts the actual binary data.
|
|
61
54
|
* @param input - Wasm bundle data
|
|
@@ -66,15 +59,27 @@ function loadWasmSync(input, imports = {}) {
|
|
|
66
59
|
return instantiate(new WebAssembly.Module(input), imports);
|
|
67
60
|
}
|
|
68
61
|
exports.loadWasmSync = loadWasmSync;
|
|
62
|
+
/**
|
|
63
|
+
* Load a wasm bundle asynchronously. Accepts the actual binary data or file path.
|
|
64
|
+
* @param input - Wasm bundle data or path
|
|
65
|
+
* @param imports - Imports
|
|
66
|
+
* @returns
|
|
67
|
+
*/
|
|
69
68
|
function loadWasm(input, imports = {}) {
|
|
70
69
|
return __awaiter(this, void 0, void 0, function* () {
|
|
71
70
|
const mod = instantiate(yield (() => __awaiter(this, void 0, void 0, function* () {
|
|
72
|
-
if (typeof input ===
|
|
71
|
+
if (typeof input === "string") {
|
|
73
72
|
try {
|
|
74
|
-
|
|
73
|
+
if (!globalThis["fetch"]) {
|
|
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
|
+
}
|
|
75
80
|
}
|
|
76
81
|
catch (_a) {
|
|
77
|
-
return WebAssembly.compile(yield (yield Promise.resolve().then(() => __importStar(require(
|
|
82
|
+
return WebAssembly.compile(yield (yield Promise.resolve().then(() => __importStar(require("fs/promises")))).readFile(input));
|
|
78
83
|
}
|
|
79
84
|
}
|
|
80
85
|
else {
|
|
@@ -86,6 +91,17 @@ function loadWasm(input, imports = {}) {
|
|
|
86
91
|
}
|
|
87
92
|
exports.loadWasm = loadWasm;
|
|
88
93
|
function instantiate(module, imports = {}) {
|
|
94
|
+
let WASM_MEMORY;
|
|
95
|
+
// eslint-disable-next-line prefer-const
|
|
96
|
+
let WASM_EXPORTS;
|
|
97
|
+
let WASM_DV;
|
|
98
|
+
let ASYNCIFY_PTR = 0;
|
|
99
|
+
// eslint-disable-next-line prefer-const
|
|
100
|
+
let ASYNCIFY_MEM;
|
|
101
|
+
let ASYNCIFY_INITIALIZED = false;
|
|
102
|
+
let fetchFn = null;
|
|
103
|
+
let ccxtFn = null;
|
|
104
|
+
let detachedValue = null;
|
|
89
105
|
const adaptedImports = Object.assign({
|
|
90
106
|
console: {
|
|
91
107
|
log(text) {
|
|
@@ -101,158 +117,115 @@ function instantiate(module, imports = {}) {
|
|
|
101
117
|
},
|
|
102
118
|
_initAsyncify(frame_ptr, stack_ptr) {
|
|
103
119
|
// @ts-ignore
|
|
104
|
-
if (!WASM_EXPORTS[
|
|
105
|
-
throw new Error(
|
|
120
|
+
if (!WASM_EXPORTS["asyncify_get_state"])
|
|
121
|
+
throw new Error("Asyncify initialized, but not enabled when run! Compile with the --runPasses asyncify flag or asyncify-shim transform!");
|
|
106
122
|
if (ASYNCIFY_INITIALIZED)
|
|
107
123
|
return;
|
|
108
124
|
ASYNCIFY_PTR = frame_ptr;
|
|
109
125
|
ASYNCIFY_MEM[ASYNCIFY_PTR >> 2] = ASYNCIFY_PTR + 8;
|
|
110
|
-
// I don't know if I need to reserve all this memory...
|
|
111
126
|
ASYNCIFY_MEM[(ASYNCIFY_PTR + 4) >> 2] = stack_ptr;
|
|
112
127
|
ASYNCIFY_INITIALIZED = true;
|
|
113
128
|
},
|
|
114
129
|
generateCandles(data, candleSize) {
|
|
115
|
-
const _data = __liftString(data) ||
|
|
116
|
-
const _candleSize = __liftString(candleSize) ||
|
|
130
|
+
const _data = __liftString(data) || "[]";
|
|
131
|
+
const _candleSize = __liftString(candleSize) || "69m";
|
|
117
132
|
const candles = (0, Candle_1.generateCandles)(JSON.parse(_data), _candleSize);
|
|
118
133
|
return __lowerString(JSON.stringify(candles));
|
|
119
134
|
},
|
|
120
|
-
|
|
135
|
+
"console.log": (text) => {
|
|
121
136
|
console.log(__liftString(text));
|
|
122
137
|
},
|
|
123
138
|
ccxt_fetchOHLCV: (exchangeId, symbol, timeframe, limit, since) => {
|
|
124
|
-
// Since may need to be passed as 64-bit?
|
|
125
|
-
// Timestamps are large
|
|
126
139
|
// @ts-ignore
|
|
127
140
|
const currentState = WASM_EXPORTS.asyncify_get_state();
|
|
128
|
-
if (currentState ===
|
|
129
|
-
//console.log("asyncify_stop_rewind() [resume wasm]");
|
|
141
|
+
if (currentState === State.Rewinding) {
|
|
130
142
|
// @ts-ignore
|
|
131
143
|
WASM_EXPORTS.asyncify_stop_rewind();
|
|
132
|
-
return _ohlcvPtr;
|
|
133
|
-
}
|
|
134
|
-
else if (currentState === 0) {
|
|
135
|
-
//console.log("asyncify_start_unwind() [pause wasm]");
|
|
136
144
|
// @ts-ignore
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
145
|
+
const ptr = __lowerStaticArray((pointer, value) => {
|
|
146
|
+
__setU32(pointer, __lowerStaticArray(__setF64, 7, 3, value, Float64Array));
|
|
147
|
+
}, 8, 2, detachedValue);
|
|
148
|
+
return ptr;
|
|
149
|
+
}
|
|
150
|
+
const _exchange = __liftString(exchangeId);
|
|
151
|
+
const _symbol = __liftString(symbol);
|
|
152
|
+
const _timeframe = __liftString(timeframe);
|
|
153
|
+
ccxtFn = (() => __awaiter(this, void 0, void 0, function* () {
|
|
142
154
|
if (!_exchange || !_symbol || !_timeframe)
|
|
143
|
-
throw new Error(
|
|
155
|
+
throw new Error("Exchange, Symbol, or Timeframe not provided when fetching OHCLV data.");
|
|
144
156
|
// @ts-ignore
|
|
145
|
-
new
|
|
146
|
-
apiKey:
|
|
147
|
-
secret:
|
|
148
|
-
})
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
// @ts-ignore: __new is defined
|
|
155
|
-
_ohlcvPtr = __lowerStaticArray((pointer, value) => {
|
|
156
|
-
__setU32(pointer, __lowerStaticArray(__setF64, 7, 3, value, Float64Array));
|
|
157
|
-
}, 8, 2, data);
|
|
158
|
-
//console.log("asyncify_start_rewind() [resuming wasm]");
|
|
159
|
-
// @ts-ignore
|
|
160
|
-
WASM_EXPORTS.asyncify_start_rewind(ASYNCIFY_PTR);
|
|
161
|
-
WASM_EXPORTS.execute();
|
|
162
|
-
});
|
|
163
|
-
}
|
|
164
|
-
},
|
|
157
|
+
const data = yield new ccxt[_exchange]({
|
|
158
|
+
apiKey: "",
|
|
159
|
+
secret: "",
|
|
160
|
+
}).fetchOHLCV(_symbol, _timeframe, since, limit);
|
|
161
|
+
return data;
|
|
162
|
+
}));
|
|
163
|
+
// @ts-ignore
|
|
164
|
+
WASM_EXPORTS.asyncify_start_unwind(ASYNCIFY_PTR);
|
|
165
|
+
}
|
|
165
166
|
},
|
|
166
|
-
|
|
167
|
+
"as-fetch": {
|
|
167
168
|
_initAsyncify(frame_ptr, stack_ptr) {
|
|
168
169
|
// @ts-ignore
|
|
169
|
-
if (!WASM_EXPORTS[
|
|
170
|
-
throw new Error(
|
|
170
|
+
if (!WASM_EXPORTS["asyncify_get_state"])
|
|
171
|
+
throw new Error("Asyncify initialized, but not enabled when run! Compile with the --runPasses asyncify flag or asyncify-shim transform!");
|
|
171
172
|
if (ASYNCIFY_INITIALIZED)
|
|
172
173
|
return;
|
|
173
174
|
ASYNCIFY_PTR = frame_ptr;
|
|
174
175
|
ASYNCIFY_MEM[ASYNCIFY_PTR >> 2] = ASYNCIFY_PTR + 8;
|
|
175
|
-
// I don
|
|
176
|
+
// I don"t know if I need to reserve all this memory...
|
|
176
177
|
ASYNCIFY_MEM[(ASYNCIFY_PTR + 4) >> 2] = stack_ptr;
|
|
177
178
|
ASYNCIFY_INITIALIZED = true;
|
|
178
179
|
},
|
|
179
180
|
_fetchPOSTSync(url, mode, headers, body) {
|
|
180
|
-
var _a;
|
|
181
181
|
// @ts-ignore
|
|
182
182
|
const currentState = WASM_EXPORTS.asyncify_get_state();
|
|
183
|
-
if (currentState ===
|
|
184
|
-
//console.log("asyncify_stop_rewind() [resume wasm]");
|
|
183
|
+
if (currentState === State.Rewinding) {
|
|
185
184
|
// @ts-ignore
|
|
186
185
|
WASM_EXPORTS.asyncify_stop_rewind();
|
|
187
|
-
const ptr =
|
|
188
|
-
|
|
186
|
+
const ptr = __lowerBuffer(detachedValue);
|
|
187
|
+
detachedValue = null;
|
|
189
188
|
return ptr;
|
|
190
189
|
}
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
fetch((_a = __liftString(url)) !== null && _a !== void 0 ? _a : '', {
|
|
196
|
-
method: 'POST',
|
|
197
|
-
mode: modeToString(mode) || 'cors',
|
|
190
|
+
fetchFn = (() => __awaiter(this, void 0, void 0, function* () {
|
|
191
|
+
const res = yield fetchImpl(__liftString(url) || "", {
|
|
192
|
+
method: "POST",
|
|
193
|
+
mode: modeToString(mode) || "cors",
|
|
198
194
|
headers: __liftArray((pointer) => __liftArray((pointer) => __liftString(__getU32(pointer)), 2, __getU32(pointer)), 2, headers) || [],
|
|
199
|
-
body: __liftBuffer(body)
|
|
200
|
-
})
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
_fetchPOSTSyncPtr = __lowerBuffer(value);
|
|
207
|
-
//wasm_exports.__new(value.byteLength, 1);
|
|
208
|
-
//new Uint8Array(wasm_exports.memory.buffer).set(new Uint8Array(value), _fetchPOSTSyncPtr);
|
|
209
|
-
//console.log("asyncify_start_rewind() [resuming wasm]");
|
|
210
|
-
// @ts-ignore
|
|
211
|
-
WASM_EXPORTS.asyncify_start_rewind(ASYNCIFY_PTR);
|
|
212
|
-
// @ts-ignore
|
|
213
|
-
// Set to your execute function that your fetch calls are in. I would go and create a _start func
|
|
214
|
-
WASM_EXPORTS.execute();
|
|
215
|
-
}));
|
|
216
|
-
}
|
|
195
|
+
body: __liftBuffer(body)
|
|
196
|
+
});
|
|
197
|
+
const value = yield res.arrayBuffer();
|
|
198
|
+
return value;
|
|
199
|
+
}));
|
|
200
|
+
// @ts-ignore
|
|
201
|
+
WASM_EXPORTS.asyncify_start_unwind(ASYNCIFY_PTR);
|
|
217
202
|
},
|
|
218
203
|
_fetchGETSync(url, mode, headers) {
|
|
219
204
|
// @ts-ignore
|
|
220
205
|
const currentState = WASM_EXPORTS.asyncify_get_state();
|
|
221
|
-
if (currentState ===
|
|
206
|
+
if (currentState === State.Rewinding) {
|
|
222
207
|
// @ts-ignore
|
|
223
|
-
//console.log("asyncify_stop_rewind() [resume wasm]");
|
|
224
208
|
WASM_EXPORTS.asyncify_stop_rewind();
|
|
225
|
-
const ptr =
|
|
226
|
-
|
|
209
|
+
const ptr = __lowerBuffer(detachedValue);
|
|
210
|
+
detachedValue = null;
|
|
227
211
|
return ptr;
|
|
228
212
|
}
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
fetch(__liftString(url) || '', {
|
|
234
|
-
method: 'GET',
|
|
235
|
-
mode: modeToString(mode) || 'cors',
|
|
213
|
+
fetchFn = (() => __awaiter(this, void 0, void 0, function* () {
|
|
214
|
+
const res = yield fetchImpl(__liftString(url) || "", {
|
|
215
|
+
method: "GET",
|
|
216
|
+
mode: modeToString(mode) || "cors",
|
|
236
217
|
headers: __liftArray((pointer) => __liftArray((pointer) => __liftString(__getU32(pointer)), 2, __getU32(pointer)), 2, headers) || [],
|
|
237
|
-
})
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
_fetchGETSyncPtr = __lowerBuffer(value);
|
|
244
|
-
// @ts-ignore
|
|
245
|
-
//console.log("asyncify_start_rewind() [resuming wasm]");
|
|
246
|
-
WASM_EXPORTS.asyncify_start_rewind(ASYNCIFY_PTR);
|
|
247
|
-
// @ts-ignore
|
|
248
|
-
WASM_EXPORTS.execute();
|
|
249
|
-
}));
|
|
250
|
-
}
|
|
218
|
+
});
|
|
219
|
+
const value = yield res.arrayBuffer();
|
|
220
|
+
return value;
|
|
221
|
+
}));
|
|
222
|
+
// @ts-ignore
|
|
223
|
+
WASM_EXPORTS.asyncify_start_unwind(ASYNCIFY_PTR);
|
|
251
224
|
},
|
|
252
225
|
_fetchGET(url, mode, headers, callbackID) {
|
|
253
|
-
|
|
254
|
-
method:
|
|
255
|
-
mode: modeToString(mode) ||
|
|
226
|
+
fetchImpl(__liftString(url) || "", {
|
|
227
|
+
method: "GET",
|
|
228
|
+
mode: modeToString(mode) || "cors",
|
|
256
229
|
headers: __liftArray((pointer) => __liftArray((pointer) => __liftString(__getU32(pointer)), 2, __getU32(pointer)), 2, headers) || [],
|
|
257
230
|
}).then((res) => __awaiter(this, void 0, void 0, function* () {
|
|
258
231
|
const body = yield res.arrayBuffer();
|
|
@@ -260,9 +233,9 @@ function instantiate(module, imports = {}) {
|
|
|
260
233
|
}));
|
|
261
234
|
},
|
|
262
235
|
_fetchPOST(url, mode, headers, body, callbackID) {
|
|
263
|
-
|
|
264
|
-
method:
|
|
265
|
-
mode: modeToString(mode) ||
|
|
236
|
+
fetchImpl(__liftString(url) || "", {
|
|
237
|
+
method: "POST",
|
|
238
|
+
mode: modeToString(mode) || "cors",
|
|
266
239
|
body: body,
|
|
267
240
|
headers: __liftArray((pointer) => __liftArray((pointer) => __liftString(__getU32(pointer)), 2, __getU32(pointer)), 2, headers) || [],
|
|
268
241
|
}).then((res) => __awaiter(this, void 0, void 0, function* () {
|
|
@@ -275,226 +248,214 @@ function instantiate(module, imports = {}) {
|
|
|
275
248
|
const mod = new WebAssembly.Instance(module, adaptedImports);
|
|
276
249
|
WASM_EXPORTS = mod.exports;
|
|
277
250
|
// @ts-ignore
|
|
251
|
+
// eslint-disable-next-line prefer-const
|
|
278
252
|
WASM_MEMORY = WASM_EXPORTS.memory || adaptedImports.env.memory;
|
|
279
253
|
ASYNCIFY_MEM = new Uint32Array(WASM_MEMORY.buffer);
|
|
280
254
|
const handledExports = Object.setPrototypeOf({
|
|
281
255
|
responseHandler(body, statusCode, redirected, callbackID) {
|
|
256
|
+
if (!WASM_EXPORTS["responseHandler"])
|
|
257
|
+
throw new Error("Unable to call .responseHandler on wasm module. Add the line export { responseHandler } from \"as-fetch/assembly\" to your entry file.");
|
|
282
258
|
try {
|
|
283
259
|
// @ts-ignore
|
|
284
260
|
WASM_EXPORTS.responseHandler(__lowerBuffer(body), statusCode, redirected ? 1 : 0, callbackID);
|
|
285
261
|
}
|
|
286
262
|
catch (e) {
|
|
287
263
|
console.error(e);
|
|
288
|
-
throw new Error('Unable to call .responseHandler on wasm module. Add the line export { responseHandler } from "as-fetch/assembly" to your entry file.');
|
|
289
264
|
}
|
|
290
265
|
},
|
|
291
266
|
initialize(config) {
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
loweredArgs[i] = __lowerRetained(params[i]);
|
|
267
|
+
if (!WASM_EXPORTS["initialize"])
|
|
268
|
+
throw new Error("Unable to call .initialize on wasm module. Are you sure this is a data connector?");
|
|
269
|
+
try {
|
|
270
|
+
// @ts-ignore
|
|
271
|
+
WASM_EXPORTS.initialize(__lowerString(config));
|
|
272
|
+
return true;
|
|
299
273
|
}
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
274
|
+
catch (e) {
|
|
275
|
+
console.error(e);
|
|
276
|
+
return false;
|
|
303
277
|
}
|
|
304
|
-
|
|
305
|
-
|
|
278
|
+
},
|
|
279
|
+
execute(...params) {
|
|
280
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
281
|
+
if (!WASM_EXPORTS["execute"])
|
|
282
|
+
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) {
|
|
290
|
+
// @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
|
+
}
|
|
302
|
+
}
|
|
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
|
+
}
|
|
314
|
+
});
|
|
306
315
|
},
|
|
307
316
|
config() {
|
|
308
|
-
|
|
317
|
+
if (!WASM_EXPORTS["config"])
|
|
318
|
+
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
|
+
}
|
|
309
326
|
},
|
|
310
327
|
transform() {
|
|
328
|
+
if (!WASM_EXPORTS["transform"])
|
|
329
|
+
throw new Error("Unable to call .transform on wasm module. Are you sure this is a data connector?");
|
|
311
330
|
try {
|
|
312
331
|
return __liftString(WASM_EXPORTS.transform());
|
|
313
332
|
}
|
|
314
333
|
catch (e) {
|
|
315
334
|
console.error(e);
|
|
316
|
-
|
|
335
|
+
return null;
|
|
317
336
|
}
|
|
318
337
|
},
|
|
338
|
+
reset() {
|
|
339
|
+
try {
|
|
340
|
+
if (WASM_EXPORTS["reset"])
|
|
341
|
+
WASM_EXPORTS.reset();
|
|
342
|
+
}
|
|
343
|
+
catch (e) {
|
|
344
|
+
console.error(e);
|
|
345
|
+
}
|
|
346
|
+
}
|
|
319
347
|
}, WASM_EXPORTS);
|
|
320
348
|
WASM_DV = new DataView(WASM_MEMORY.buffer);
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
349
|
+
function __lower(val) {
|
|
350
|
+
if (typeof val === "number") {
|
|
351
|
+
return val;
|
|
352
|
+
}
|
|
353
|
+
else if (typeof val === "string") {
|
|
354
|
+
return __lowerString(val);
|
|
355
|
+
}
|
|
356
|
+
else if (val instanceof ArrayBuffer) {
|
|
357
|
+
return __lowerBuffer(val);
|
|
358
|
+
}
|
|
359
|
+
else {
|
|
360
|
+
return 0;
|
|
361
|
+
}
|
|
331
362
|
}
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
const
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
throw Error(`invalid refcount '${refcount}' for reference '${ptr}'`);
|
|
363
|
+
function __liftString(ptr) {
|
|
364
|
+
if (!ptr)
|
|
365
|
+
return null;
|
|
366
|
+
const end = ptr + new Uint32Array(WASM_MEMORY.buffer)[ptr - 4 >>> 2] >>> 1;
|
|
367
|
+
const memoryU16 = new Uint16Array(WASM_MEMORY.buffer);
|
|
368
|
+
let start = ptr >>> 1;
|
|
369
|
+
let string = "";
|
|
370
|
+
while (end - start > 1024)
|
|
371
|
+
string += String.fromCharCode(...memoryU16.subarray(start, start += 1024));
|
|
372
|
+
return string + String.fromCharCode(...memoryU16.subarray(start, end));
|
|
343
373
|
}
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
374
|
+
function __lowerString(value) {
|
|
375
|
+
if (value == null)
|
|
376
|
+
return 0;
|
|
377
|
+
const length = value.length;
|
|
378
|
+
const ptr = WASM_EXPORTS.__pin(WASM_EXPORTS.__new(length << 1, 2) >>> 0);
|
|
379
|
+
const memoryU16 = new Uint16Array(WASM_MEMORY.buffer);
|
|
380
|
+
for (let i = 0; i < length; ++i)
|
|
381
|
+
memoryU16[(ptr >>> 1) + i] = value.charCodeAt(i);
|
|
382
|
+
return ptr;
|
|
348
383
|
}
|
|
349
|
-
|
|
350
|
-
|
|
384
|
+
function __liftBuffer(ptr) {
|
|
385
|
+
if (!ptr)
|
|
386
|
+
return null;
|
|
387
|
+
return WASM_MEMORY.buffer.slice(ptr, ptr + new Uint32Array(WASM_MEMORY.buffer)[ptr - 4 >>> 2]);
|
|
351
388
|
}
|
|
352
|
-
|
|
353
|
-
|
|
389
|
+
function __lowerBuffer(value) {
|
|
390
|
+
if (value == null)
|
|
391
|
+
return 0;
|
|
392
|
+
const ptr = WASM_EXPORTS.__pin(WASM_EXPORTS.__new(value.byteLength, 1) >>> 0);
|
|
393
|
+
new Uint8Array(WASM_MEMORY.buffer).set(new Uint8Array(value), ptr);
|
|
394
|
+
return ptr;
|
|
354
395
|
}
|
|
355
|
-
|
|
356
|
-
|
|
396
|
+
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
397
|
+
function __liftArray(liftElement, align, ptr) {
|
|
398
|
+
if (!ptr)
|
|
399
|
+
return null;
|
|
400
|
+
const dataStart = __getU32(ptr + 4);
|
|
401
|
+
const length = WASM_DV.getUint32(ptr + 12, true);
|
|
402
|
+
const values = new Array(length);
|
|
403
|
+
for (let i = 0; i < length; ++i)
|
|
404
|
+
values[i] = liftElement(dataStart + (i << align >>> 0));
|
|
405
|
+
return values;
|
|
357
406
|
}
|
|
358
|
-
|
|
359
|
-
function
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
return 0;
|
|
373
|
-
const length = str.length;
|
|
374
|
-
// @ts-ignore
|
|
375
|
-
const ptr = WASM_EXPORTS.__new(length << 1, STRING_ID);
|
|
376
|
-
__retain(ptr);
|
|
377
|
-
const memoryU16 = new Uint16Array(WASM_MEMORY.buffer);
|
|
378
|
-
for (let i = 0; i < length; ++i)
|
|
379
|
-
memoryU16[(ptr >>> 1) + i] = str.charCodeAt(i);
|
|
380
|
-
return ptr;
|
|
381
|
-
}
|
|
382
|
-
function __lowerStringRetained(str) {
|
|
383
|
-
if (str === null)
|
|
384
|
-
return 0;
|
|
385
|
-
const length = str.length;
|
|
386
|
-
// @ts-ignore
|
|
387
|
-
const ptr = WASM_EXPORTS.__new(length << 1, STRING_ID);
|
|
388
|
-
__retain(ptr);
|
|
389
|
-
const memoryU16 = new Uint16Array(WASM_MEMORY.buffer);
|
|
390
|
-
for (let i = 0; i < length; ++i)
|
|
391
|
-
memoryU16[(ptr >>> 1) + i] = str.charCodeAt(i);
|
|
392
|
-
return ptr;
|
|
393
|
-
}
|
|
394
|
-
function __liftArray(liftElement, align, ptr) {
|
|
395
|
-
if (!ptr)
|
|
396
|
-
return null;
|
|
397
|
-
let dataStart;
|
|
398
|
-
try {
|
|
399
|
-
dataStart = WASM_DV.getUint32(ptr + 4, true);
|
|
400
|
-
}
|
|
401
|
-
catch (_a) {
|
|
402
|
-
WASM_DV = new DataView(WASM_MEMORY.buffer);
|
|
403
|
-
dataStart = WASM_DV.getUint32(ptr + 4, true);
|
|
404
|
-
}
|
|
405
|
-
const length = WASM_DV.getUint32(ptr + 12, true);
|
|
406
|
-
const values = new Array(length);
|
|
407
|
-
for (let i = 0; i < length; ++i)
|
|
408
|
-
values[i] = liftElement(dataStart + ((i << align) >>> 0));
|
|
409
|
-
return values;
|
|
410
|
-
}
|
|
411
|
-
function __lowerArray(lowerElement, id, align, values) {
|
|
412
|
-
if (values == null)
|
|
413
|
-
return 0;
|
|
414
|
-
const length = values.length;
|
|
415
|
-
const buffer = WASM_EXPORTS.__pin(WASM_EXPORTS.__new(length << align, 1)) >>> 0;
|
|
416
|
-
const header = WASM_EXPORTS.__pin(WASM_EXPORTS.__new(16, id)) >>> 0;
|
|
417
|
-
WASM_DV.setUint32(header, buffer, true);
|
|
418
|
-
WASM_DV.setUint32(header + 4, buffer, true);
|
|
419
|
-
WASM_DV.setUint32(header + 8, length << align, true);
|
|
420
|
-
WASM_DV.setUint32(header + 12, length, true);
|
|
421
|
-
for (let i = 0; i < length; ++i)
|
|
422
|
-
lowerElement(buffer + ((i << align) >>> 0), values[i]);
|
|
423
|
-
WASM_EXPORTS.__unpin(buffer);
|
|
424
|
-
WASM_EXPORTS.__unpin(header);
|
|
425
|
-
return header;
|
|
426
|
-
}
|
|
427
|
-
function __liftBuffer(ptr) {
|
|
428
|
-
if (!ptr)
|
|
429
|
-
return null;
|
|
430
|
-
const len = new Uint32Array(WASM_MEMORY.buffer)[(ptr - 4) >>> 2];
|
|
431
|
-
return WASM_MEMORY.buffer.slice(ptr, ptr + len);
|
|
432
|
-
}
|
|
433
|
-
function __lowerBuffer(buf) {
|
|
434
|
-
if (buf == null)
|
|
435
|
-
return 0;
|
|
436
|
-
const ptr = WASM_EXPORTS.__new(buf.byteLength, ARRAYBUFFER_ID) >>> 0;
|
|
437
|
-
new Uint8Array(WASM_MEMORY.buffer).set(new Uint8Array(buf), ptr);
|
|
438
|
-
return ptr;
|
|
439
|
-
}
|
|
440
|
-
function __lowerBufferRetained(buf) {
|
|
441
|
-
if (buf == null)
|
|
442
|
-
return 0;
|
|
443
|
-
const ptr = WASM_EXPORTS.__new(buf.byteLength, ARRAYBUFFER_ID) >>> 0;
|
|
444
|
-
__retain(ptr);
|
|
445
|
-
new Uint8Array(WASM_MEMORY.buffer).set(new Uint8Array(buf), ptr);
|
|
446
|
-
return ptr;
|
|
447
|
-
}
|
|
448
|
-
function __lowerStaticArray(lowerElement, id, align, values, typedConstructor) {
|
|
449
|
-
if (values == null)
|
|
450
|
-
return 0;
|
|
451
|
-
const length = values.length;
|
|
452
|
-
const ptr = WASM_EXPORTS.__pin(WASM_EXPORTS.__new(length << align, id)) >>> 0;
|
|
453
|
-
if (typedConstructor) {
|
|
454
|
-
new typedConstructor(WASM_EXPORTS.memory.buffer, ptr, length).set(values);
|
|
455
|
-
}
|
|
456
|
-
else {
|
|
457
|
-
for (let i = 0; i < length; i++)
|
|
458
|
-
lowerElement(ptr + ((i << align) >>> 0), values[i]);
|
|
459
|
-
}
|
|
460
|
-
WASM_EXPORTS.__unpin(ptr);
|
|
461
|
-
return ptr;
|
|
462
|
-
}
|
|
463
|
-
function __setF64(ptr, val) {
|
|
464
|
-
try {
|
|
465
|
-
WASM_DV.setFloat64(ptr, val, true);
|
|
407
|
+
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
408
|
+
function __lowerStaticArray(lowerElement, id, align, values, typedConstructor = null) {
|
|
409
|
+
if (values == null)
|
|
410
|
+
return 0;
|
|
411
|
+
const length = values.length;
|
|
412
|
+
const buffer = WASM_EXPORTS.__pin(WASM_EXPORTS.__new(length << align, id)) >>> 0;
|
|
413
|
+
if (typedConstructor) {
|
|
414
|
+
new typedConstructor(WASM_MEMORY.buffer, buffer, length).set(values);
|
|
415
|
+
}
|
|
416
|
+
else {
|
|
417
|
+
for (let i = 0; i < length; i++)
|
|
418
|
+
lowerElement(buffer + (i << align >>> 0), values[i]);
|
|
419
|
+
}
|
|
420
|
+
return buffer;
|
|
466
421
|
}
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
422
|
+
function __setU32(ptr, value) {
|
|
423
|
+
try {
|
|
424
|
+
WASM_DV.setUint32(ptr, value, true);
|
|
425
|
+
}
|
|
426
|
+
catch (_a) {
|
|
427
|
+
WASM_DV = new DataView(WASM_MEMORY.buffer);
|
|
428
|
+
WASM_DV.setUint32(ptr, value, true);
|
|
429
|
+
}
|
|
470
430
|
}
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
431
|
+
function __setF64(ptr, value) {
|
|
432
|
+
try {
|
|
433
|
+
WASM_DV.setFloat64(ptr, value, true);
|
|
434
|
+
}
|
|
435
|
+
catch (_a) {
|
|
436
|
+
WASM_DV = new DataView(WASM_MEMORY.buffer);
|
|
437
|
+
WASM_DV.setFloat64(ptr, value, true);
|
|
438
|
+
}
|
|
479
439
|
}
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
440
|
+
function __getU32(ptr) {
|
|
441
|
+
try {
|
|
442
|
+
return WASM_DV.getUint32(ptr, true);
|
|
443
|
+
}
|
|
444
|
+
catch (_a) {
|
|
445
|
+
WASM_DV = new DataView(WASM_MEMORY.buffer);
|
|
446
|
+
return WASM_DV.getUint32(ptr, true);
|
|
447
|
+
}
|
|
488
448
|
}
|
|
449
|
+
return handledExports;
|
|
489
450
|
}
|
|
490
451
|
function modeToString(mode) {
|
|
491
452
|
if (mode == 1)
|
|
492
|
-
return
|
|
453
|
+
return "cors";
|
|
493
454
|
if (mode == 2)
|
|
494
|
-
return
|
|
455
|
+
return "no-cors";
|
|
495
456
|
if (mode == 3)
|
|
496
|
-
return
|
|
457
|
+
return "same-origin";
|
|
497
458
|
if (mode == 4)
|
|
498
|
-
return
|
|
459
|
+
return "navigate";
|
|
499
460
|
return null;
|
|
500
461
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@steerprotocol/app-loader",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "App Loader for Steer Protocol",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -31,22 +31,23 @@
|
|
|
31
31
|
},
|
|
32
32
|
"homepage": "https://github.com/hebertcisco/ts-npm-package-boilerplate#readme",
|
|
33
33
|
"devDependencies": {
|
|
34
|
-
"@types/jest": "29.
|
|
35
|
-
"@types/timestring": "^6.0.
|
|
36
|
-
"@typescript-eslint/eslint-plugin": "
|
|
37
|
-
"@typescript-eslint/parser": "
|
|
38
|
-
"eslint": "8.
|
|
39
|
-
"eslint-plugin-jest": "27.
|
|
40
|
-
"jest": "29.
|
|
41
|
-
"prettier": "
|
|
42
|
-
"ts-jest": "29.
|
|
43
|
-
"typescript": "
|
|
34
|
+
"@types/jest": "29.5.6",
|
|
35
|
+
"@types/timestring": "^6.0.4",
|
|
36
|
+
"@typescript-eslint/eslint-plugin": "6.8.0",
|
|
37
|
+
"@typescript-eslint/parser": "6.8.0",
|
|
38
|
+
"eslint": "8.51.0",
|
|
39
|
+
"eslint-plugin-jest": "27.4.2",
|
|
40
|
+
"jest": "29.7.0",
|
|
41
|
+
"prettier": "3.0.3",
|
|
42
|
+
"ts-jest": "29.1.1",
|
|
43
|
+
"typescript": "5.2.2"
|
|
44
44
|
},
|
|
45
45
|
"files": [
|
|
46
46
|
"lib/**/*"
|
|
47
47
|
],
|
|
48
48
|
"dependencies": {
|
|
49
|
-
"ccxt": "^4.
|
|
50
|
-
"timestring": "^7.0.0"
|
|
49
|
+
"ccxt": "^4.1.19",
|
|
50
|
+
"timestring": "^7.0.0",
|
|
51
|
+
"undici": "^5.26.4"
|
|
51
52
|
}
|
|
52
53
|
}
|