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

bookworm

v0.4.2

Published

Document entity framework

Downloads

24

Readme

Bookworm

Document entity framework

Wiki

Reference

Bookworm is an isomorphic library that helps organizing the application’s model layer into a document oriented structure. Through entity classes the Bookworm API allows for access and modification of sntls.Tree-based cache nodes. Instead of using absolute paths, Bookworm entities may be accessed relying only on their identifiers (keys).

The document oriented structure means that the model layer is organized into these units:

  • the document, identified by a document type and document ID
    • a DocumentKey instance identifies a document
    • the Document class implements its API
    • for application-domain document functionality, subclass Document
  • the field, identified by a document reference, and a field name
    • a FieldKey instance identifies a field
    • the Field, CollectionField, and OrderedCollectionField classes implement its API
  • the collection item, identified by the (collection) field, and an item ID
    • an ItemKey instance identifies an item
    • the Item class implements its API

Fields and collection items may have the ‘reference’ type, pointing to other entities. (Common application is the collection of references.)

Entity store

The Bookworm entity store is an in-memory datastore based on sntls.Tree.

The cache is composed of three containers:

  • bookworm.entities: Contains all entities within the application. Entity classes provide access to the contents of this container.
  • bookworm.config: Contains configuration information, most importantly field and collection item types. Look in js/cache/config.js or the non-minified distribution for the structure. The contents of this container is expected to be initialized before those parts of the application that use the Bookworm API.
  • bookworm.index: Holds user-defined indexes for lookups, search, etc. No structure is imposed on this container, content is completely up to the application implementation.

Entity keys

Entity keys, such as DocumentKey, FieldKey, and ItemKey, are evented. You may trigger and capture events on them. The library itself triggers events on keys whenever a corresponding entity is accessed (when absent) or changed.

Examples

Setting field value

‘user/1234/name’.toField().setValue(“John Smith”);

Will set the value “John Smith” on the node in bookworm.entities (instance of sntls.Tree) on the path that corresponds to the field ‘user/1234/name’. By default, this is mapped to the path ’document>documentType>documentId>fieldName’.toPath(), but the mapping may be changed by subclassing FieldKey and providing a suitable surrogate.

Checking a document’s presence

!!’user/1234’.toDocument().getSilentNode();

Will not trigger access event signaling that the node is missing. Use .getNode() to allow access events to be triggered.

Obtaining a field key from document key

var userKey = ‘user/1234’.toDocumentKey(),
    nameKey = userKey.getFieldKey(‘name’);

is the same as:

var nameKey = ‘user/1234/name’.toFieldKey();

Subscribing to document changes

'foo/bar'.toDocumentKey()
    .subscribeTo(bookworm.Entity.EVENT_ENTITY_CHANGE, function (event) {
        console.log("Entity " + event.sender + " changed.");
        console.log("Was: " + event.beforeNode);
        console.log("Now: " + event.afterNode);
    });