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

@sap-ux/store

v0.9.3

Published

NPM module for storing persistent data

Downloads

916,806

Readme

@sap-ux/store

This is a store for persistent data in Fiori tools.

Usage

Add @sap-ux/store to your projects package.json to include it in your module.

API

The main API to this module is getService(). Given an optional logger and an entity name, this function will return an instance of a class with the following methods:

interface Service<Entity, EntityKey> {
    read(key: EntityKey): Promise<Entity | undefined>;
    write(entity: Entity): Promise<Entity | undefined>;
    delete(entity: Entity): Promise<boolean>;
    getAll(): Promise<Entity[] | []>;
}

Currently, 'system', 'telemetry' and 'api-hub' are the only supported entities. Support for 'user' may be added in the future. Unsupported entity names will result in an error being thrown.

The store supports storing values in operating system specific secure storage, like keychain on MacOS or secure storage on Windows. To disable access to secure storage, environment variable FIORI_TOOLS_DISABLE_SECURE_STORE can be set.

Recommended way to add support for a new entity

(Please read the code for the system entity starting here for a concrete example: ./src/services/backend-system.ts)

Add a service

This needs to needs to implement the Service<Entity, EntityKey> interface shown above. This is what the external clients of the API will use.

Optionally, you may need to migrate data if the underlying schema changes. You may choose to do this as a single-shot one-off procedure or do it on the fly when any of the service methods are accessed. Code for an example migration service (no-op).

Add a data provider

It is recommended that the DataProvider interface be used to create a data provider for the new entity. This class' concern will purely be managing the persistence of the entity. The service interface may have other concerns like the data migration step in the system store.

Recommended interfaces to implement:

interface DataProvider<E, K extends EntityKey<E>> {
    read(key: K): Promise<E | undefined>;
    write(entity: E): Promise<E | undefined>;
    delete(entity: E): Promise<boolean>;
    getAll(): Promise<E[] | []>;
}

Implement the static side of the interface for the constructor:

interface DataProviderConstructor<E, K extends EntityKey<K>> {
    new (logger: Logger): DataProvider<E, K>;
}

Data providers can delegate to data accessors.

Data accessors

The following data accessors are currently available:

Filesystem accessor

This stores the entities on the filesystem inside the Fiori Tools directory (Uses: getFioriToolsDirectory() from @sap-ux/common-utils)

Hybrid accessor

This stores information on the filesystem and the system's secure store.

Add an entity

Entity classes are simple. They don't do much other than list the properties that will be serialized. @serializable and @sensitiveData are two annotations that are understood by the hybrid store.

The system entity for example looks like this:

class BackendSystem {
    @serializable public readonly name: string;
    @serializable public readonly url: string;
    @serializable public readonly client?: string;
    @sensitiveData public readonly serviceKeys?: unknown;
    @sensitiveData public readonly username?: string;
    @sensitiveData public readonly password?: string;
    ...
    ...
}

Systems that are constructed using new BackendSystem({...}) will have the properties correctly persisted in the relevant medium by the hybrid data accessor.

Every entity needs an EntityKey implementing this interface:

interface EntityKey<T> {
    getId: () => string;
}