Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

jstor

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jstor

jstor nodejs

  • 1.0.2
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
1
decreased by-87.5%
Maintainers
1
Weekly downloads
 
Created
Source

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

Keywords

FAQs

Package last updated on 30 May 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc