@steerprotocol/app-loader 2.1.1 → 3.0.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.
- package/README.md +137 -1
- package/lib/{WasmModule.d.ts → WasmModule-MhaHnYBX.d.mts} +21 -2
- package/lib/{esm/WasmModule.d.ts → WasmModule-MhaHnYBX.d.ts} +21 -2
- package/lib/browser.mjs +559 -0
- package/lib/browser.mjs.map +1 -0
- package/lib/index.cjs +623 -0
- package/lib/index.cjs.map +1 -0
- package/lib/index.d.mts +20 -0
- package/lib/index.d.ts +10 -8
- package/lib/index.mjs +600 -0
- package/lib/index.mjs.map +1 -0
- package/lib/node.cjs +607 -0
- package/lib/node.cjs.map +1 -0
- package/lib/node.d.mts +19 -0
- package/lib/node.d.ts +19 -0
- package/lib/node.mjs +567 -0
- package/lib/node.mjs.map +1 -0
- package/package.json +27 -13
- package/lib/Candle.d.ts +0 -14
- package/lib/Candle.js +0 -79
- package/lib/RawTradeData.d.ts +0 -6
- package/lib/RawTradeData.js +0 -11
- package/lib/WasmModule.js +0 -2
- package/lib/esm/Candle.d.ts +0 -14
- package/lib/esm/Candle.js +0 -75
- package/lib/esm/RawTradeData.d.ts +0 -6
- package/lib/esm/RawTradeData.js +0 -10
- package/lib/esm/WasmModule.js +0 -1
- package/lib/esm/index.d.ts +0 -18
- package/lib/esm/index.js +0 -397
- package/lib/esm/package.json +0 -1
- package/lib/esm/timestring.d.ts +0 -9
- package/lib/esm/timestring.js +0 -83
- package/lib/index.js +0 -439
- package/lib/timestring.d.ts +0 -9
- package/lib/timestring.js +0 -86
package/lib/node.cjs
ADDED
|
@@ -0,0 +1,607 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/node.ts
|
|
31
|
+
var node_exports = {};
|
|
32
|
+
__export(node_exports, {
|
|
33
|
+
Candle: () => Candle,
|
|
34
|
+
RawTradeData: () => RawTradeData,
|
|
35
|
+
loadWasm: () => loadWasm,
|
|
36
|
+
loadWasmSync: () => loadWasmSync
|
|
37
|
+
});
|
|
38
|
+
module.exports = __toCommonJS(node_exports);
|
|
39
|
+
|
|
40
|
+
// src/internal/instantiate.ts
|
|
41
|
+
var import_ethers = require("ethers");
|
|
42
|
+
|
|
43
|
+
// src/timestring.ts
|
|
44
|
+
var DEFAULT_OPTS = {
|
|
45
|
+
hoursPerDay: 24,
|
|
46
|
+
daysPerWeek: 7,
|
|
47
|
+
weeksPerMonth: 4,
|
|
48
|
+
monthsPerYear: 12,
|
|
49
|
+
daysPerYear: 365.25
|
|
50
|
+
};
|
|
51
|
+
var UNIT_MAP = {
|
|
52
|
+
ms: ["ms", "milli", "millisecond", "milliseconds"],
|
|
53
|
+
s: ["s", "sec", "secs", "second", "seconds"],
|
|
54
|
+
m: ["m", "min", "mins", "minute", "minutes"],
|
|
55
|
+
h: ["h", "hr", "hrs", "hour", "hours"],
|
|
56
|
+
d: ["d", "day", "days"],
|
|
57
|
+
w: ["w", "week", "weeks"],
|
|
58
|
+
mth: ["mon", "mth", "mths", "month", "months"],
|
|
59
|
+
y: ["y", "yr", "yrs", "year", "years"]
|
|
60
|
+
};
|
|
61
|
+
function parseTimestring(value, returnUnit, opts) {
|
|
62
|
+
const options = Object.assign({}, DEFAULT_OPTS, opts || {});
|
|
63
|
+
let strValue;
|
|
64
|
+
if (typeof value === "number") {
|
|
65
|
+
strValue = parseInt(value.toString()) + "ms";
|
|
66
|
+
} else if (value.match(/^[-+]?[0-9.]+$/g)) {
|
|
67
|
+
strValue = parseInt(value) + "ms";
|
|
68
|
+
} else {
|
|
69
|
+
strValue = value;
|
|
70
|
+
}
|
|
71
|
+
let totalSeconds = 0;
|
|
72
|
+
const unitValues = getUnitValues(options);
|
|
73
|
+
const groups = strValue.toLowerCase().replace(/[^.\w+-]+/g, "").match(/[-+]?[0-9.]+[a-z]+/g);
|
|
74
|
+
if (groups === null) {
|
|
75
|
+
throw new Error(`The value [${strValue}] could not be parsed by timestring`);
|
|
76
|
+
}
|
|
77
|
+
groups.forEach((group) => {
|
|
78
|
+
const valMatch = group.match(/[0-9.]+/g);
|
|
79
|
+
const unitMatch = group.match(/[a-z]+/g);
|
|
80
|
+
if (valMatch && unitMatch) {
|
|
81
|
+
const val = parseFloat(valMatch[0]);
|
|
82
|
+
const unit = unitMatch[0];
|
|
83
|
+
totalSeconds += getSeconds(val, unit, unitValues);
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
if (returnUnit) {
|
|
87
|
+
return convert(totalSeconds, returnUnit, unitValues);
|
|
88
|
+
}
|
|
89
|
+
return totalSeconds;
|
|
90
|
+
}
|
|
91
|
+
function getUnitValues(opts) {
|
|
92
|
+
const unitValues = {
|
|
93
|
+
ms: 1e-3,
|
|
94
|
+
s: 1,
|
|
95
|
+
m: 60,
|
|
96
|
+
h: 3600,
|
|
97
|
+
d: 0,
|
|
98
|
+
w: 0,
|
|
99
|
+
mth: 0,
|
|
100
|
+
y: 0
|
|
101
|
+
};
|
|
102
|
+
unitValues.d = opts.hoursPerDay * unitValues.h;
|
|
103
|
+
unitValues.w = opts.daysPerWeek * unitValues.d;
|
|
104
|
+
unitValues.mth = opts.daysPerYear / opts.monthsPerYear * unitValues.d;
|
|
105
|
+
unitValues.y = opts.daysPerYear * unitValues.d;
|
|
106
|
+
return unitValues;
|
|
107
|
+
}
|
|
108
|
+
function getUnitKey(unit) {
|
|
109
|
+
for (const key of Object.keys(UNIT_MAP)) {
|
|
110
|
+
if (UNIT_MAP[key].indexOf(unit) > -1) {
|
|
111
|
+
return key;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
throw new Error(`The unit [${unit}] is not supported by timestring`);
|
|
115
|
+
}
|
|
116
|
+
function getSeconds(value, unit, unitValues) {
|
|
117
|
+
return value * unitValues[getUnitKey(unit)];
|
|
118
|
+
}
|
|
119
|
+
function convert(value, unit, unitValues) {
|
|
120
|
+
return value / unitValues[getUnitKey(unit)];
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// src/Candle.ts
|
|
124
|
+
var Candle = class {
|
|
125
|
+
constructor(timestamp, high, low, open, close, volume) {
|
|
126
|
+
this.timestamp = timestamp;
|
|
127
|
+
this.high = high;
|
|
128
|
+
this.low = low;
|
|
129
|
+
this.open = open;
|
|
130
|
+
this.close = close;
|
|
131
|
+
this.volume = volume;
|
|
132
|
+
}
|
|
133
|
+
toString() {
|
|
134
|
+
return JSON.stringify(this);
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
function generateCandles(data, candleSize) {
|
|
138
|
+
const candleWidth = parseTimestring(candleSize, "ms", {});
|
|
139
|
+
if (data.length === 0) {
|
|
140
|
+
throw new Error("Input data is empty");
|
|
141
|
+
}
|
|
142
|
+
const _data = data.map((point) => {
|
|
143
|
+
return Object.assign(Object.assign({}, point), {
|
|
144
|
+
// This will convert the timestamp to milliseconds if it's in seconds
|
|
145
|
+
timestamp: point.timestamp && String(point.timestamp).length == 10 ? point.timestamp * 1e3 : point.timestamp
|
|
146
|
+
});
|
|
147
|
+
});
|
|
148
|
+
if (_data[0] === void 0 || Object.keys(_data[0]).length === 0) {
|
|
149
|
+
return [];
|
|
150
|
+
}
|
|
151
|
+
const ohlcvData = [];
|
|
152
|
+
let i = 0;
|
|
153
|
+
let currentTimestamp = Math.floor(_data[0].timestamp / candleWidth) * candleWidth;
|
|
154
|
+
let open = _data[0].price;
|
|
155
|
+
let high = _data[0].price;
|
|
156
|
+
let low = _data[0].price;
|
|
157
|
+
let close = _data[0].price;
|
|
158
|
+
let volume = 0;
|
|
159
|
+
while (i < _data.length) {
|
|
160
|
+
open = close;
|
|
161
|
+
high = close;
|
|
162
|
+
low = close;
|
|
163
|
+
volume = 0;
|
|
164
|
+
let innerI = i;
|
|
165
|
+
while (innerI < _data.length && _data[innerI].timestamp < currentTimestamp + candleWidth) {
|
|
166
|
+
open = innerI === 0 ? _data[innerI].price : open;
|
|
167
|
+
high = Math.max(high, _data[innerI].price);
|
|
168
|
+
low = Math.min(low, _data[innerI].price);
|
|
169
|
+
close = _data[innerI].price;
|
|
170
|
+
volume += _data[innerI].volume;
|
|
171
|
+
innerI++;
|
|
172
|
+
}
|
|
173
|
+
ohlcvData.push({
|
|
174
|
+
timestamp: currentTimestamp,
|
|
175
|
+
high,
|
|
176
|
+
low,
|
|
177
|
+
open,
|
|
178
|
+
close,
|
|
179
|
+
volume
|
|
180
|
+
});
|
|
181
|
+
currentTimestamp += candleWidth;
|
|
182
|
+
i = innerI;
|
|
183
|
+
}
|
|
184
|
+
return ohlcvData;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// src/RawTradeData.ts
|
|
188
|
+
var RawTradeData = class {
|
|
189
|
+
constructor(timestamp, price, volume) {
|
|
190
|
+
this.timestamp = timestamp;
|
|
191
|
+
this.price = price;
|
|
192
|
+
this.volume = volume;
|
|
193
|
+
}
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
// src/internal/instantiate.ts
|
|
197
|
+
function instantiate(module2, imports = {}, runtime = {}) {
|
|
198
|
+
let WASM_MEMORY;
|
|
199
|
+
let WASM_EXPORTS;
|
|
200
|
+
let WASM_DV;
|
|
201
|
+
let ASYNCIFY_PTR = 0;
|
|
202
|
+
let ASYNCIFY_MEM;
|
|
203
|
+
let ASYNCIFY_INITIALIZED = false;
|
|
204
|
+
let fetchFn = null;
|
|
205
|
+
let ccxtFn = null;
|
|
206
|
+
let detachedValue = null;
|
|
207
|
+
const adaptedImports = Object.assign(
|
|
208
|
+
{
|
|
209
|
+
console: {
|
|
210
|
+
log(text) {
|
|
211
|
+
console.log(__liftString(text));
|
|
212
|
+
}
|
|
213
|
+
},
|
|
214
|
+
ethers: {
|
|
215
|
+
keccak256_str(str_ptr) {
|
|
216
|
+
const str = __liftString(str_ptr);
|
|
217
|
+
const hash = import_ethers.ethers.keccak256(str);
|
|
218
|
+
return __lowerString(hash);
|
|
219
|
+
},
|
|
220
|
+
keccak256_buf(buf_ptr) {
|
|
221
|
+
const buf = __liftBuffer(buf_ptr);
|
|
222
|
+
const hash = import_ethers.ethers.keccak256(new Uint8Array(buf));
|
|
223
|
+
return __lowerString(hash);
|
|
224
|
+
}
|
|
225
|
+
},
|
|
226
|
+
// @ts-ignore
|
|
227
|
+
env: {
|
|
228
|
+
abort(message, fileName, lineNumber, columnNumber) {
|
|
229
|
+
(() => {
|
|
230
|
+
throw Error(`${__liftString(message)} in ${__liftString(fileName)}:${lineNumber}:${columnNumber}`);
|
|
231
|
+
})();
|
|
232
|
+
},
|
|
233
|
+
_initAsyncify(frame_ptr, stack_ptr) {
|
|
234
|
+
if (!WASM_EXPORTS["asyncify_get_state"])
|
|
235
|
+
throw new Error(
|
|
236
|
+
"Asyncify initialized, but not enabled when run! Compile with the --runPasses asyncify flag or asyncify-shim transform!"
|
|
237
|
+
);
|
|
238
|
+
if (ASYNCIFY_INITIALIZED) return;
|
|
239
|
+
ASYNCIFY_PTR = frame_ptr;
|
|
240
|
+
ASYNCIFY_MEM[ASYNCIFY_PTR >> 2] = ASYNCIFY_PTR + 8;
|
|
241
|
+
ASYNCIFY_MEM[ASYNCIFY_PTR + 4 >> 2] = stack_ptr;
|
|
242
|
+
ASYNCIFY_INITIALIZED = true;
|
|
243
|
+
},
|
|
244
|
+
generateCandles(data, candleSize) {
|
|
245
|
+
const _data = __liftString(data) || "[]";
|
|
246
|
+
const _candleSize = __liftString(candleSize) || "69m";
|
|
247
|
+
const candles = generateCandles(JSON.parse(_data), _candleSize);
|
|
248
|
+
return __lowerString(JSON.stringify(candles));
|
|
249
|
+
},
|
|
250
|
+
"console.log": (text) => {
|
|
251
|
+
console.log(__liftString(text));
|
|
252
|
+
},
|
|
253
|
+
ccxt_fetchOHLCV: (exchangeId, symbol, timeframe, limit, since) => {
|
|
254
|
+
const currentState = WASM_EXPORTS.asyncify_get_state();
|
|
255
|
+
if (currentState === 2 /* Rewinding */) {
|
|
256
|
+
WASM_EXPORTS.asyncify_stop_rewind();
|
|
257
|
+
const ptr = __lowerStaticArray(
|
|
258
|
+
(pointer, value) => {
|
|
259
|
+
__setU32(pointer, __lowerStaticArray(__setF64, 7, 3, value, Float64Array));
|
|
260
|
+
},
|
|
261
|
+
8,
|
|
262
|
+
2,
|
|
263
|
+
detachedValue
|
|
264
|
+
);
|
|
265
|
+
return ptr;
|
|
266
|
+
}
|
|
267
|
+
const _exchange = __liftString(exchangeId);
|
|
268
|
+
const _symbol = __liftString(symbol);
|
|
269
|
+
const _timeframe = __liftString(timeframe);
|
|
270
|
+
ccxtFn = async () => {
|
|
271
|
+
if (!_exchange || !_symbol || !_timeframe)
|
|
272
|
+
throw new Error("Exchange, Symbol, or Timeframe not provided when fetching OHCLV data.");
|
|
273
|
+
const ccxt = await getCcxtOrThrow(runtime);
|
|
274
|
+
const data = await new ccxt[_exchange]({
|
|
275
|
+
apiKey: "",
|
|
276
|
+
secret: ""
|
|
277
|
+
}).fetchOHLCV(_symbol, _timeframe, since, limit);
|
|
278
|
+
return data;
|
|
279
|
+
};
|
|
280
|
+
WASM_EXPORTS.asyncify_start_unwind(ASYNCIFY_PTR);
|
|
281
|
+
}
|
|
282
|
+
},
|
|
283
|
+
"as-fetch": {
|
|
284
|
+
_initAsyncify(frame_ptr, stack_ptr) {
|
|
285
|
+
if (!WASM_EXPORTS["asyncify_get_state"])
|
|
286
|
+
throw new Error(
|
|
287
|
+
"Asyncify initialized, but not enabled when run! Compile with the --runPasses asyncify flag or asyncify-shim transform!"
|
|
288
|
+
);
|
|
289
|
+
if (ASYNCIFY_INITIALIZED) return;
|
|
290
|
+
ASYNCIFY_PTR = frame_ptr;
|
|
291
|
+
ASYNCIFY_MEM[ASYNCIFY_PTR >> 2] = ASYNCIFY_PTR + 8;
|
|
292
|
+
ASYNCIFY_MEM[ASYNCIFY_PTR + 4 >> 2] = stack_ptr;
|
|
293
|
+
ASYNCIFY_INITIALIZED = true;
|
|
294
|
+
},
|
|
295
|
+
_fetchPOSTSync(url, mode, headers, body) {
|
|
296
|
+
const currentState = WASM_EXPORTS.asyncify_get_state();
|
|
297
|
+
if (currentState === 2 /* Rewinding */) {
|
|
298
|
+
WASM_EXPORTS.asyncify_stop_rewind();
|
|
299
|
+
const ptr = __lowerBuffer(detachedValue);
|
|
300
|
+
detachedValue = null;
|
|
301
|
+
return ptr;
|
|
302
|
+
}
|
|
303
|
+
fetchFn = async () => {
|
|
304
|
+
const fetchImpl = await getFetchOrThrow(runtime);
|
|
305
|
+
const res = await fetchImpl(__liftString(url) || "", {
|
|
306
|
+
method: "POST",
|
|
307
|
+
mode: modeToString(mode) || "cors",
|
|
308
|
+
headers: __liftArray(
|
|
309
|
+
(pointer) => __liftArray((pointer2) => __liftString(__getU32(pointer2)), 2, __getU32(pointer)),
|
|
310
|
+
2,
|
|
311
|
+
headers
|
|
312
|
+
) || [],
|
|
313
|
+
body: __liftBuffer(body)
|
|
314
|
+
});
|
|
315
|
+
const value = await res.arrayBuffer();
|
|
316
|
+
return value;
|
|
317
|
+
};
|
|
318
|
+
WASM_EXPORTS.asyncify_start_unwind(ASYNCIFY_PTR);
|
|
319
|
+
},
|
|
320
|
+
_fetchGETSync(url, mode, headers) {
|
|
321
|
+
const currentState = WASM_EXPORTS.asyncify_get_state();
|
|
322
|
+
if (currentState === 2 /* Rewinding */) {
|
|
323
|
+
WASM_EXPORTS.asyncify_stop_rewind();
|
|
324
|
+
const ptr = __lowerBuffer(detachedValue);
|
|
325
|
+
detachedValue = null;
|
|
326
|
+
return ptr;
|
|
327
|
+
}
|
|
328
|
+
fetchFn = async () => {
|
|
329
|
+
const fetchImpl = await getFetchOrThrow(runtime);
|
|
330
|
+
const res = await fetchImpl(__liftString(url) || "", {
|
|
331
|
+
method: "GET",
|
|
332
|
+
mode: modeToString(mode) || "cors",
|
|
333
|
+
headers: __liftArray(
|
|
334
|
+
(pointer) => __liftArray((pointer2) => __liftString(__getU32(pointer2)), 2, __getU32(pointer)),
|
|
335
|
+
2,
|
|
336
|
+
headers
|
|
337
|
+
) || []
|
|
338
|
+
});
|
|
339
|
+
const value = await res.arrayBuffer();
|
|
340
|
+
return value;
|
|
341
|
+
};
|
|
342
|
+
WASM_EXPORTS.asyncify_start_unwind(ASYNCIFY_PTR);
|
|
343
|
+
},
|
|
344
|
+
_fetchGET(url, mode, headers, callbackID) {
|
|
345
|
+
void (async () => {
|
|
346
|
+
const fetchImpl = await getFetchOrThrow(runtime);
|
|
347
|
+
const res = await fetchImpl(__liftString(url) || "", {
|
|
348
|
+
method: "GET",
|
|
349
|
+
mode: modeToString(mode) || "cors",
|
|
350
|
+
headers: __liftArray(
|
|
351
|
+
(pointer) => __liftArray((pointer2) => __liftString(__getU32(pointer2)), 2, __getU32(pointer)),
|
|
352
|
+
2,
|
|
353
|
+
headers
|
|
354
|
+
) || []
|
|
355
|
+
});
|
|
356
|
+
const body = await res.arrayBuffer();
|
|
357
|
+
WASM_EXPORTS.responseHandler(body, res.status, res.redirected ? 1 : 0, callbackID);
|
|
358
|
+
})();
|
|
359
|
+
},
|
|
360
|
+
_fetchPOST(url, mode, headers, body, callbackID) {
|
|
361
|
+
void (async () => {
|
|
362
|
+
const fetchImpl = await getFetchOrThrow(runtime);
|
|
363
|
+
const res = await fetchImpl(__liftString(url) || "", {
|
|
364
|
+
method: "POST",
|
|
365
|
+
mode: modeToString(mode) || "cors",
|
|
366
|
+
body,
|
|
367
|
+
headers: __liftArray(
|
|
368
|
+
(pointer) => __liftArray((pointer2) => __liftString(__getU32(pointer2)), 2, __getU32(pointer)),
|
|
369
|
+
2,
|
|
370
|
+
headers
|
|
371
|
+
) || []
|
|
372
|
+
});
|
|
373
|
+
const responseBody = await res.arrayBuffer();
|
|
374
|
+
WASM_EXPORTS.responseHandler(responseBody, res.status, res.redirected ? 1 : 0, callbackID);
|
|
375
|
+
})();
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
},
|
|
379
|
+
imports
|
|
380
|
+
);
|
|
381
|
+
const mod = new WebAssembly.Instance(module2, adaptedImports);
|
|
382
|
+
WASM_EXPORTS = mod.exports;
|
|
383
|
+
WASM_MEMORY = WASM_EXPORTS.memory || adaptedImports.env.memory;
|
|
384
|
+
ASYNCIFY_MEM = new Uint32Array(WASM_MEMORY.buffer);
|
|
385
|
+
const handledExports = Object.setPrototypeOf(
|
|
386
|
+
{
|
|
387
|
+
responseHandler(body, statusCode, redirected, callbackID) {
|
|
388
|
+
if (!WASM_EXPORTS["responseHandler"])
|
|
389
|
+
throw new Error(
|
|
390
|
+
'Unable to call .responseHandler on wasm module. Add the line export { responseHandler } from "as-fetch/assembly" to your entry file.'
|
|
391
|
+
);
|
|
392
|
+
WASM_EXPORTS.responseHandler(__lowerBuffer(body), statusCode, redirected ? 1 : 0, callbackID);
|
|
393
|
+
},
|
|
394
|
+
initialize(config) {
|
|
395
|
+
if (!WASM_EXPORTS["initialize"])
|
|
396
|
+
throw new Error("Unable to call .initialize on wasm module. Are you sure this is a data connector?");
|
|
397
|
+
try {
|
|
398
|
+
WASM_EXPORTS.initialize(__lowerString(config));
|
|
399
|
+
return true;
|
|
400
|
+
} catch (e) {
|
|
401
|
+
console.error(e);
|
|
402
|
+
return false;
|
|
403
|
+
}
|
|
404
|
+
},
|
|
405
|
+
async execute(...params) {
|
|
406
|
+
if (!WASM_EXPORTS["execute"])
|
|
407
|
+
throw new Error("Unable to call .execute on wasm module. Are you sure this is a data connector?");
|
|
408
|
+
const loweredArgs = new Array(params.length);
|
|
409
|
+
for (let i = 0; i < params.length; i++) {
|
|
410
|
+
loweredArgs[i] = __lower(params[i]);
|
|
411
|
+
}
|
|
412
|
+
let result;
|
|
413
|
+
try {
|
|
414
|
+
result = WASM_EXPORTS.execute(...loweredArgs);
|
|
415
|
+
} catch (error) {
|
|
416
|
+
if (params.length !== 0) {
|
|
417
|
+
throw error;
|
|
418
|
+
}
|
|
419
|
+
result = WASM_EXPORTS.execute(__lowerString(""));
|
|
420
|
+
}
|
|
421
|
+
if (ASYNCIFY_INITIALIZED) {
|
|
422
|
+
while (WASM_EXPORTS.asyncify_get_state() === 1 /* Unwinding */) {
|
|
423
|
+
WASM_EXPORTS.asyncify_stop_unwind();
|
|
424
|
+
if (fetchFn) detachedValue = await fetchFn();
|
|
425
|
+
if (ccxtFn) detachedValue = await ccxtFn();
|
|
426
|
+
WASM_EXPORTS.asyncify_start_rewind(ASYNCIFY_PTR);
|
|
427
|
+
result = WASM_EXPORTS.execute();
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
if (fetchFn) fetchFn = null;
|
|
431
|
+
if (ccxtFn) ccxtFn = null;
|
|
432
|
+
return __liftString(result);
|
|
433
|
+
},
|
|
434
|
+
config() {
|
|
435
|
+
if (!WASM_EXPORTS["config"])
|
|
436
|
+
throw new Error("Unable to call .config on wasm module. Are you sure this is a data connector?");
|
|
437
|
+
return __liftString(WASM_EXPORTS.config());
|
|
438
|
+
},
|
|
439
|
+
transform() {
|
|
440
|
+
if (!WASM_EXPORTS["transform"])
|
|
441
|
+
throw new Error("Unable to call .transform on wasm module. Are you sure this is a data connector?");
|
|
442
|
+
return __liftString(WASM_EXPORTS.transform());
|
|
443
|
+
},
|
|
444
|
+
reset() {
|
|
445
|
+
if (WASM_EXPORTS["reset"]) WASM_EXPORTS.reset();
|
|
446
|
+
}
|
|
447
|
+
},
|
|
448
|
+
WASM_EXPORTS
|
|
449
|
+
);
|
|
450
|
+
WASM_DV = new DataView(WASM_MEMORY.buffer);
|
|
451
|
+
function __lower(val) {
|
|
452
|
+
if (typeof val === "number") {
|
|
453
|
+
return val;
|
|
454
|
+
} else if (typeof val === "string") {
|
|
455
|
+
return __lowerString(val);
|
|
456
|
+
} else if (val instanceof ArrayBuffer) {
|
|
457
|
+
return __lowerBuffer(val);
|
|
458
|
+
} else {
|
|
459
|
+
return 0;
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
function __liftString(ptr) {
|
|
463
|
+
if (!ptr) return null;
|
|
464
|
+
const end = ptr + new Uint32Array(WASM_MEMORY.buffer)[ptr - 4 >>> 2] >>> 1;
|
|
465
|
+
const memoryU16 = new Uint16Array(WASM_MEMORY.buffer);
|
|
466
|
+
let start = ptr >>> 1;
|
|
467
|
+
let string = "";
|
|
468
|
+
while (end - start > 1024) string += String.fromCharCode(...memoryU16.subarray(start, start += 1024));
|
|
469
|
+
return string + String.fromCharCode(...memoryU16.subarray(start, end));
|
|
470
|
+
}
|
|
471
|
+
function __lowerString(value) {
|
|
472
|
+
if (value == null) return 0;
|
|
473
|
+
const length = value.length;
|
|
474
|
+
const ptr = WASM_EXPORTS.__pin(WASM_EXPORTS.__new(length << 1, 2) >>> 0);
|
|
475
|
+
const memoryU16 = new Uint16Array(WASM_MEMORY.buffer);
|
|
476
|
+
for (let i = 0; i < length; ++i) memoryU16[(ptr >>> 1) + i] = value.charCodeAt(i);
|
|
477
|
+
return ptr;
|
|
478
|
+
}
|
|
479
|
+
function __liftBuffer(ptr) {
|
|
480
|
+
if (!ptr) return null;
|
|
481
|
+
return WASM_MEMORY.buffer.slice(ptr, ptr + new Uint32Array(WASM_MEMORY.buffer)[ptr - 4 >>> 2]);
|
|
482
|
+
}
|
|
483
|
+
function __lowerBuffer(value) {
|
|
484
|
+
if (value == null) return 0;
|
|
485
|
+
const ptr = WASM_EXPORTS.__pin(WASM_EXPORTS.__new(value.byteLength, 1) >>> 0);
|
|
486
|
+
new Uint8Array(WASM_MEMORY.buffer).set(new Uint8Array(value), ptr);
|
|
487
|
+
return ptr;
|
|
488
|
+
}
|
|
489
|
+
function __liftArray(liftElement, align, ptr) {
|
|
490
|
+
if (!ptr) return null;
|
|
491
|
+
const dataStart = __getU32(ptr + 4);
|
|
492
|
+
const length = WASM_DV.getUint32(ptr + 12, true);
|
|
493
|
+
const values = new Array(length);
|
|
494
|
+
for (let i = 0; i < length; ++i) values[i] = liftElement(dataStart + (i << align >>> 0));
|
|
495
|
+
return values;
|
|
496
|
+
}
|
|
497
|
+
function __lowerStaticArray(lowerElement, id, align, values, typedConstructor = null) {
|
|
498
|
+
if (values == null) return 0;
|
|
499
|
+
const length = values.length;
|
|
500
|
+
const buffer = WASM_EXPORTS.__pin(WASM_EXPORTS.__new(length << align, id)) >>> 0;
|
|
501
|
+
if (typedConstructor) {
|
|
502
|
+
new typedConstructor(WASM_MEMORY.buffer, buffer, length).set(values);
|
|
503
|
+
} else {
|
|
504
|
+
for (let i = 0; i < length; i++) lowerElement(buffer + (i << align >>> 0), values[i]);
|
|
505
|
+
}
|
|
506
|
+
return buffer;
|
|
507
|
+
}
|
|
508
|
+
function __setU32(ptr, value) {
|
|
509
|
+
try {
|
|
510
|
+
WASM_DV.setUint32(ptr, value, true);
|
|
511
|
+
} catch {
|
|
512
|
+
WASM_DV = new DataView(WASM_MEMORY.buffer);
|
|
513
|
+
WASM_DV.setUint32(ptr, value, true);
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
function __setF64(ptr, value) {
|
|
517
|
+
try {
|
|
518
|
+
WASM_DV.setFloat64(ptr, value, true);
|
|
519
|
+
} catch {
|
|
520
|
+
WASM_DV = new DataView(WASM_MEMORY.buffer);
|
|
521
|
+
WASM_DV.setFloat64(ptr, value, true);
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
function __getU32(ptr) {
|
|
525
|
+
try {
|
|
526
|
+
return WASM_DV.getUint32(ptr, true);
|
|
527
|
+
} catch {
|
|
528
|
+
WASM_DV = new DataView(WASM_MEMORY.buffer);
|
|
529
|
+
return WASM_DV.getUint32(ptr, true);
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
return handledExports;
|
|
533
|
+
}
|
|
534
|
+
async function getFetchOrThrow(runtime) {
|
|
535
|
+
if (!runtime.getFetch) {
|
|
536
|
+
throw new Error("Fetch is not available in this runtime.");
|
|
537
|
+
}
|
|
538
|
+
return runtime.getFetch();
|
|
539
|
+
}
|
|
540
|
+
async function getCcxtOrThrow(runtime) {
|
|
541
|
+
if (!runtime.getCcxt) {
|
|
542
|
+
throw new Error("ccxt is not available in this runtime.");
|
|
543
|
+
}
|
|
544
|
+
return runtime.getCcxt();
|
|
545
|
+
}
|
|
546
|
+
function modeToString(mode) {
|
|
547
|
+
if (mode == 1) return "cors";
|
|
548
|
+
if (mode == 2) return "no-cors";
|
|
549
|
+
if (mode == 3) return "same-origin";
|
|
550
|
+
if (mode == 4) return "navigate";
|
|
551
|
+
return null;
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
// src/node.ts
|
|
555
|
+
function loadWasmSync(input, imports = {}) {
|
|
556
|
+
return instantiate(new WebAssembly.Module(input), imports, {
|
|
557
|
+
getFetch: getNodeFetch,
|
|
558
|
+
getCcxt
|
|
559
|
+
});
|
|
560
|
+
}
|
|
561
|
+
async function loadWasm(input, imports = {}) {
|
|
562
|
+
const module2 = typeof input === "string" ? await compileFromString(input) : await WebAssembly.compile(input);
|
|
563
|
+
return instantiate(module2, imports, {
|
|
564
|
+
getFetch: getNodeFetch,
|
|
565
|
+
getCcxt
|
|
566
|
+
});
|
|
567
|
+
}
|
|
568
|
+
async function compileFromString(input) {
|
|
569
|
+
if (isHttpUrl(input)) {
|
|
570
|
+
const fetchImpl = await getNodeFetch();
|
|
571
|
+
const response = await fetchImpl(input);
|
|
572
|
+
if (typeof WebAssembly.compileStreaming === "function") {
|
|
573
|
+
try {
|
|
574
|
+
return await WebAssembly.compileStreaming(Promise.resolve(response.clone()));
|
|
575
|
+
} catch {
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
return WebAssembly.compile(await response.arrayBuffer());
|
|
579
|
+
}
|
|
580
|
+
const fs = await import("fs/promises");
|
|
581
|
+
return WebAssembly.compile(await fs.readFile(input));
|
|
582
|
+
}
|
|
583
|
+
async function getNodeFetch() {
|
|
584
|
+
if (typeof globalThis.fetch === "function") {
|
|
585
|
+
return globalThis.fetch.bind(globalThis);
|
|
586
|
+
}
|
|
587
|
+
throw new Error("Fetch is not available in this Node runtime. Node 18+ is required.");
|
|
588
|
+
}
|
|
589
|
+
async function getCcxt() {
|
|
590
|
+
return (await import("ccxt")).default;
|
|
591
|
+
}
|
|
592
|
+
function isHttpUrl(value) {
|
|
593
|
+
try {
|
|
594
|
+
const url = new URL(value);
|
|
595
|
+
return url.protocol === "http:" || url.protocol === "https:";
|
|
596
|
+
} catch {
|
|
597
|
+
return false;
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
601
|
+
0 && (module.exports = {
|
|
602
|
+
Candle,
|
|
603
|
+
RawTradeData,
|
|
604
|
+
loadWasm,
|
|
605
|
+
loadWasmSync
|
|
606
|
+
});
|
|
607
|
+
//# sourceMappingURL=node.cjs.map
|