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

supastash

v0.1.48

Published

Offline-first sync engine for Supabase in React Native using SQLite

Readme

Supastash

npm version

Offline-First Sync Engine for Supabase + React Native

Supastash syncs your Supabase data with SQLite — live, offline, and conflict-safe. No boilerplate. Built for React Native and Expo.


📚 Documentation

Full Docs
Getting Started Guide


✨ Features

  • 🔁 Two-way sync (Supabase ↔ SQLite)

  • 💾 Offline-first querying with local cache

  • Realtime updates (INSERT, UPDATE, DELETE)

  • 🔌 Compatible with all major SQLite clients:

    • expo-sqlite
    • react-native-nitro-sqlite
    • react-native-sqlite-storage (beta)
  • 🧠 Built-in:

    • Conflict resolution
    • Sync retries
    • Batched updates
    • Row-level filtering
    • Staged job processing

📦 Installation

npm install supastash

➕ Required Peer Dependencies

npm install @supabase/supabase-js \
             @react-native-community/netinfo \
             react \
             react-native

🧱 Choose a SQLite Adapter

Choose only one, based on your stack:

# Expo (most common)
npm install expo-sqlite

# Bare RN with better speed
npm install react-native-nitro-sqlite

# Classic RN SQLite (beta)
npm install react-native-sqlite-storage

Match with sqliteClientType: "expo", "rn-nitro", or "rn-storage"


⚙️ Quick Setup

1. Configure Supastash

// lib/supastash.ts
import { configureSupastash, defineLocalSchema } from "supastash";
import { supabase } from "./supabase";
import { openDatabaseAsync } from "expo-sqlite"; // or your adapter

configureSupastash({
  supabaseClient: supabase,
  dbName: "supastash_db",
  sqliteClient: { openDatabaseAsync },
  sqliteClientType: "expo",

  onSchemaInit: () => {
    defineLocalSchema("users", {
      id: "TEXT PRIMARY KEY",
      name: "TEXT",
      email: "TEXT",
      created_at: "TIMESTAMP",
      updated_at: "TIMESTAMP",
    });
  },

  debugMode: true,
  syncEngine: {
    push: true,
    pull: false, // enable this if using filters or RLS
  },
  excludeTables: {
    push: ["daily_reminders"],
    pull: ["daily_reminders"],
  },
});

2. Initialize Once

// App.tsx or _layout.tsx
import "@/lib/supastash"; // triggers init
import { useSupatash } from "supastash";

export default function App() {
  const { dbReady } = useSupatash();
  if (!dbReady) return null;
  return <Stack />;
}

🧠 Optional: Zustand Auto-Hydration

To auto-update Zustand stores when local data changes, listen for refresh events:

supastashEventBus.on("supastash:refreshZustand:orders", hydrateOrders);

Use this in a hook like useHydrateStores() to stay in sync without polling. 👉 Read Docs


🔁 useSupastashData (with Realtime)

const { data, groupedBy } = useSupastashData("orders", {
  filter: { column: "user_id", operator: "eq", value: userId },
  extraMapKeys: ["status"],
  realtime: true, // Default: true
});
  • ✅ Auto-syncs with Supabase Realtime
  • ✅ Keeps your UI in sync automatically
  • ✅ Ideal for dashboards, chat, shared data

🛡️ Use Filters for Pull Syncing

If you use pull: true, you must define filters per table:

useSupastashFilters({
  orders: [{ column: "shop_id", operator: "eq", value: activeShopId }],
  inventory: [{ column: "location_id", operator: "eq", value: location }],
});

Without filters or RLS, Supastash may try to pull full tables — which could lead to empty results or large sync payloads.


🚨 Important Notes

  • Your Supabase tables must have:

    • A primary key id (string or UUID)
    • timestamptz columns for created_at, updated_at, and deleted_at
  • Run this SQL in Supabase to allow schema reflection:

create or replace function get_table_schema(table_name text)
returns table(column_name text, data_type text, is_nullable text)
security definer
as $$
  select column_name, data_type, is_nullable
  from information_schema.columns
  where table_schema = 'public' and table_name = $1;
$$ language sql;

grant execute on function get_table_schema(text) to anon, authenticated;

🧪 Example: useSupatashData

import { useSupatashData } from "supastash";

const { data: orders } = useSupatashData("orders", {
  filter: { column: "user_id", operator: "eq", value: userId },
});

🔄 How Sync Works

  • Tracks rows using updated_at, deleted_at, and created_at
  • Batches changes in background and retries failed ones
  • Local cache backed by Supabase
  • Runs pull/push jobs efficiently using staged task pipelines

🧠 Advanced Querying (Optional)

Supastash includes a built-in query builder:

await supastash
  .from("orders")
  .update({ status: "delivered" })
  .syncMode("localFirst") // localOnly, remoteOnly also available
  .run();

🔧 API Docs


🤝 Contributing

PRs are welcome! Please write clear commit messages and add tests when relevant.


📜 License

MIT © Ezekiel Akpan


💬 Need Help?

Open an issue or reach out on Twitter/X