@coherentglobal/wasm-runner 0.0.22
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 +263 -0
- package/dist/browser/template/main.template.d.ts +1 -0
- package/dist/browser/template/main.template.js +13 -0
- package/dist/browser/template/main.template.js.map +1 -0
- package/dist/browser/template/runtime.template.d.ts +1 -0
- package/dist/browser/template/runtime.template.js +926 -0
- package/dist/browser/template/runtime.template.js.map +1 -0
- package/dist/browser/template/worker.template.d.ts +3 -0
- package/dist/browser/template/worker.template.js +39 -0
- package/dist/browser/template/worker.template.js.map +1 -0
- package/dist/browser/template.d.ts +1 -0
- package/dist/browser/template.js +14 -0
- package/dist/browser/template.js.map +1 -0
- package/dist/browser.d.ts +63 -0
- package/dist/browser.js +308 -0
- package/dist/browser.js.map +1 -0
- package/dist/error.d.ts +56 -0
- package/dist/error.js +112 -0
- package/dist/error.js.map +1 -0
- package/dist/node/template/main.template.ejs +70 -0
- package/dist/node.d.ts +66 -0
- package/dist/node.js +375 -0
- package/dist/node.js.map +1 -0
- package/dist/types.d.ts +32 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/dist/utils.d.ts +15 -0
- package/dist/utils.js +122 -0
- package/dist/utils.js.map +1 -0
- package/package.json +79 -0
- package/tsconfig.json +22 -0
package/README.md
ADDED
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
<br>
|
|
3
|
+
<br>
|
|
4
|
+
<!-- <img width="200" src="" alt="Wasm Runnert"> -->
|
|
5
|
+
<br>
|
|
6
|
+
<h1> Wasm Runner Browser </h1>
|
|
7
|
+
</div>
|
|
8
|
+
|
|
9
|
+
<div align="center">
|
|
10
|
+
<a href='https://github.com/CoherentCapital/wasm-runner-js/issues'>Report Bug</a>
|
|
11
|
+
·
|
|
12
|
+
<a href='https://github.com/CoherentCapital/wasm-runner-js/issues'>Request Feature</a>
|
|
13
|
+
</div>
|
|
14
|
+
|
|
15
|
+
- [About the Project](#about-the-project)
|
|
16
|
+
- [Demo](#demo)
|
|
17
|
+
- [Getting Started](#getting-started)
|
|
18
|
+
- [Prerequisites](#prerequisites)
|
|
19
|
+
- [Install](#install)
|
|
20
|
+
- [Usage](#usage)
|
|
21
|
+
- [Browser ( HTML )](#browser--html-)
|
|
22
|
+
- [React](#react)
|
|
23
|
+
- [Development](#development)
|
|
24
|
+
- [Setup](#setup)
|
|
25
|
+
- [Methods](#methods)
|
|
26
|
+
- [Initialize Model](#initialize-model)
|
|
27
|
+
- [Limitations](#limitations)
|
|
28
|
+
- [FootNote](#footnote)
|
|
29
|
+
- [Sample Payload](#sample-payload)
|
|
30
|
+
|
|
31
|
+
# About the Project
|
|
32
|
+
|
|
33
|
+
Run wasm models on browser, on server, on mobile
|
|
34
|
+
|
|
35
|
+
## Demo
|
|
36
|
+
|
|
37
|
+
Link: https://jeengine.s3.ap-southeast-1.amazonaws.com/wasm/index.html
|
|
38
|
+
|
|
39
|
+
# Getting Started
|
|
40
|
+
|
|
41
|
+
## Prerequisites
|
|
42
|
+
|
|
43
|
+
1. Download and setup AWS CLI to your machine.
|
|
44
|
+
2. Run `aws configure` on your preferred terminal and fill-out the necessary fields.
|
|
45
|
+
|
|
46
|
+
Execute this command to retrieve the authorization token. This **token is only valid for 12 hours** after the retrieval.
|
|
47
|
+
|
|
48
|
+
```
|
|
49
|
+
export CODEARTIFACT_AUTH_TOKEN=`aws codeartifact get-authorization-token --domain coherent-global --domain-owner 792307798794 --query authorizationToken --output text`
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
3. Create or update your `.npmrc` file.
|
|
53
|
+
|
|
54
|
+
```
|
|
55
|
+
registry=https://registry.yarnpkg.com
|
|
56
|
+
@coherentglobal:registry=https://coherent-global-792307798794.d.codeartifact.ap-southeast-1.amazonaws.com/npm/coherent-global/
|
|
57
|
+
//coherent-global-792307798794.d.codeartifact.ap-southeast-1.amazonaws.com/npm/coherent-global/:always-auth=true
|
|
58
|
+
//coherent-global-792307798794.d.codeartifact.ap-southeast-1.amazonaws.com/npm/coherent-global/:_authToken=${CODEARTIFACT_AUTH_TOKEN}
|
|
59
|
+
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Install
|
|
63
|
+
|
|
64
|
+
To use WasmRunner SDK, run
|
|
65
|
+
|
|
66
|
+
```
|
|
67
|
+
npm install "@coherentglobal/wasm-runner"
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
or
|
|
71
|
+
|
|
72
|
+
```
|
|
73
|
+
yarn add "@coherentglobal/wasm-runner"
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## Usage
|
|
77
|
+
|
|
78
|
+
### Browser ( HTML )
|
|
79
|
+
|
|
80
|
+
First we call the SDK
|
|
81
|
+
|
|
82
|
+
```html
|
|
83
|
+
<script src="https://wasm-runner-sdk.s3.ap-southeast-1.amazonaws.com/wasmrunner.min.js"></script>
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
Then create our javascript that initializes the model and runs it.
|
|
87
|
+
|
|
88
|
+
```js
|
|
89
|
+
const param = {
|
|
90
|
+
id: "f30f5935-36c2-4155-aede-523ab2245fd6",
|
|
91
|
+
url: "<zip url>",
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
const payload = {
|
|
95
|
+
request_data: {
|
|
96
|
+
inputs: {
|
|
97
|
+
age: 60,
|
|
98
|
+
insure: "Insure",
|
|
99
|
+
medical: "Yes",
|
|
100
|
+
plan: "Plan 1",
|
|
101
|
+
},
|
|
102
|
+
},
|
|
103
|
+
request_meta: {
|
|
104
|
+
service_uri: "",
|
|
105
|
+
service_uuid: "",
|
|
106
|
+
version: "",
|
|
107
|
+
version_uuid: "f30f5935-36c2-4155-aede-523ab2245fd6",
|
|
108
|
+
transaction_date: "2021-08-18T04:17:17.142Z",
|
|
109
|
+
call_purpose: "postman_request",
|
|
110
|
+
source_system: "",
|
|
111
|
+
correlation_id: "",
|
|
112
|
+
requested_output: "",
|
|
113
|
+
},
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
const wasmRunner = new WasmRunner(param);
|
|
117
|
+
await wasmRunner.initialize();
|
|
118
|
+
const response = await wasmRunner
|
|
119
|
+
.execute(payload)
|
|
120
|
+
.catch((err) => ({ error: err.v3 }));
|
|
121
|
+
|
|
122
|
+
// Do something with the response
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
### React
|
|
126
|
+
|
|
127
|
+
We can call the SDK directly, then follow the normal process of initializing a model then calling the execute method for calculation.
|
|
128
|
+
|
|
129
|
+
```js
|
|
130
|
+
import { WasmRunner } from "@coherentglobal/wasm-runner";
|
|
131
|
+
|
|
132
|
+
const param = {
|
|
133
|
+
id: "f30f5935-36c2-4155-aede-523ab2245fd6",
|
|
134
|
+
url: "<zip url>",
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
const payload = {
|
|
138
|
+
request_data: {
|
|
139
|
+
inputs: {
|
|
140
|
+
age: 60,
|
|
141
|
+
insure: "Insure",
|
|
142
|
+
medical: "Yes",
|
|
143
|
+
plan: "Plan 1",
|
|
144
|
+
},
|
|
145
|
+
},
|
|
146
|
+
request_meta: {
|
|
147
|
+
service_uri: "",
|
|
148
|
+
service_uuid: "",
|
|
149
|
+
version: "",
|
|
150
|
+
version_uuid: "f30f5935-36c2-4155-aede-523ab2245fd6",
|
|
151
|
+
transaction_date: "2021-08-18T04:17:17.142Z",
|
|
152
|
+
call_purpose: "postman_request",
|
|
153
|
+
source_system: "",
|
|
154
|
+
correlation_id: "",
|
|
155
|
+
requested_output: "",
|
|
156
|
+
},
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
const wasmRunner = new WasmRunner(param);
|
|
160
|
+
await wasmRunner.initialize();
|
|
161
|
+
const response = await wasmRunner
|
|
162
|
+
.execute(payload)
|
|
163
|
+
.catch((err) => ({ error: err.v3 }));
|
|
164
|
+
|
|
165
|
+
// Do something the response
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
# Development
|
|
169
|
+
|
|
170
|
+
## Setup
|
|
171
|
+
|
|
172
|
+
Clone the repo, then install the dependencies
|
|
173
|
+
|
|
174
|
+
```bash
|
|
175
|
+
$ git clone https://github.com/CoherentCapital/wasm-runner-js.git
|
|
176
|
+
$ yarn install
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
## Methods
|
|
180
|
+
|
|
181
|
+
### (async) append(modelConfig)
|
|
182
|
+
|
|
183
|
+
Append and initialized new model to runner
|
|
184
|
+
|
|
185
|
+
```js
|
|
186
|
+
await wasmRunner.append(param)
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
### (async) execute(input)
|
|
190
|
+
|
|
191
|
+
Perform calculation. The runner will use request_meta.version_uuid of input argument to locate model
|
|
192
|
+
|
|
193
|
+
```js
|
|
194
|
+
const response = await wasmRunner
|
|
195
|
+
.execute(payload)
|
|
196
|
+
.catch((err) => {
|
|
197
|
+
// Do something here
|
|
198
|
+
});
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
### isExist(id)
|
|
202
|
+
|
|
203
|
+
Check if model existed
|
|
204
|
+
|
|
205
|
+
```js
|
|
206
|
+
if (wasmRunner.isExist(id)) {
|
|
207
|
+
// Do something here
|
|
208
|
+
}
|
|
209
|
+
```
|
|
210
|
+
### remove(id)
|
|
211
|
+
|
|
212
|
+
Remove model from runner
|
|
213
|
+
|
|
214
|
+
```js
|
|
215
|
+
wasmRunner.remove(id)
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
## Initialize Model
|
|
219
|
+
|
|
220
|
+
There are two ways to initialize a model. First is when you instantiating a class,
|
|
221
|
+
|
|
222
|
+
```js
|
|
223
|
+
const wasmRunner = new WasmRunner(param);
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
And the second way is by using the append method.
|
|
227
|
+
|
|
228
|
+
```js
|
|
229
|
+
await wasmRunner.append(param)
|
|
230
|
+
```
|
|
231
|
+
# Limitations
|
|
232
|
+
|
|
233
|
+
## Lower Level Error
|
|
234
|
+
|
|
235
|
+
Please note that if there's lower level error that occurs, wasm runner can't handle that kind of exception.
|
|
236
|
+
|
|
237
|
+
# FootNote
|
|
238
|
+
|
|
239
|
+
## Sample Payload
|
|
240
|
+
|
|
241
|
+
``` js
|
|
242
|
+
{
|
|
243
|
+
"request_data": {
|
|
244
|
+
"inputs": {
|
|
245
|
+
"age": 60,
|
|
246
|
+
"insure": "Insure",
|
|
247
|
+
"medical": "Yes",
|
|
248
|
+
"plan": "Plan 1"
|
|
249
|
+
}
|
|
250
|
+
},
|
|
251
|
+
"request_meta": {
|
|
252
|
+
"service_uri": "",
|
|
253
|
+
"service_uuid": "",
|
|
254
|
+
"version": "",
|
|
255
|
+
"version_uuid": "<model id>",
|
|
256
|
+
"transaction_date": "2021-08-18T04:17:17.142Z",
|
|
257
|
+
"call_purpose": "postman_request",
|
|
258
|
+
"source_system": "",
|
|
259
|
+
"correlation_id": "",
|
|
260
|
+
"requested_output": ""
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
```
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function buildWorkerFN(runtime: any, license?: string): string;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
function buildWorkerFN(runtime, license = "") {
|
|
4
|
+
return `
|
|
5
|
+
${runtime}
|
|
6
|
+
|
|
7
|
+
const license = '${license}';
|
|
8
|
+
|
|
9
|
+
%%%WORKER%%%
|
|
10
|
+
`;
|
|
11
|
+
}
|
|
12
|
+
exports.default = buildWorkerFN;
|
|
13
|
+
//# sourceMappingURL=main.template.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"main.template.js","sourceRoot":"","sources":["../../../src/browser/template/main.template.js"],"names":[],"mappings":";;AAAA,SAAwB,aAAa,CAAC,OAAO,EAAE,OAAO,GAAG,EAAE;IACzD,OAAO;MACH,OAAO;;uBAEU,OAAO;;;CAG7B,CAAC;AACF,CAAC;AARD,gCAQC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
declare function runtime(wasmBinaryFile: any): (Module: any) => any;
|