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

@adorsys-gis/storage

v1.0.3

Published

A service module for data storage and retrieval in Progressive Web Apps (PWAs) using IndexedDB, LocalStorage, and SessionStorage. This library provides an interface for efficient asynchronous storage of structured data, designed to meet the needs of moder

Downloads

290

Readme

storage

This library was generated with purpose of building a service module for data storage and retrieval.

Considering the nature of PWAs been browser applications, access to device storage cannot be done directly. PWAs thought acting like native applications can only make use of browser storage for any relative use case. This said, our goal here is to provide a default interface module and implementation that writes to the browser storage option we'ld have chosen. As any other web application, Here are some of the most revelant data storage options for PWAs:

  1. LocalStorage: localStorage allows you to store key-value pairs in the client's web browser. It's synchronous, meaning it can potentially block the main thread, so it's best suited for small amounts of data (usually limited to 5-10 MB per domain). Data stored in localStorage persists even after the browser is closed and reopened.

  2. SessionStorage: sessionStorage is similar to localStorage but scoped to the current session. Data stored in sessionStorage is cleared when the browser tab is closed. Like localStorage, it's synchronous and suitable for storing small amounts of data.

  3. IndexedDB: IndexedDB is a low-level API for client-side storage of significant amounts of structured data. It's designed for storing larger amounts of data asynchronously, making it suitable for more complex applications. IndexedDB supports transactions and indexing, allowing for efficient querying and retrieval of data.

These three options encompass a broad spectrum of data storage use cases in PWAs, ranging from structured data storage with IndexedDB to basic key-value pair storage with LocalStorage and SessionStorage. IndexedDB emerges as the most suitable option for our needs, given its capacity for structured data, larger storage capacity, transaction support, and indexing capabilities, but most importantly, its asynchronous nature.

Compatibility

The compatibility graph of indexedDB can be found at the following address https://developer.mozilla.org/en-US/docs/Web/API/indexedDB#browser_compatibility

Usage

To use this libray in the app, first import

import { StorageFactory } from '@wallet/storage';
import { WalletDBSchema } from './schema';

// open a new database named `storage` following the `WalletDBSchema` schema
const storageFactory = new StorageFactory<WalletDBSchema>('storage', 1, {
  upgrade(db, oldVersion, newVersion, transaction, event) {
    //creating a new store `test_store`
    db.createObjectStore('test_store');
  },
  blocked(currentVersion, blockedVersion, event) {
    // …
  },
  blocking(currentVersion, blockedVersion, event) {
    // …
  },
  terminated() {
    // …
  },
});

// schema.d.ts
import type { DBSchema } from 'idb';

interface WalletDBSchema extends DBSchema {
  test_store: {
    key: string;
    value: string;
  };
}

Running unit tests

Run npm run test to execute the unit tests via Jest.

Building the library

Run npm run build to build the library