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

simple-state-model-graphql-api

v0.1.0

Published

Simple State Model — GraphQL API layer: typeDefs and resolvers exposing states as queries, patch mutations and mutation/subscriber subscriptions

Readme

simple-state-model-graphql-api

The GraphQL layer over a simple-state-model StateModel. It exposes states as queries, patch mutations, and live subscriptions, and tracks who is subscribed to each state.

Install

npm install simple-state-model-graphql-api graphql @graphql-tools/schema

graphql and @graphql-tools/schema are peer dependencies so the host application controls the versions. If you assemble the schema yourself, use stateGraphQLTypeDefs and stateGraphQLResolvers and skip @graphql-tools/schema entirely.

Usage

import { StateModel } from "simple-state-model";
import { StateSubscriptionModel, stateGraphQLSchema } from "simple-state-model-graphql-api";

const stateModel = new StateModel({ logger: console });

const stateSubscriptionModel = new StateSubscriptionModel({
    stateModel: stateModel,
    logger: console
});

const { schema } = stateGraphQLSchema(stateSubscriptionModel, console);

Serve schema with any transport that supports subscriptions — graphql-http-ws-server, for example. Subscription resolvers return an async iterator, so no pubsub is needed.

Composing the schema yourself

import { makeExecutableSchema } from "@graphql-tools/schema";
import { stateGraphQLTypeDefs, stateGraphQLResolvers } from "simple-state-model-graphql-api";

const schema = makeExecutableSchema({
    typeDefs: [stateGraphQLTypeDefs, myOtherTypeDefs],
    resolvers: [stateGraphQLResolvers(stateSubscriptionModel, console), myOtherResolvers]
});

The API

type Query {
    state(provider_id: ID, state_id: ID!): State
    state_subscribers(provider_id: ID, state_id: ID!, options: StateSubscribersOptionsInput): StateSubscribers
}

type Mutation {
    state_patch(provider_id: ID, state_id: ID!, patch: JSON!, options: StateMutationOptionsInput): StateMutation
    update_subscriber(subscriber_id: ID!, subscriber: StateSubscriberInput!): StateSubscriber
}

type Subscription {
    state_mutation(provider_id: ID, state_id: ID!, options: StateMutationSubscriptionOptionsInput): StateMutationUpdate
    state_subscribers(provider_id: ID, state_id: ID!, options: StateSubscribersOptionsInput): StateSubscribers
}

provider_id selects a provider registered on the StateModel; omitting it uses the model's default. patch is an RFC6902 patch array.

state_mutation sends the current value first, as a root replace patch with reset: true, then streams each subsequent patch. Set exclude_source to your own source ID so your own writes are not echoed back to you.

Subscribers

StateSubscriptionModel keeps a StateSubscriberManager per state. Each state_mutation subscription registers a StateSubscriber, which starts anonymous and can be named later with update_subscriber — that is how a presence list ("who is editing this element") is built.

Subscribers to state_subscribers are registered with count: false, so watching the presence list does not add you to it. A manager destroys itself when its last subscriber leaves.

Related packages