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

feathers-offline-log

v0.0.1

Published

Performant, persistent client-side log

Downloads

6

Readme

feathers-offline-log

Greenkeeper badge

Build Status Code Climate Test Coverage Dependency Status Download Status

| Performant, persistent client-side transaction log.

Browser client logs are kept in (preferred order) IndexedDB, WebSQL or localStorage. Log entries are added in an efficient manner, whether the log is small or very large. JavaScript objects are also handled in an efficient manner.

ProTip: Used for feathers-offline's optimistic mutation log, which is updated while the client is disconnected.

The cache stringifies an added object just once, eliminating the multiple stringifications of alternative designs. The cache bundles logs into chunks, whose maximum size you can specify (0.5 meg default). This avoids both the repetitive persisting of large blobs and the inefficiencies of writing individual log items.

Installation

npm install feathers-offline-log --save

Documentation

  • cache = new Cache(storageHandler, options) - Configure a new cache.
    • storageHandler (required, module) - Module responsible for persistence.
      • /browserStorage - Browser support. See example below.
    • options (optional) - Options for the cache.
      • chunkMaxLen (optional, number, default 500 000) - Maximum chunk size in chars.
      • sep (optional, char, default ',') - Separator char between log entries. Objects are always separated with ','.
  • cache.config(options) - Configure the storage handler for the cache. The options depend on the storage handler.
    • browserStorage - See options for localforage
      • name (optional, string, default 'offline') - Namespace for storage. Typically the app name.
      • collection (optional, string, default 'log') - Namespace within name. Typically the name of the collection or table name.
  • cache.add(str) - Add str to the logs.
  • cache.addObj(obj) - Stringifyy obj and add it to the logs.
  • cache.getOldestChunk() - Returns the oldest chunk of logs. If it consists solely of added objects, then JSON.stringify('[' + chunk + ']') will return an array of POJO.
  • cache.removeOldestChunk() - Remove the oldest chunk from the log.
  • cache.clear() - Remove all chunks.

Example

const browserStorage = require('feathers-offline-log/browser-storage');
const Cache = require('feathers-offline-log');

const cache = new Cache(browserStorage, { chunkMaxLen: 500000 }); // logs stored in 0.5 meg chunks
cache.config({ name: 'myApp', collection: 'people' })
  .then(() => cache.addObj(obj1))
  .then(() => cache.addObj(obj2))
  .then(() => cache.addObj(obj3))

  .then(() => cache.getOldestChunk()) 
  .then(chunk => console.log(JSON.parse(`[${chunk}]`))) 
  .then(() => cache.removeOldestChunk()) 

The included browser storage abstraction for localforage may be used standalone.

const browserStorage = require('feathers-offline-log/browser-storage');

browserStorage.config({ name: 'myApp', collection: 'people' })
  .then(() => browserStorage.setItem('john', ' ... ')) // full key is myApp_people/john
  .then(() => browserStorage.getItem('john'))
  .then(str => browserStorage.removeItem('john'))
  .then(() => browserStorage.clear())
  .then(() => browserStorage.length())
  .then(numb => browserStorage.keys())
  .then(array => browserStorage.iterate((value, key, iterationNumber) => { ... }));

License

Copyright (c) 2017

Licensed under the MIT license.