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

thermodb

v1.1.2

Published

Database for progressive Webapps

Downloads

28

Readme

ThermoDb

A fork of minimongo for agnostic datasources.

Usage

import MemoryDb from 'thermodb/MemoryDb';

const db = new MemoryDb();

const collection = await db.addCollection('things');
// collection === db.collections.things === db.things

const foo = await collection.upsert({ a: 'Hello' });
// -> { id: ..., a: 'Hello' }

API

HybridDb

Combines results from the local database with remote data.

import HybridDb from 'thermodb/HybridDb';

const db = new IndexedDb(localDb, remoteDb);

await db.addCollection('foo', {
   // Cache find results in local db
   cacheFind: true,
   // Cache findOne results in local db
   cacheFindOne: true,
   // Return interim results from local db while waiting for remote db (see onRemoteData)
   interim: true,
   // Use local results if the remote find fails. Only applies if interim is false.
   useLocalOnRemoteError: true,
   // true to return `findOne` results if any matching result is found in the local database.
   // Useful for documents that change rarely.
   shortcut: false,
   // Set to ms to timeout in for remote calls
   timeout: 0,
   // Compare function to sort upserts sent to server. (called by Array.sort()
   sortUpserts: null,
   // called if interim is true and remote data updates local collection
   onRemoteData: null,
   // called if interim is true and remote find throws an error
   onRemoteError: null
});

IndexedDb

Make a local database backed by IndexedDb:

import IndexedDb from 'thermodb/IndexedDb';

const db = new IndexedDb({
   /*
   Optionally define the key attribute of the documents. Will default
   to KeyUtil.getField()
   */
   key: null,
   /*
   Optionally define the KeyUtil instance to generate and manage document ids
   */
   keyUtil: null,
   /*
   Optionally define a namespace to store data
   */
   namespace: 'default',
});

// all options override db options
await db.addCollection('foo', options);

MemoryDb

Make an in-memory local database backed by a simple JavaScript object.

import MemoryDb from 'thermodb/MemoryDb';

const db = new MemoryDb({
   /*
   Optionally define the key attribute of the documents. Will default
   to KeyUtil.getField()
   */
   key: null,
   /*
   Optionally define the KeyUtil instance to generate and manage document ids
   */
   keyUtil: null,
   /*
   Optionally define the strategy when returning documents:
   - "clone" (default) will deep clone the document before returning it
   - "freeze" will prevent any modification of the returned document
   */
   safety: "clone",
});

// all options override db options
await db.addCollection('foo', options);

RemoteDb

Uses AJAX-JSON calls to an API to query a server-side database.

import RemoteDb from 'thermodb/RemoteDb';

const db = new RemoteDb({
   /*
   Optionally define the name of the client that will be passed as argument
   to the API
   */
   client: null,
   /*
   Optionally define the KeyUtil instance to generate and manage document ids
   */
   keyUtil: null,
   /*
   The API URL to request and post data
   */
   url: '',
   /*
   Optionally define a function provding the implementation to send data to
   the API server
   */
   httpClient: defaultHttpClient,
   /*
   Optionally define the options to pass to the httpClient function
   */
   httpOptions: null,
   /*
   Does the API support QuickFind?
   */
   useQuickFind: true,
   /*
   Does the API support POST request?
   */
   usePostFind: true,
});

await db.addCollection('foo', {
   /*
   Optionally define the key attribute of the documents. Will default
   to KeyUtil.getField()
   */
   key: null
});

Database instances

await db.addCollection(name, options);
// -> a Collection instance

await db.removeCollection(name);
// -> undefined

db.getCollectionNames();
// -> Array<String>

Collection instances

db.collections['foo'] === db['foo'];
// -> true

await db.foo.find(selector, options);
// -> Array<Object>

await db.foo.findOne(selector, options);
// -> Object

await db.foo.upsert(docs);
// -> Object or Array<Object>

await db.foo.remove(docKey);
// -> mixed