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

@blastjs/minimongo

v0.1.0

Published

Meteor's client-side datastore: a port of MongoDB to Javascript

Downloads

2

Readme

Minimongo

Source code of released version | Source code of development version


minimongo is reimplementation of (almost) the entire MongoDB API, against an in-memory JavaScript database. It is like a MongoDB emulator that runs inside your web browser. You can insert data into it and search, sort, and update that data. This is great if you like the MongoDB API (which you may already be using on the server), need a way to store data on the client that you've fetched and are using to render your interface, and want to use that familiar API.

Minimongo is used as a temporary data cache in the standard Meteor stack, to learn more about mini-databases and what they can do, see the project page on www.meteor.com

Internals

Minimongo implements the following features, mirroring the MongoDB features:

  • Selectors
  • Modifiers
  • Fields projections
  • Querying with sort and limit
  • ObjectID generation
  • Geo-positional operator $near with GeoJSON parsing

Internally, all documents are mapped in a single JS object from _id to the document. Besides this mapping, Minimongo doesn't implement any types of secondary indexes.

Also, currently Minimongo doesn't implement any aggregation features. The full list of incompatible features can be found in the NOTES file.

Besides the MongoDB features, Minimongo implements the following for a better integration with the Meteor stack:

  • observe and observeChanges APIs, notification callbacks when the result of a query changes
  • integration with Meteor's Tracker
  • Meteor's Publish a cursor interface _publishCursor, that results into an observe call
  • Meteor's interface of pauseObservers and resumeObservers, for client-side caches (allow latency compensation to change multiple objects at once w/o a flicker)
  • In addition to the previous point, saveOriginals and retrieveOriginals are used to revert the local changes
  • additional analysis functions for Meteor's server-side Oplog Observe Driver (only loaded for the server-side):
    • can this modifier change the result of this selector if the document didn't match before
    • can the sort order change after applying this modifier (for a given selector)
    • what is a combined projection for these selector, sorter and projection
  • find accepts a literal function instead of a selector, and a comparison function for sorting

saveOriginals/retrieveOriginals & pauseObserver/resumeObservers

This part of the implementation is very important for a smooth Optimistic UI experience (also called "Latency Compensation") avoiding an extra flicker.

Let's review the usual Optimistic UI flow:

  • User triggers an interaction on the client
  • The simulation applies some mutations to the state locally
  • The RPC is fired to be executed on the server
  • After some time, the RPC returns with the result
  • After some more time, RPC returns an "updated" message (on DDP level), meaning that all the changes from RPC have persisted
  • At this point we know, that all the actual changes from the server are synced, we can throw away the simulated mutations (preserving the real changes from the server)

To implement the last step, Minimongo implements the following:

  • When a simulation starts, saveOriginals is called, to take a snapshot of the state before the update. Internally, it is implemented in a more efficient copy-on-write style.
  • After the simulation, wait, to get all the real changes from the server.
  • When the server is done with giving us new changes, we apply all the new changes and throw away all the simulated changes (with retrieveOriginals).
  • All massive replacements happen in between pauseObservers and resumeObservers calls, so any user code (such as Blaze) sees the whole change in one tick (helps to avoid the flicker).