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

jstor

v1.0.2

Published

jstor nodejs

Downloads

10

Readme

JSTOR

! Under construction !

Jstor is an extremely simple ODM (Object Document Mapping), mainly focussed on JSON storage...

Install

npm install jstor

Jstor can be either used in combination with

  • MongoDb

    npm i jstor jstor-mongodb

  • DocumentDb

    npm i jstor jstor-mongodb

  • DynamoDb

    npm i jstor jstor-dynamodb

  • Redis

    npm i jstor jstor-redis

  • S3

    npm i jstor jstor-s3

  • local filesystem

Usage

Constructor

General options

import Store from "jstor";
const store = new Store({
    strategy: File/Memory/MongoDb/DynamoDb/Redis/S3(strategyOptions),
    cacheOptions: {
      keys: {
        maxAge: seconds how long the keys (index) can get kept in memory
      },
      files: {
        maxAge: seconds how long the documents themselves can remain in memory
      }
    },
    failOptions: {
      get: 'silent' || 'warning' || 'error',
      set: 'silent' || 'warning' || 'error',
      remove: 'silent' || 'warning' || 'error',
      keys: 'silent' || 'warning' || 'error',
      find: 'silent' || 'warning' || 'error',
      ...
      always: 'silent' || 'warning' || 'error'
    }
})

Memory

import Store, {Memory} from "jstor";
const store = new Store({
    strategy: Memory()
})

Local file system

import Store, {File} from "jstor";
const store = new Store({
    strategy: File({
      directory: './mystoragedir'
    })
})

MongoDb / DocumentDb

import Store from "jstor";
import MongoDb from "jstor-mongodb";
const store = new Store({
    strategy: MongoDb({
        uri: 'mongodb://127.0.0.1:27017',
        dbName: 'jstorTestDb',
        collection: 'jstorTestCollection',
        maxBatchSize: 20 //whenever elements are batch fetched, take max 2 only per batch (default is 50)
    })
})

Redis

import Store from "jstor";
import Redis from "jstor-redis";
const store = new Store({
    strategy: Redis({
        url: 'redis://127.0.0.1:6379',
        keyPrefix: 'jstor' (only take keys into account with this prefix)
    })
})

S3

import Store from "jstor";
import S3 from "jstor-s3";
const store = new Store({
    strategy: S3({
        bucket: 'jstor-s3-sample',
        region: 'eu-west-1',
        credentials: {
           accessKeyId: process.env.ACCESS_KEY,
           secretAccessKey: process.env.ACCESS_KEY_SECRET
        },
        keyPrefix: 'jstor/'
    })
})

DynamoDb

import Store from "jstor";
import DynamoDb from "jstor-dynamodb";
const store = new DynamoDb({
    strategy: S3({
        table: 'jstor-dynamodb-test',
        region: 'eu-west-1',
        credentials: {
           accessKeyId: process.env.ACCESS_KEY,
           secretAccessKey: process.env.ACCESS_KEY_SECRET
        }
    })
})

Methods

Get document

const jsonDoc = await store.get(key)

Save document

const jsonDoc = await store.get(key);
await jsonDoc.save();
//or
await store.save(key, jsonValue);

Delete document

const jsonDoc = await store.get(key);
await jsonDoc.remove();
//or
await store.remove(key);

Get keys

const keys = await store.keys();

Get a given number of documents (either from the start or from the end)

const docs = await store.all(startIndex, numberOfDocuments, booleanReverse);

Get a batch of documents matching the given keys

const docs = await store.batch([keys]);

Migrate store (move all documents from one storage system to another)

sourceStore.migrateTo(targetStore)

Migrate document

const doc = await sourceStore.get(key);
await doc.migrateTo(targetStore);

Find (only supported on MongoDb, for now)

const docs = await store.find(mongoDbSearchDoc);

FindOne (only supported on MongoDb, for now)

const doc = await store.findOne(mongoDbSearchDoc);

CRU operations within a JSON document

const doc = await store.get(key);

doc.set('address.street', 'Oudstrijdersstraat');
//doc.set(xpath, value)

doc.get('address.street');
//doc.get(key)
//returns 'Oudstrijdersstraat'

doc.json()
//returns the full json structure of the page
doc.json({foo: 'bar'})
//sets the full json document into the page
doc.json(`{"foo":"bar"}`)
//parses the string value to JSON

await doc.save();
//write changes to the storage system