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

opfsdb

v1.0.8

Published

Origin private file system DB

Downloads

3

Readme

OPFSDB

OPFSDB (Origin Private File System Database) is a TypeScript library that provides a lightweight and efficient in-browser database solution using the File System Access API and Web Workers. It utilizes the B+ Tree data structure from the serializable-bptree library for indexing and querying data, allowing for fast and scalable storage and retrieval of records.

You can find demo with table for data browsing and querying here. You can also load custom CSV file but for now "id" is required column.

Table of Contents

Features

  • File System Access API: OPFSDB uses the File System Access API to create a private, sandboxed database for your application, ensuring data privacy and security.
  • Web Workers: Utilizes Web Workers to allow for sync OPFS API that drastically improves read and write performance.
  • Shared Worker API: OPFSDB leverages the Shared Worker API to enable communication between multiple Web Workers, allowing for multi-tab interaction with one database.
  • Efficient Indexing: OPFSDB uses serializable-bptree, a high-performance B+ Tree implementation, for indexing and querying data.
  • TypeScript Support: Written in TypeScript for better type safety and developer experience.
  • Encoding/Decoding: OPFSDB encodes data in CBOR format using cbor-x library, also storing the structures alongside.

Architecture

OPFSDB has three main entry points:

  1. Main Page Code: This is the code that runs in the main browser context. It is responsible for initializing WorkerManager and interacting with the database through the sendCommand method.

  2. Shared Worker: This is a special type of Web Worker that can be shared across multiple browser contexts. It acts as a communication bridge between the main page code and the dedicated Web Workers.

  3. Dedicated Web Workers: These are the actual workers that perform the database operations. They can either execute queries directly or communicate with a master worker through the shared worker.

Installation

npm install opfsdb
pnpm add opfsdb
yarn add opfsdb

Getting Started

Main Thread

In your main application code, you can interact with OPFSDB using the sendCommand method from the WorkerManager class:

import { WorkerManager } from 'opfsdb/WorkerManager'

const workerManager = new WorkerManager('worker.js', 'shared-worker.js')

// Send a command to create a new table
workerManager.sendCommand({
	name: 'createTable',
	tableName: 'users',
	keys: {
		id: { type: 'string' },
		name: { type: 'string', indexed: true },
		age: { type: 'number', indexed: true },
	},
})

// Insert data into the table
workerManager.sendCommand({
	name: 'insert',
	tableName: 'users',
	record: { id: '1', name: 'John Doe', age: 30 },
})

// Query data from the table
workerManager
	.sendCommand({
		name: 'query',
		tableName: 'users',
		query: { age: { gte: 25 }, name: { like: 'John%' } },
	})
	.then(results => {
		console.log('Query results:', results)
	})

Shared Worker

The Shared Worker acts as a communication channel between different Web Workers. It connects with each Web Worker and tracks the master one, when one of the slave Web Workers receives a command from the Main Thread, it will communicate with the master Web Worker through the Shared Web Worker.
You can create a new Shared Worker file (shared-worker.js) and import the SharedWorkerController class from OPFSDB:

import { SharedWorkerController } from 'opfsdb/workers/SharedWorkerController'
const sharedWorkerController = new SharedWorkerController()

Web Worker

The Web Workers handle the actual execution of commands. They receive commands from the Main thread and, depending on whether it's the master Worker or not, they will either execute the command and return the results or send the command to the Shared Worker.
You can create a new Web Worker file (worker.js) and import the DedicatedWorkerController class from OPFSDB:

import { DedicatedWorkerController } from 'opfsdb/workers/DedicatedWorkerController'
const dedicatedWorkerController = new DedicatedWorkerController()

Docs

You can find typedoc in the docs folder Here