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 🙏

© 2026 – Pkg Stats / Ryan Hefner

ngx-s-state-api

v1.0.0

Published

API implementation with CQRS Architecture.

Readme

State class CQRS reactive based for handling cache and API requests

A fully reactive, CQRS‑style data store that binds Angular’s HttpClient to an in‑memory cache, exposing safe, immutable operations via RxJS.

Table of Contents


Description

A CQRS reactive API–bound approach that uses RxJS and Angular’s HttpClient to manage queries (selections) and commands in a single, easy‑to‑use class.

Features

  • Cache: Keeps fetched data in a private Map and exposes it reactively.

  • Queries: value$() and values$() selectors let you subscribe to single or multiple items by key.

  • Commands: post(), put(), delete() methods call the API and synchronize the cache on success.

  • Immutability: Every cache update creates a new Map so subscribers always see fresh references.

  • Builder Pattern: Configure unique key, default values, and optional auto‑reset timer via .withUniqueKey(), .withDefaultValues(), and .withResetTimer().

  • Reset: Opt‑in automatic cache reset after a configurable interval.

Getting Started

Step 1 – Install the package

npm install ngx-s-state-api

Step 2 – Import & configure

You can either instantiate State directly in a component or wrap it in an Angular service.

example.service.ts

import { Injectable } from '@angular/core';
import { State }      from 'ngx-s-state-api';
import { User }       from './models/user.model';

@Injectable({ providedIn: 'root' })
export class UserStateService {
  public readonly users = new State<User>('https://api.myapp.com', 'users')
    .withUniqueKey('userId')
    .withDefaultValues([])
    // optionally:
    // .withResetTimer(300_000) // reset cache every 5 minutes
}

Usage

Basic

Inject your service (or instantiate State directly) and subscribe:

@Component({...})
export class UserListComponent {
  users$: Observable<User[]>;

  constructor(private userState: UserStateService) {
    this.users$ = this.userState.users.values$();
    // fetch and cache
    this.userState.users.getAll().subscribe();
  }
}

Fetch single entity

this.userState.users
  .getSingle(42)
  .subscribe(user => console.log('User:', user));

Create / Update / Delete

// create
this.userState.users.post(newUser).subscribe();

// update
this.userState.users.put(updatedUser).subscribe();

// delete
this.userState.users.delete(42).subscribe();

API

Builder Methods

| Method | Signature | Description | | ------------------- | ------------------------------------- | --------------------------------------------------- | | withUniqueKey | (key: string) => this | Change the property name used as the unique key. | | withDefaultValues | (vals: T[]) => this | Seed the cache with an initial array of values. | | withResetTimer | (): this(ms: number) => this | Enable auto‑reset of cache every ms milliseconds. |

Cache Selectors

| Method | Signature | Returns | | --------- | ------------------------------------------------------------ | ------------------------------ | | value$ | (key: K) => Observable<T \| undefined> | Latest value by key | | values$ | () => Observable<T[]>(keys: K[]) => Observable<T[]> | All values or filtered by keys |

HTTP Commands

| Method | Signature | Typical REST Semantics | | ----------- | -------------------------------------------------- | --------------------------------- | | getSingle | (key: K, opts?: HttpOptions) => Observable<T> | GET /endpoint/{key} | | getAll | (opts?: HttpOptions) => Observable<T[]> | GET /endpoint | | post | (entity: T, opts?: HttpOptions) => Observable<T> | POST /endpoint → created entity | | put | (entity: T, opts?: HttpOptions) => Observable<T> | PUT /endpoint → updated entity | | delete | (key: K, opts?: HttpOptions) => Observable<void> | DELETE /endpoint/{key} |

Interval Management

| Method | Signature | Description | | ------------ | ------------ | --------------------------------------------------- | | resetTimer | () => void | Manually restart the auto‑reset timer (if enabled). |