npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@coherentglobal/wasm-runner

v0.1.4

Published

Coherent WASM runner for Javascript and Node.js

Downloads

46

Readme

About the Project

Run wasm models on browser, on server, on mobile

Demo

Link: https://jeengine.s3.ap-southeast-1.amazonaws.com/wasm/index.html

Getting Started

Install

To use WasmRunner SDK, run

npm install "@coherentglobal/wasm-runner"

or

yarn add "@coherentglobal/wasm-runner"

Usage

Browser ( HTML )

First we call the SDK

<script src="https://wasm-runner-sdk.s3.ap-southeast-1.amazonaws.com/wasmrunner.min.js"></script>

Then create our javascript that initializes the model and runs it.

const param = {
  id: "f30f5935-36c2-4155-aede-523ab2245fd6",
  url: "<zip url>",
};

const payload = {
  request_data: {
    inputs: {
      age: 60,
      insure: "Insure",
      medical: "Yes",
      plan: "Plan 1",
    },
  },
  request_meta: {
    service_uri: "",
    service_uuid: "",
    version: "",
    version_uuid: "f30f5935-36c2-4155-aede-523ab2245fd6",
    transaction_date: "2021-08-18T04:17:17.142Z",
    call_purpose: "postman_request",
    source_system: "",
    correlation_id: "",
    requested_output: "",
  },
};

const wasmRunner = new WasmRunner(param);
await wasmRunner.initialize();
const response = await wasmRunner
  .execute(payload)
  .catch((err) => ({ error: err.v3 }));

// Do something with the response

React

We can call the SDK directly, then follow the normal process of initializing a model then calling the execute method for calculation.

import { WasmRunner } from "@coherentglobal/wasm-runner";

const param = {
  id: "f30f5935-36c2-4155-aede-523ab2245fd6",
  url: "<zip url>",
};

const payload = {
  request_data: {
    inputs: {
      age: 60,
      insure: "Insure",
      medical: "Yes",
      plan: "Plan 1",
    },
  },
  request_meta: {
    service_uri: "",
    service_uuid: "",
    version: "",
    version_uuid: "f30f5935-36c2-4155-aede-523ab2245fd6",
    transaction_date: "2021-08-18T04:17:17.142Z",
    call_purpose: "postman_request",
    source_system: "",
    correlation_id: "",
    requested_output: "",
  },
};

const wasmRunner = new WasmRunner(param);
await wasmRunner.initialize();
const response = await wasmRunner
  .execute(payload)
  .catch((err) => ({ error: err.v3 }));

// Do something the response

NODE JS

We can call the SDK directly, then follow the normal process of initializing a model then calling the execute method for calculation.

const { WasmRunner } = require("@coherentglobal/wasm-runner");

const param = {
  id: "f30f5935-36c2-4155-aede-523ab2245fd6",
  url: "<zip url>",
};

const payload = {
  request_data: {
    inputs: {
      age: 60,
      insure: "Insure",
      medical: "Yes",
      plan: "Plan 1",
    },
  },
  request_meta: {
    service_uri: "",
    service_uuid: "",
    version: "",
    version_uuid: "f30f5935-36c2-4155-aede-523ab2245fd6",
    transaction_date: "2021-08-18T04:17:17.142Z",
    call_purpose: "postman_request",
    source_system: "",
    correlation_id: "",
    requested_output: "",
  },
};

const wasmRunner = new WasmRunner(param);
await wasmRunner.initialize();
const response = await wasmRunner
  .execute(payload)
  .catch((err) => ({ error: err.v3 }));

Different Scenarios to Initialize a Model

Scenario 1

Config is initialized directly on WasmRunner instance.

const param = {
  id: "f30f5935-36c2-4155-aede-523ab2245fd6",
  url: "<zip url>",
};

const payload = {
  request_data: {
    inputs: {
      age: 60,
      insure: "Insure",
      medical: "Yes",
      plan: "Plan 1",
    },
  },
  request_meta: {
    service_uri: "",
    service_uuid: "",
    version: "",
    version_uuid: "f30f5935-36c2-4155-aede-523ab2245fd6",
    transaction_date: "2021-08-18T04:17:17.142Z",
    call_purpose: "postman_request",
    source_system: "",
    correlation_id: "",
    requested_output: "",
  },
};

const wasmRunner = new WasmRunner(param);
await wasmRunner.initialize();
const response = await wasmRunner
  .execute(payload)
  .catch((err) => ({ error: err.v3 }));

Scenario 2

Config is initialized via the append method.

const param = {
  id: "f30f5935-36c2-4155-aede-523ab2245fd6",
  url: "<zip url>",
};

const payload = {
  request_data: {
    inputs: {
      age: 60,
      insure: "Insure",
      medical: "Yes",
      plan: "Plan 1",
    },
  },
  request_meta: {
    service_uri: "",
    service_uuid: "",
    version: "",
    version_uuid: "f30f5935-36c2-4155-aede-523ab2245fd6",
    transaction_date: "2021-08-18T04:17:17.142Z",
    call_purpose: "postman_request",
    source_system: "",
    correlation_id: "",
    requested_output: "",
  },
};

const wasmRunner = new WasmRunner();
await wasmRunner.append(param);
await wasmRunner.initialize();
const response = await wasmRunner
  .execute(payload)
  .catch((err) => ({ error: err.v3 }));

Scenario 3

Config is initialized directly on WasmRunner instance and append a new model via the append method.

const param = {
  id: "f30f5935-36c2-4155-aede-523ab2245fd6",
  url: "<zip url>",
};

const param2 = {
  id: "e8ba9e7e-169c-4752-8a8e-d6eb0c78cb01",
  url: "<zip url>",
};

const payload = {
  request_data: {
    inputs: {
      age: 60,
      insure: "Insure",
      medical: "Yes",
      plan: "Plan 1",
    },
  },
  request_meta: {
    service_uri: "",
    service_uuid: "",
    version: "",
    version_uuid: "f30f5935-36c2-4155-aede-523ab2245fd6",
    transaction_date: "2021-08-18T04:17:17.142Z",
    call_purpose: "postman_request",
    source_system: "",
    correlation_id: "",
    requested_output: "",
  },
};

const wasmRunner = new WasmRunner(param);
await wasmRunner.initialize();
await wasmRunner.append(param2);

const response = await wasmRunner
  .execute(payload)
  .catch((err) => ({ error: err.v3 }));

Development

Setup

Clone the repo, then install the dependencies

$ git clone https://github.com/CoherentCapital/wasm-runner-js.git
$ yarn install

Methods

(async) append(modelConfig)

Append and initialized new model to runner

await wasmRunner.append(param);

(async) execute(input)

Perform calculation. The runner will use request_meta.version_uuid of input argument to locate model

const response = await wasmRunner.execute(payload).catch((err) => {
  // Do something here
});

isExist(id)

Check if model existed

if (wasmRunner.isExist(id)) {
  // Do something here
}

remove(id)

Remove model from runner

wasmRunner.remove(id);

Initialize Model

There are two ways to initialize a model. First is when you instantiating a class,

const wasmRunner = new WasmRunner(param);

And the second way is by using the append method.

await wasmRunner.append(param);

Limitations

Lower Level Error

Please note that if there's lower level error that occurs, wasm runner can't handle that kind of exception.

FootNote

Sample Payload

{
  "request_data": {
    "inputs": {
      "age": 60,
      "insure": "Insure",
      "medical": "Yes",
      "plan": "Plan 1"
    }
  },
  "request_meta": {
    "service_uri": "",
    "service_uuid": "",
    "version": "",
    "version_uuid": "<model id>",
    "transaction_date": "2021-08-18T04:17:17.142Z",
    "call_purpose": "postman_request",
    "source_system": "",
    "correlation_id": "",
    "requested_output": ""
  }
}