trepo-webworker

Wrapper to host Trepo in a Web Worker

Usage no npm install needed!

<script type="module">
  import trepoWebworker from 'https://cdn.skypack.dev/trepo-webworker';
</script>

README

trepo-webworker-js

Starts a Trepo Server in a Web Worker.

Example

var worker = new Worker('/trepo-webworker.js');

worker.onmessage = function(e) {
  console.log(e.data);
  // Data will have 2 fields, id and payload.
}

// To start Trepo
worker.postMessage({
  id: '1234',
  cmd: 'start',
  payload: {
    repo: 'my-repo',
    vgraph: {
      //engine: 'level',
      name: 'testing'
    },
    xsearch: {
      prefix: 'testing'
    }
  }
});

// To make a request
worker.postMessage({
  id: '1234',
  cmd: 'request',
  payload: {
    method: 'GET',
    path: '/graph/info'
  }
});

// To Stop Trepo
worker.postMessage({
  id: '1234',
  cmd: 'stop',
  payload: {}
});

Usage

Each request sends an id, cmd, and payload. Each response includes an id and a payload.

Request

  • id - Used to match requests with responses (each response will include the id of the request).
  • cmd - One of start, stop, and request.
  • payload - The request payload.

Response

  • id - Used to match requests with responses.
  • payload - The response payload.