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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@braine/quantum-query

v1.2.5

Published

A high-performance, proxy-based state management library with built-in async handling.

Readme

@braine/quantum-query

State Management at the Speed of Light.

A unified, signal-based architecture that merges Store, Actions, and API Logic into a single, high-performance ecosystem.

npm version License: MIT

⚡️ Why "Quantum"?

Existing libraries (Redux, RTK Query) behave like "Buses". They stop at every station (component) to check if someone needs to get off (re-render via O(n) selectors).

Quantum-Query behaves like a teleporter. It updates only the specific component listening to a specific property, instantly.

  • O(1) Reactivity: Powered by Atomic Signals. Zero selectors. No "Top-Down" re-renders.
  • Zero Boilerplate: No reducers, no providers, no slices, no thunks.
  • Enterprise Ecosystem: Persistence, Plugins, Deduplication, and Validation included.

📦 Installation

npm install @braine/quantum-query

🚀 Quick Start (React Hooks)

If you just want to fetch data, it works exactly like you expect.

import { useQuery } from '@braine/quantum-query';

function UserProfile({ id }) {
    const { data, isLoading } = useQuery({
        queryKey: ['user', id],
        queryFn: () => fetch(`/api/user/${id}`).then(r => r.json()),
        staleTime: 5000 // Auto-cache for 5s
    });

    if (isLoading) return <div>Loading...</div>;
    return <div>Hello, {data.name}!</div>;
}

🧠 The "Smart Model" Pattern (Advanced)

Stop splitting your logic between Redux (Client State) and React Query (Server State). Smart Models combine state, computed properties, and actions into one reactive entity.

1. Define Model

import { defineModel } from '@braine/quantum-query';

export const TodoModel = defineModel({
  // 1. Unified State
  state: {
    items: [] as string[],
    filter: 'all', 
  },

  // 2. Computed Properties (Auto-Memoized)
  computed: {
    activeCount() {
      return this.items.length;
    },
    isEmpty() {
      return this.items.length === 0;
    }
  },

  // 3. Actions (Sync + Async + Optimistic)
  actions: {
    add(text: string) {
      this.items.push(text); // Direct mutation (proxied)
    },
    async save() {
       await api.post('/todos', { items: this.items });
    }
  }
});

2. Use Model

import { useStore } from '@braine/quantum-query';
import { TodoModel } from './models/TodoModel';

function TodoApp() {
  // auto-subscribes ONLY to properties accessed in this component
  const model = useStore(TodoModel); 

  return (
    <div>
      <h1>Active: {model.activeCount}</h1>
      <button onClick={() => model.add("Ship it")}>Add</button>
    </div>
  );
}

🌐 Enterprise HTTP Client

We built a fetch wrapper that matches RTK Query in power but keeps Axios simplicity. It includes Automatic Deduplication and Retries.

import { createHttpClient } from '@braine/quantum-query';

export const api = createHttpClient({
  baseURL: 'https://api.myapp.com',
  timeout: 5000, 
  retry: { retries: 3 }, // Exponential backoff for Network errors
  
  // Auth Handling (Auto-Refresh)
  auth: {
    getToken: () => localStorage.getItem('token'),
    onTokenExpired: async () => {
        const newToken = await refreshToken();
        localStorage.setItem('token', newToken);
        return newToken; // Automatically retries original request
    }
  }
});

// data is strictly typed!
const user = await api.get<User>('/me');

🔐 Authentication (Built-in)

No more interceptors. We handle token injection and automatic refresh on 401 errors out of the box.

const client = createClient({
  baseURL: 'https://api.myapp.com',
  auth: {
    // 1. Inject Token
    getToken: () => localStorage.getItem('token'),
    
    // 2. Refresh & Retry (Auto-called on 401)
    onTokenExpired: async (client) => {
        const newToken = await refreshToken(); 
        localStorage.setItem('token', newToken);
        return newToken; // Original request is automatically retried
    },
    
    // 3. Redirect on Fail
    onAuthFailed: () => window.location.href = '/login'
  }
});

🛡️ Data Integrity (Runtime Safety)

Don't trust the backend. Validate it. We support Zod, Valibot, or Yup schemas directly in the hook.

import { z } from 'zod';

const UserSchema = z.object({
  id: z.string(),
  name: z.string(),
  role: z.enum(['admin', 'user'])
});

const { data } = useQuery({
   queryKey: ['user'],
   queryFn: fetchUser,
   schema: UserSchema // Throws descriptive error if API returns garbage
});

🔌 Plugin System (Middleware) 🆕

Inject logic into every request lifecycle (Logging, Analytics, Performance Monitoring).

import { queryCache } from '@braine/quantum-query';

queryCache.use({
    name: 'logger',
    onFetchStart: (key) => console.log('Fetching', key),
    onFetchError: (key, error) => console.error(`Fetch failed for ${key}:`, error)
});

💾 Persistence Adapter 🆕

Persist your cache to localStorage (or IndexedDB/AsyncStorage) automatically. Works offline.

import { persistQueryClient, createLocalStoragePersister } from '@braine/quantum-query/persist';

persistQueryClient({
    queryClient: queryCache,
    persister: createLocalStoragePersister(),
    maxAge: 1000 * 60 * 60 * 24 // 24 hours
});

📚 Documentation


🆚 Comparison

| Feature | RTK Query | TanStack Query | Quantum-Query | | :--- | :--- | :--- | :--- | | Architecture | Redux (Store + Slices) | Observers | Atomic Signals ✅ | | Boilerplate | High (Provider + Store) | Medium | Zero ✅ | | Re-Renders | Selector-based (O(n)) | Observer-based | Signal-based (O(1)) ✅ | | Smart Models | ❌ (Requires Redux) | ❌ | Built-in ✅ | | Bundle Size | ~17kb | ~13kb | ~3kb ✅ | | Deduplication | Yes | Yes | Yes ✅ | | Persistence | redux-persist | Experimental | Built-in First Class ✅ |


License

MIT