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

@varasto/storage

v5.0.0

Published

Type definitions for Varasto key-value storage

Downloads

38

Readme

@varasto/storage

npm

Type definitions for Varasto JSON key-value store.

Installation

$ npm install --save @varasto/storage

Usage

This package provides abstract base class for Varasto storage implementations as well as error classes to indicate that an item identifier (either namespace or key) does not pass the slug validation or that an item being updated does not exist.

Usually you don't need to use or install this package directly, but use an storage implementation package instead. Below is an list of storage implementations for different use cases.

| Name | Description | | --------------------- | ----------------------------------------- | | cache-storage | Acts as an cache for another storage. | | fs-storage | Stores data persistently to hard disk. | | memory-storage | Stores data to memory. | | multi-storage | Stores data to multiple other storages. | | postgres-storage | Stores data to PostgreSQL database. | | remote-storage | Stores data to remote server. | | redis-storage | Stores data to Redis. | | single-file-storage | Stores data to a single file. | | sqlite-storage | Stores data to SQLite database. | | validator-storage | Acts as an validator for another storage. | | web-storage | Stores data to browser storage. |

Storing items

set<T extends JsonObject>(
  namespace: string,
  key: string,
  value: T
): Promise<void>

Attempts to store an item identified by namespace and key. Returned promise will fail if an I/O error occurs while storing the item.

Retrieving items

get<T extends JsonObject>(
  namespace: string,
  key: string
): Promise<T | undefined>

Attempts to retrieve an item identified by namespace and key. Returned promise will either resolve into the value, or undefined if item with the given identifier does not exist. The promise will fail if an I/O error occurs while retrieving the item.

Removing items

delete(
  namespace: string,
  key: string
): Promise<boolean>

Attempts to remove an item identified by namespace and key. Returned promise will resolve into a boolean value which tells whether an value with the given identifier existed or not. The promise will fail if an I/O error occurs while removing the item.

Searching for entries

find<T extends JsonObject>(
  namespace: string,
  callback: (value: T, key: string) => boolean
): Promise<[string, T | undefined]>

Returns the first entry from specified namespace to which given callback function returns true for, or undefined if the callback function does not return true for any entry in the namespace.

The promise will fail if an I/O error occurs, or if given namespace is not a valid slug.

Updating already existing item

update<T extends JsonObject>(
  namespace: string,
  key: string,
  value: Partial<T>
): Promise<T>

Attempts to update an already existing item identified by namespace and key by shallowly merging with the given new data. Returned promise will resolve into the new value, or will fail if no such item exists.

Testing whether an item exists or not

has(
  namespace: string,
  key: string
): Promise<boolean>

Returns true if an item identified by namespace and key exists in the storage, or false if it doesn't. The promise will fail if an I/O error occurs while testing whether item exists or not.

Listing keys stored in a namespace

keys(
  namespace: string
): AsyncGenerator<string>

Lists keys of all items stored under an namespace. The promise will fail if an I/O error occurs while listing the keys.

Listing values stored in a namespace

values<T extends JsonObject>(
  namespace: string
): AsyncGenerator<T>

Lists all items stored under an namespace. The promise will fail if an I/O error occurs.

Listing entries stored in a namespace

entries<T extends JsonObject>(
  namespace: string
): AsyncGenerator<[string, T]>

Lists all items stored under an namespace, with the keys they are identified by. The promise will fail if an I/O error occurs.

Filtering entries stored in a namespace

filter<T extends JsonObject>(
  namespace: string,
  callback: (value: T, key: string) => boolean
): AsyncGenerator<[string, T]>

Goes through all entries from the given namespace, returning ones for which the given callback functions returns true for.

The promise will fail if an I/O error occurs, or if given namespace is not a valid slug.

Map operation

map<T extends JsonObject, U extends JsonObject>(
  namespace: string,
  callback: (value: T, key: string) => U
): AsyncGenerator<[string, U]>

Goes through all entries from the given namespace, passing them to the given callback function and returning whatever the callback function returned.

The promise will fail if an I/O error occurs, or if given namespace is not a valid slug.