@steerprotocol/app-loader 0.0.1

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/LICENSE.md ADDED
@@ -0,0 +1,7 @@
1
+ Copyright 2022 Hebert Cisco
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1 @@
1
+ # Steer Protocol App Loader
@@ -0,0 +1,7 @@
1
+ /// <reference types="node" />
2
+ import crypto from 'node:crypto';
3
+ export declare class Uuid {
4
+ v4(options?: crypto.RandomUUIDOptions | undefined): string;
5
+ }
6
+ declare const _default: Uuid;
7
+ export default _default;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.Uuid = void 0;
7
+ const node_crypto_1 = __importDefault(require("node:crypto"));
8
+ class Uuid {
9
+ v4(options) {
10
+ return node_crypto_1.default.randomUUID(options);
11
+ }
12
+ }
13
+ exports.Uuid = Uuid;
14
+ exports.default = new Uuid();
package/lib/index.d.ts ADDED
@@ -0,0 +1,30 @@
1
+ /**
2
+ * assembly/index/initialize
3
+ * @param config `~lib/string/String`
4
+ */
5
+ declare function initialize(config: string): void;
6
+ /**
7
+ * assembly/index/execute
8
+ * @param _prices `~lib/string/String`
9
+ * @returns `~lib/string/String`
10
+ */
11
+ declare function execute(_prices: string): string;
12
+ /**
13
+ * assembly/index/config
14
+ * @returns `~lib/string/String`
15
+ */
16
+ declare function config(): string;
17
+ /**
18
+ * assembly/index/version
19
+ * @returns `i32`
20
+ */
21
+ declare function version(): number;
22
+ export type WasmModule = {
23
+ initialize: typeof initialize;
24
+ execute: typeof execute;
25
+ config: typeof config;
26
+ version: typeof version;
27
+ memory: WebAssembly.Memory;
28
+ };
29
+ export declare const loadWasm: (url: string, imports?: {}) => Promise<WasmModule>;
30
+ export {};
package/lib/index.js ADDED
@@ -0,0 +1,186 @@
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 = void 0;
36
+ function instantiate(module, imports = {}) {
37
+ return __awaiter(this, void 0, void 0, function* () {
38
+ const adaptedImports = {
39
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
40
+ // @ts-ignore
41
+ env: Object.assign(Object.create(globalThis), imports.env || {}, {
42
+ abort(message, fileName, lineNumber, columnNumber) {
43
+ // ~lib/builtins/abort(~lib/string/String | null?, ~lib/string/String | null?, u32?, u32?) => void
44
+ message = __liftString(message >>> 0);
45
+ fileName = __liftString(fileName >>> 0);
46
+ lineNumber >>>= 0;
47
+ columnNumber >>>= 0;
48
+ (() => {
49
+ // @external.js
50
+ throw new Error(`${message} in ${fileName}:${lineNumber}:${columnNumber}`);
51
+ })();
52
+ },
53
+ }),
54
+ };
55
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
56
+ // @ts-ignore
57
+ const { exports } = yield WebAssembly.instantiate(module, adaptedImports);
58
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
59
+ // @ts-ignore
60
+ const memory = exports.memory || imports.env.memory;
61
+ const adaptedExports = Object.setPrototypeOf({
62
+ initialize(config) {
63
+ // assembly/index/initialize(~lib/string/String) => void
64
+ const configPointer = __lowerString(config) || __notnull();
65
+ exports.initialize(configPointer);
66
+ },
67
+ execute(_prices) {
68
+ // assembly/index/execute(~lib/string/String) => ~lib/string/String
69
+ const _pricesPointer = __lowerString(_prices) || __notnull();
70
+ return __liftString(exports.execute(_pricesPointer) >>> 0);
71
+ },
72
+ config() {
73
+ // assembly/index/config() => ~lib/string/String
74
+ return __liftString(exports.config() >>> 0);
75
+ },
76
+ }, exports);
77
+ function __liftString(pointer) {
78
+ if (!pointer)
79
+ return null;
80
+ const end = pointer + new Uint32Array(memory.buffer)[pointer - 4 >>> 2] >>> 1;
81
+ const memoryU16 = new Uint16Array(memory.buffer);
82
+ let start = pointer >>> 1;
83
+ let string = '';
84
+ while (end - start > 1024)
85
+ string += String.fromCharCode(...memoryU16.subarray(start, start += 1024));
86
+ return string + String.fromCharCode(...memoryU16.subarray(start, end));
87
+ }
88
+ function __lowerString(value) {
89
+ if (value === null)
90
+ return 0;
91
+ const length = value.length;
92
+ const pointer = exports.__new(length << 1, 2) >>> 0;
93
+ const memoryU16 = new Uint16Array(memory.buffer);
94
+ for (let i = 0; i < length; ++i)
95
+ memoryU16[(pointer >>> 1) + i] = value.charCodeAt(i);
96
+ return pointer;
97
+ }
98
+ function __liftArray(liftElement, align, pointer) {
99
+ if (!pointer)
100
+ return null;
101
+ const dataStart = __getU32(pointer + 4);
102
+ const length = __dataview.getUint32(pointer + 12, true);
103
+ const values = new Array(length);
104
+ for (let i = 0; i < length; ++i)
105
+ values[i] = liftElement(dataStart + (i << align >>> 0));
106
+ return values;
107
+ }
108
+ function __lowerArray(lowerElement, id, align, values) {
109
+ if (values === null)
110
+ return 0;
111
+ const length = values.length;
112
+ const buffer = exports.__pin(exports.__new(length << align, 1)) >>> 0;
113
+ const header = exports.__pin(exports.__new(16, id)) >>> 0;
114
+ __setU32(header + 0, buffer);
115
+ __dataview.setUint32(header + 4, buffer, true);
116
+ __dataview.setUint32(header + 8, length << align, true);
117
+ __dataview.setUint32(header + 12, length, true);
118
+ for (let i = 0; i < length; ++i)
119
+ lowerElement(buffer + (i << align >>> 0), values[i]);
120
+ exports.__unpin(buffer);
121
+ exports.__unpin(header);
122
+ return header;
123
+ }
124
+ class Internref extends Number {
125
+ }
126
+ function __lowerInternref(value) {
127
+ if (value === null)
128
+ return 0;
129
+ if (value instanceof Internref)
130
+ return value.valueOf();
131
+ throw new TypeError('internref expected');
132
+ }
133
+ function __notnull() {
134
+ throw new TypeError('value must not be null');
135
+ }
136
+ let __dataview = new DataView(memory.buffer);
137
+ function __setU32(pointer, value) {
138
+ try {
139
+ __dataview.setUint32(pointer, value, true);
140
+ }
141
+ catch (_a) {
142
+ __dataview = new DataView(memory.buffer);
143
+ __dataview.setUint32(pointer, value, true);
144
+ }
145
+ }
146
+ function __getU32(pointer) {
147
+ try {
148
+ return __dataview.getUint32(pointer, true);
149
+ }
150
+ catch (_a) {
151
+ __dataview = new DataView(memory.buffer);
152
+ return __dataview.getUint32(pointer, true);
153
+ }
154
+ }
155
+ function __getF32(pointer) {
156
+ try {
157
+ return __dataview.getFloat32(pointer, true);
158
+ }
159
+ catch (_a) {
160
+ __dataview = new DataView(memory.buffer);
161
+ return __dataview.getFloat32(pointer, true);
162
+ }
163
+ }
164
+ function __getF64(pointer) {
165
+ try {
166
+ return __dataview.getFloat64(pointer, true);
167
+ }
168
+ catch (_a) {
169
+ __dataview = new DataView(memory.buffer);
170
+ return __dataview.getFloat64(pointer, true);
171
+ }
172
+ }
173
+ return adaptedExports;
174
+ });
175
+ }
176
+ const loadWasm = (url, imports = {}) => __awaiter(void 0, void 0, void 0, function* () {
177
+ return instantiate(yield (() => __awaiter(void 0, void 0, void 0, function* () {
178
+ try {
179
+ return yield globalThis.WebAssembly.compileStreaming(globalThis.fetch(url));
180
+ }
181
+ catch (_a) {
182
+ return globalThis.WebAssembly.compile(yield (yield Promise.resolve().then(() => __importStar(require('node:fs/promises')))).readFile(url));
183
+ }
184
+ }))(), imports);
185
+ });
186
+ exports.loadWasm = loadWasm;
package/package.json ADDED
@@ -0,0 +1,47 @@
1
+ {
2
+ "name": "@steerprotocol/app-loader",
3
+ "version": "0.0.1",
4
+ "description": "App Loader for Steer Protocol",
5
+ "main": "lib/index.js",
6
+ "types": "lib/index.d.ts",
7
+ "scripts": {
8
+ "build": "tsc",
9
+ "format": "prettier --write \"src/**/*.(js|ts)\"",
10
+ "lint": "eslint src --ext .js,.ts",
11
+ "lint:fix": "eslint src --fix --ext .js,.ts",
12
+ "test": "jest --config jest.config.js",
13
+ "prepare": "npm run build",
14
+ "prepublishOnly": "npm test && npm run lint",
15
+ "preversion": "npm run lint",
16
+ "version": "npm run format && git add -A src",
17
+ "postversion": "git push && git push --tags"
18
+ },
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "git+https://github.com/hebertcisco/ts-npm-package-boilerplate.git"
22
+ },
23
+ "keywords": [
24
+ "boilerplate",
25
+ "typescript"
26
+ ],
27
+ "author": "Hebert Cisco",
28
+ "license": "MIT",
29
+ "bugs": {
30
+ "url": "https://github.com/hebertcisco/ts-npm-package-boilerplate/issues"
31
+ },
32
+ "homepage": "https://github.com/hebertcisco/ts-npm-package-boilerplate#readme",
33
+ "devDependencies": {
34
+ "@types/jest": "29.2.4",
35
+ "@typescript-eslint/eslint-plugin": "5.46.0",
36
+ "@typescript-eslint/parser": "5.47.1",
37
+ "eslint": "8.30.0",
38
+ "eslint-plugin-jest": "27.1.7",
39
+ "jest": "29.3.1",
40
+ "prettier": "2.8.1",
41
+ "ts-jest": "29.0.3",
42
+ "typescript": "4.9.4"
43
+ },
44
+ "files": [
45
+ "lib/**/*"
46
+ ]
47
+ }