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

@realitypackagemanager/wasm-facet-engine

v0.0.14

Published

A piece of code designed to take a small set of json records and create facets based on sub parts of those records. This is for a small number of records as it is intended to be used as a webassembly on a client browser.

Downloads

3

Readme

Web Assembly Facet Engine

A piece of code designed to take a small set of json records and create facets based on sub parts of those records. This is for a small number of records as it is intended to be used as a webassembly on a client browser.

The advantage of this approach is you can have very rich faceting without exploding your server.

The "small number" has yet to be determined, but performance metrics will be posted here when we know more.

0.0.14 performance

|Record Count|Initialization|Search |--------:|----------:|--------: | 1 | 2 ms | 1 ms
| 100 | 47 ms | 2 ms
| 1,000 | 528 ms | 15 ms
| 10,000 | 2,776 ms | 42 ms | 100,000 | 34,553 ms | 544 ms

Installation

Add the js bundle to your application

npm i @realitypackagemanager/wasm-facet-engine

Copy the facet-engine.wasm file from node_modules/@realitypackagemanager/wasm-facet-engine into the root of your web-application.

Ensure that this wasm file is served with the mime-type application/wasm or it will not work.

Import the facetEngine into your application

import facetEngine from '@realitypackagemanager/wasm-facet-engine'
  • facetEngineLoad(callbackFunction) - load the wasm file from your webserver.
  • facetEngine.initializeObjects(stringifiedConfiguration, stringifiedObjectArray, callbackFacets) - send in the records that you're going to work with and the configuration about which data elements are to be used as facets. Facets are sent back to the callback supplied
  • facetEngine.addFilter('facetGroupName', 'facetName', true, 7, false, 12) - add a filter to the state. The boolean parameters specify that the range is (true = inclusive) or (false = exclusive)
  • facetEngine.removeFilter(filterName) - remove a filter by name
  • facetEngine.clearFilters() - remove all filters
  • facetEngine.query(callbackRecords, callbackFacets) - query the records for the current filters. Results are sent to the supplied callback invocations callbackFacets(stringifiedIdArray). Facets are sent back to callbackRecords(stringifiedFacets)

Usage

Given the following array of two json objects held in a variable called jsonData:

let jsonData = [
  {
    "id": "record 1",
    "measurements": [
      {
        "measurementName": "area",
        "metrics": {
          "metricName": "cube",
          "measurements": {
            "side": "10"
          }
        }
      }
    ]
  },
  {
    "id": "record 2",
    "measurements": [
      {
        "measurementName": "area",
        "metrics": {
          "metricName": "cube",
          "measurements": {
            "side": "20"
          }
        }
      }
    ]
  }
]

Load the facet engine

facetEngine.load(function(){
  console.log('loaded!')
})

Initialize the engine with the list of objects to create facets for and the configuration of which data elements to extract for facets.

let config = {
  arrayDotNotation:     "measurements",
  nameFieldDotNotation: "measurementName",
  nameMetaDotNotation:  "metrics.metricName",
  valueMapDotNotation:  "metrics.measurements"
}

facetEngine.initializeObjects(JSON.stringify(config), JSON.stringify(jsonData), function(facets){
  console.log('got facets', facets)
})

Add a filter and run it

facetEngine.addFilter("area (cube)", "side", true, 8.0, false, 12.0)
facetEngine.query(callbackResults, callbackFacets)
function callbackResults(stringifiedIdArray) {
  listOfIds = JSON.parse(stringifiedIdArray)
  // Do something with the ids
}
function callbackFacets(stringifiedFacets) {
  facets = JSON.parse(stringifiedFacets)
  // Do something with the facets
}