@steerprotocol/app-loader 2.1.0 → 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/lib/index.js DELETED
@@ -1,439 +0,0 @@
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
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
- return new (P || (P = Promise))(function (resolve, reject) {
28
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
- step((generator = generator.apply(thisArg, _arguments || [])).next());
32
- });
33
- };
34
- Object.defineProperty(exports, "__esModule", { value: true });
35
- exports.loadWasm = exports.loadWasmSync = exports.RawTradeData = exports.Candle = void 0;
36
- const ethers_1 = require("ethers");
37
- const Candle_1 = require("./Candle");
38
- Object.defineProperty(exports, "Candle", { enumerable: true, get: function () { return Candle_1.Candle; } });
39
- const RawTradeData_1 = require("./RawTradeData");
40
- Object.defineProperty(exports, "RawTradeData", { enumerable: true, get: function () { return RawTradeData_1.RawTradeData; } });
41
- let isNode = process || null;
42
- let fetchImpl = null;
43
- let fsImpl = null;
44
- let ccxt = null;
45
- if (globalThis['fetch'])
46
- fetchImpl = fetch;
47
- var State;
48
- (function (State) {
49
- State[State["None"] = 0] = "None";
50
- State[State["Unwinding"] = 1] = "Unwinding";
51
- State[State["Rewinding"] = 2] = "Rewinding";
52
- })(State || (State = {}));
53
- /**
54
- * Load a wasm bundle synchronously. Only accepts the actual binary data.
55
- * @param input - Wasm bundle data
56
- * @param imports - Imports
57
- * @returns
58
- */
59
- function loadWasmSync(input, imports = {}) {
60
- return instantiate(new WebAssembly.Module(input), imports);
61
- }
62
- exports.loadWasmSync = loadWasmSync;
63
- /**
64
- * Load a wasm bundle asynchronously. Accepts the actual binary data or file path.
65
- * @param input - Wasm bundle data or path
66
- * @param imports - Imports
67
- * @returns
68
- */
69
- function loadWasm(input, imports = {}) {
70
- return __awaiter(this, void 0, void 0, function* () {
71
- const mod = instantiate(yield (() => __awaiter(this, void 0, void 0, function* () {
72
- if (typeof input === 'string') {
73
- if (isNode) {
74
- if (!fetchImpl)
75
- fetchImpl = (yield Promise.resolve().then(() => __importStar(require('undici')))).fetch;
76
- if (!fsImpl)
77
- fsImpl = yield Promise.resolve().then(() => __importStar(require('fs/promises')));
78
- if (!ccxt)
79
- ccxt = (yield Promise.resolve().then(() => __importStar(require('ccxt')))).default;
80
- return WebAssembly.compile(yield fsImpl.readFile(input));
81
- }
82
- return yield WebAssembly.compileStreaming(globalThis.fetch(input));
83
- }
84
- else {
85
- return WebAssembly.compile(input);
86
- }
87
- }))(), imports);
88
- return mod;
89
- });
90
- }
91
- exports.loadWasm = loadWasm;
92
- function instantiate(module, imports = {}) {
93
- let WASM_MEMORY;
94
- let WASM_EXPORTS;
95
- let WASM_DV;
96
- let ASYNCIFY_PTR = 0;
97
- let ASYNCIFY_MEM;
98
- let ASYNCIFY_INITIALIZED = false;
99
- let fetchFn = null;
100
- let ccxtFn = null;
101
- let detachedValue = null;
102
- const adaptedImports = Object.assign({
103
- console: {
104
- log(text) {
105
- console.log(__liftString(text));
106
- },
107
- },
108
- ethers: {
109
- keccak256_str(str_ptr) {
110
- const str = __liftString(str_ptr);
111
- const hash = ethers_1.ethers.keccak256(str);
112
- return __lowerString(hash);
113
- },
114
- keccak256_buf(buf_ptr) {
115
- const buf = __liftBuffer(buf_ptr);
116
- const hash = ethers_1.ethers.keccak256(new Uint8Array(buf));
117
- return __lowerString(hash);
118
- },
119
- },
120
- // @ts-ignore
121
- env: {
122
- abort(message, fileName, lineNumber, columnNumber) {
123
- (() => {
124
- throw Error(`${__liftString(message)} in ${__liftString(fileName)}:${lineNumber}:${columnNumber}`);
125
- })();
126
- },
127
- _initAsyncify(frame_ptr, stack_ptr) {
128
- // @ts-ignore
129
- if (!WASM_EXPORTS['asyncify_get_state'])
130
- throw new Error('Asyncify initialized, but not enabled when run! Compile with the --runPasses asyncify flag or asyncify-shim transform!');
131
- if (ASYNCIFY_INITIALIZED)
132
- return;
133
- ASYNCIFY_PTR = frame_ptr;
134
- ASYNCIFY_MEM[ASYNCIFY_PTR >> 2] = ASYNCIFY_PTR + 8;
135
- ASYNCIFY_MEM[(ASYNCIFY_PTR + 4) >> 2] = stack_ptr;
136
- ASYNCIFY_INITIALIZED = true;
137
- },
138
- generateCandles(data, candleSize) {
139
- const _data = __liftString(data) || '[]';
140
- const _candleSize = __liftString(candleSize) || '69m';
141
- const candles = (0, Candle_1.generateCandles)(JSON.parse(_data), _candleSize);
142
- return __lowerString(JSON.stringify(candles));
143
- },
144
- 'console.log': (text) => {
145
- console.log(__liftString(text));
146
- },
147
- ccxt_fetchOHLCV: (exchangeId, symbol, timeframe, limit, since) => {
148
- // @ts-ignore
149
- const currentState = WASM_EXPORTS.asyncify_get_state();
150
- if (currentState === State.Rewinding) {
151
- // @ts-ignore
152
- WASM_EXPORTS.asyncify_stop_rewind();
153
- // @ts-ignore
154
- const ptr = __lowerStaticArray((pointer, value) => {
155
- __setU32(pointer, __lowerStaticArray(__setF64, 7, 3, value, Float64Array));
156
- }, 8, 2, detachedValue);
157
- return ptr;
158
- }
159
- const _exchange = __liftString(exchangeId);
160
- const _symbol = __liftString(symbol);
161
- const _timeframe = __liftString(timeframe);
162
- ccxtFn = () => __awaiter(this, void 0, void 0, function* () {
163
- if (!_exchange || !_symbol || !_timeframe)
164
- throw new Error('Exchange, Symbol, or Timeframe not provided when fetching OHCLV data.');
165
- // @ts-ignore
166
- const data = yield new ccxt[_exchange]({
167
- apiKey: '',
168
- secret: '',
169
- }).fetchOHLCV(_symbol, _timeframe, since, limit);
170
- return data;
171
- });
172
- // @ts-ignore
173
- WASM_EXPORTS.asyncify_start_unwind(ASYNCIFY_PTR);
174
- },
175
- },
176
- 'as-fetch': {
177
- _initAsyncify(frame_ptr, stack_ptr) {
178
- // @ts-ignore
179
- if (!WASM_EXPORTS['asyncify_get_state'])
180
- throw new Error('Asyncify initialized, but not enabled when run! Compile with the --runPasses asyncify flag or asyncify-shim transform!');
181
- if (ASYNCIFY_INITIALIZED)
182
- return;
183
- ASYNCIFY_PTR = frame_ptr;
184
- ASYNCIFY_MEM[ASYNCIFY_PTR >> 2] = ASYNCIFY_PTR + 8;
185
- // I don"t know if I need to reserve all this memory...
186
- ASYNCIFY_MEM[(ASYNCIFY_PTR + 4) >> 2] = stack_ptr;
187
- ASYNCIFY_INITIALIZED = true;
188
- },
189
- _fetchPOSTSync(url, mode, headers, body) {
190
- // @ts-ignore
191
- const currentState = WASM_EXPORTS.asyncify_get_state();
192
- if (currentState === State.Rewinding) {
193
- // @ts-ignore
194
- WASM_EXPORTS.asyncify_stop_rewind();
195
- const ptr = __lowerBuffer(detachedValue);
196
- detachedValue = null;
197
- return ptr;
198
- }
199
- fetchFn = () => __awaiter(this, void 0, void 0, function* () {
200
- const res = yield fetchImpl(__liftString(url) || '', {
201
- method: 'POST',
202
- mode: modeToString(mode) || 'cors',
203
- headers: __liftArray((pointer) => __liftArray((pointer) => __liftString(__getU32(pointer)), 2, __getU32(pointer)), 2, headers) || [],
204
- body: __liftBuffer(body),
205
- });
206
- const value = yield res.arrayBuffer();
207
- return value;
208
- });
209
- // @ts-ignore
210
- WASM_EXPORTS.asyncify_start_unwind(ASYNCIFY_PTR);
211
- },
212
- _fetchGETSync(url, mode, headers) {
213
- // @ts-ignore
214
- const currentState = WASM_EXPORTS.asyncify_get_state();
215
- if (currentState === State.Rewinding) {
216
- // @ts-ignore
217
- WASM_EXPORTS.asyncify_stop_rewind();
218
- const ptr = __lowerBuffer(detachedValue);
219
- detachedValue = null;
220
- return ptr;
221
- }
222
- fetchFn = () => __awaiter(this, void 0, void 0, function* () {
223
- const res = yield fetchImpl(__liftString(url) || '', {
224
- method: 'GET',
225
- mode: modeToString(mode) || 'cors',
226
- headers: __liftArray((pointer) => __liftArray((pointer) => __liftString(__getU32(pointer)), 2, __getU32(pointer)), 2, headers) || [],
227
- });
228
- const value = yield res.arrayBuffer();
229
- return value;
230
- });
231
- // @ts-ignore
232
- WASM_EXPORTS.asyncify_start_unwind(ASYNCIFY_PTR);
233
- },
234
- _fetchGET(url, mode, headers, callbackID) {
235
- fetchImpl(__liftString(url) || '', {
236
- method: 'GET',
237
- mode: modeToString(mode) || 'cors',
238
- headers: __liftArray((pointer) => __liftArray((pointer) => __liftString(__getU32(pointer)), 2, __getU32(pointer)), 2, headers) || [],
239
- }).then((res) => __awaiter(this, void 0, void 0, function* () {
240
- const body = yield res.arrayBuffer();
241
- WASM_EXPORTS.responseHandler(body, res.status, res.redirected ? 1 : 0, callbackID);
242
- }));
243
- },
244
- _fetchPOST(url, mode, headers, body, callbackID) {
245
- fetchImpl(__liftString(url) || '', {
246
- method: 'POST',
247
- mode: modeToString(mode) || 'cors',
248
- body: body,
249
- headers: __liftArray((pointer) => __liftArray((pointer) => __liftString(__getU32(pointer)), 2, __getU32(pointer)), 2, headers) || [],
250
- }).then((res) => __awaiter(this, void 0, void 0, function* () {
251
- const body = yield res.arrayBuffer();
252
- WASM_EXPORTS.responseHandler(body, res.status, res.redirected ? 1 : 0, callbackID);
253
- }));
254
- },
255
- },
256
- }, imports);
257
- const mod = new WebAssembly.Instance(module, adaptedImports);
258
- WASM_EXPORTS = mod.exports;
259
- // @ts-ignore
260
- WASM_MEMORY = WASM_EXPORTS.memory || adaptedImports.env.memory;
261
- ASYNCIFY_MEM = new Uint32Array(WASM_MEMORY.buffer);
262
- const handledExports = Object.setPrototypeOf({
263
- responseHandler(body, statusCode, redirected, callbackID) {
264
- if (!WASM_EXPORTS['responseHandler'])
265
- throw new Error('Unable to call .responseHandler on wasm module. Add the line export { responseHandler } from "as-fetch/assembly" to your entry file.');
266
- // @ts-ignore
267
- WASM_EXPORTS.responseHandler(__lowerBuffer(body), statusCode, redirected ? 1 : 0, callbackID);
268
- },
269
- initialize(config) {
270
- if (!WASM_EXPORTS['initialize'])
271
- throw new Error('Unable to call .initialize on wasm module. Are you sure this is a data connector?');
272
- try {
273
- // @ts-ignore
274
- WASM_EXPORTS.initialize(__lowerString(config));
275
- return true;
276
- }
277
- catch (e) {
278
- console.error(e);
279
- return false;
280
- }
281
- },
282
- execute(...params) {
283
- return __awaiter(this, void 0, void 0, function* () {
284
- if (!WASM_EXPORTS['execute'])
285
- throw new Error('Unable to call .execute on wasm module. Are you sure this is a data connector?');
286
- const loweredArgs = new Array(params.length);
287
- for (let i = 0; i < params.length; i++) {
288
- loweredArgs[i] = __lower(params[i]);
289
- }
290
- let result = WASM_EXPORTS.execute(...loweredArgs);
291
- if (ASYNCIFY_INITIALIZED) {
292
- // @ts-ignore
293
- while (WASM_EXPORTS.asyncify_get_state() === State.Unwinding) {
294
- // @ts-ignore
295
- WASM_EXPORTS.asyncify_stop_unwind();
296
- if (fetchFn)
297
- detachedValue = yield fetchFn();
298
- if (ccxtFn)
299
- detachedValue = yield ccxtFn();
300
- // @ts-ignore
301
- WASM_EXPORTS.asyncify_start_rewind(ASYNCIFY_PTR);
302
- result = WASM_EXPORTS.execute();
303
- }
304
- }
305
- if (fetchFn)
306
- fetchFn = null;
307
- if (ccxtFn)
308
- ccxtFn = null;
309
- // @ts-ignore
310
- return __liftString(result);
311
- });
312
- },
313
- config() {
314
- if (!WASM_EXPORTS['config'])
315
- throw new Error('Unable to call .config on wasm module. Are you sure this is a data connector?');
316
- return __liftString(WASM_EXPORTS.config());
317
- },
318
- transform() {
319
- if (!WASM_EXPORTS['transform'])
320
- throw new Error('Unable to call .transform on wasm module. Are you sure this is a data connector?');
321
- return __liftString(WASM_EXPORTS.transform());
322
- },
323
- reset() {
324
- if (WASM_EXPORTS['reset'])
325
- WASM_EXPORTS.reset();
326
- },
327
- }, WASM_EXPORTS);
328
- WASM_DV = new DataView(WASM_MEMORY.buffer);
329
- function __lower(val) {
330
- if (typeof val === 'number') {
331
- return val;
332
- }
333
- else if (typeof val === 'string') {
334
- return __lowerString(val);
335
- }
336
- else if (val instanceof ArrayBuffer) {
337
- return __lowerBuffer(val);
338
- }
339
- else {
340
- return 0;
341
- }
342
- }
343
- function __liftString(ptr) {
344
- if (!ptr)
345
- return null;
346
- const end = (ptr + new Uint32Array(WASM_MEMORY.buffer)[(ptr - 4) >>> 2]) >>> 1;
347
- const memoryU16 = new Uint16Array(WASM_MEMORY.buffer);
348
- let start = ptr >>> 1;
349
- let string = '';
350
- while (end - start > 1024)
351
- string += String.fromCharCode(...memoryU16.subarray(start, (start += 1024)));
352
- return string + String.fromCharCode(...memoryU16.subarray(start, end));
353
- }
354
- function __lowerString(value) {
355
- if (value == null)
356
- return 0;
357
- const length = value.length;
358
- const ptr = WASM_EXPORTS.__pin(WASM_EXPORTS.__new(length << 1, 2) >>> 0);
359
- const memoryU16 = new Uint16Array(WASM_MEMORY.buffer);
360
- for (let i = 0; i < length; ++i)
361
- memoryU16[(ptr >>> 1) + i] = value.charCodeAt(i);
362
- return ptr;
363
- }
364
- function __liftBuffer(ptr) {
365
- if (!ptr)
366
- return null;
367
- return WASM_MEMORY.buffer.slice(ptr, ptr + new Uint32Array(WASM_MEMORY.buffer)[(ptr - 4) >>> 2]);
368
- }
369
- function __lowerBuffer(value) {
370
- if (value == null)
371
- return 0;
372
- const ptr = WASM_EXPORTS.__pin(WASM_EXPORTS.__new(value.byteLength, 1) >>> 0);
373
- new Uint8Array(WASM_MEMORY.buffer).set(new Uint8Array(value), ptr);
374
- return ptr;
375
- }
376
- function __liftArray(liftElement, align, ptr) {
377
- if (!ptr)
378
- return null;
379
- const dataStart = __getU32(ptr + 4);
380
- const length = WASM_DV.getUint32(ptr + 12, true);
381
- const values = new Array(length);
382
- for (let i = 0; i < length; ++i)
383
- values[i] = liftElement(dataStart + ((i << align) >>> 0));
384
- return values;
385
- }
386
- function __lowerStaticArray(lowerElement, id, align, values, typedConstructor = null) {
387
- if (values == null)
388
- return 0;
389
- const length = values.length;
390
- const buffer = WASM_EXPORTS.__pin(WASM_EXPORTS.__new(length << align, id)) >>> 0;
391
- if (typedConstructor) {
392
- new typedConstructor(WASM_MEMORY.buffer, buffer, length).set(values);
393
- }
394
- else {
395
- for (let i = 0; i < length; i++)
396
- lowerElement(buffer + ((i << align) >>> 0), values[i]);
397
- }
398
- return buffer;
399
- }
400
- function __setU32(ptr, value) {
401
- try {
402
- WASM_DV.setUint32(ptr, value, true);
403
- }
404
- catch (_a) {
405
- WASM_DV = new DataView(WASM_MEMORY.buffer);
406
- WASM_DV.setUint32(ptr, value, true);
407
- }
408
- }
409
- function __setF64(ptr, value) {
410
- try {
411
- WASM_DV.setFloat64(ptr, value, true);
412
- }
413
- catch (_a) {
414
- WASM_DV = new DataView(WASM_MEMORY.buffer);
415
- WASM_DV.setFloat64(ptr, value, true);
416
- }
417
- }
418
- function __getU32(ptr) {
419
- try {
420
- return WASM_DV.getUint32(ptr, true);
421
- }
422
- catch (_a) {
423
- WASM_DV = new DataView(WASM_MEMORY.buffer);
424
- return WASM_DV.getUint32(ptr, true);
425
- }
426
- }
427
- return handledExports;
428
- }
429
- function modeToString(mode) {
430
- if (mode == 1)
431
- return 'cors';
432
- if (mode == 2)
433
- return 'no-cors';
434
- if (mode == 3)
435
- return 'same-origin';
436
- if (mode == 4)
437
- return 'navigate';
438
- return null;
439
- }
@@ -1,9 +0,0 @@
1
- interface TimestringOptions {
2
- hoursPerDay?: number;
3
- daysPerWeek?: number;
4
- weeksPerMonth?: number;
5
- monthsPerYear?: number;
6
- daysPerYear?: number;
7
- }
8
- export default function parseTimestring(value: string | number, returnUnit?: string, opts?: TimestringOptions): number;
9
- export {};
package/lib/timestring.js DELETED
@@ -1,86 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const DEFAULT_OPTS = {
4
- hoursPerDay: 24,
5
- daysPerWeek: 7,
6
- weeksPerMonth: 4,
7
- monthsPerYear: 12,
8
- daysPerYear: 365.25,
9
- };
10
- const UNIT_MAP = {
11
- ms: ['ms', 'milli', 'millisecond', 'milliseconds'],
12
- s: ['s', 'sec', 'secs', 'second', 'seconds'],
13
- m: ['m', 'min', 'mins', 'minute', 'minutes'],
14
- h: ['h', 'hr', 'hrs', 'hour', 'hours'],
15
- d: ['d', 'day', 'days'],
16
- w: ['w', 'week', 'weeks'],
17
- mth: ['mon', 'mth', 'mths', 'month', 'months'],
18
- y: ['y', 'yr', 'yrs', 'year', 'years'],
19
- };
20
- function parseTimestring(value, returnUnit, opts) {
21
- const options = Object.assign({}, DEFAULT_OPTS, opts || {});
22
- let strValue;
23
- if (typeof value === 'number') {
24
- strValue = parseInt(value.toString()) + 'ms';
25
- }
26
- else if (value.match(/^[-+]?[0-9.]+$/g)) {
27
- strValue = parseInt(value) + 'ms';
28
- }
29
- else {
30
- strValue = value;
31
- }
32
- let totalSeconds = 0;
33
- const unitValues = getUnitValues(options);
34
- const groups = strValue
35
- .toLowerCase()
36
- .replace(/[^.\w+-]+/g, '')
37
- .match(/[-+]?[0-9.]+[a-z]+/g);
38
- if (groups === null) {
39
- throw new Error(`The value [${strValue}] could not be parsed by timestring`);
40
- }
41
- groups.forEach((group) => {
42
- const valMatch = group.match(/[0-9.]+/g);
43
- const unitMatch = group.match(/[a-z]+/g);
44
- if (valMatch && unitMatch) {
45
- const val = parseFloat(valMatch[0]);
46
- const unit = unitMatch[0];
47
- totalSeconds += getSeconds(val, unit, unitValues);
48
- }
49
- });
50
- if (returnUnit) {
51
- return convert(totalSeconds, returnUnit, unitValues);
52
- }
53
- return totalSeconds;
54
- }
55
- exports.default = parseTimestring;
56
- function getUnitValues(opts) {
57
- const unitValues = {
58
- ms: 0.001,
59
- s: 1,
60
- m: 60,
61
- h: 3600,
62
- d: 0,
63
- w: 0,
64
- mth: 0,
65
- y: 0,
66
- };
67
- unitValues.d = opts.hoursPerDay * unitValues.h;
68
- unitValues.w = opts.daysPerWeek * unitValues.d;
69
- unitValues.mth = (opts.daysPerYear / opts.monthsPerYear) * unitValues.d;
70
- unitValues.y = opts.daysPerYear * unitValues.d;
71
- return unitValues;
72
- }
73
- function getUnitKey(unit) {
74
- for (const key of Object.keys(UNIT_MAP)) {
75
- if (UNIT_MAP[key].indexOf(unit) > -1) {
76
- return key;
77
- }
78
- }
79
- throw new Error(`The unit [${unit}] is not supported by timestring`);
80
- }
81
- function getSeconds(value, unit, unitValues) {
82
- return value * unitValues[getUnitKey(unit)];
83
- }
84
- function convert(value, unit, unitValues) {
85
- return value / unitValues[getUnitKey(unit)];
86
- }