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

@aegiondynamic/async-storage-sync

v1.0.13

Published

Offline-first data layer for React Native with local-first storage and automatic sync

Readme

@aegiondynamic/async-storage-sync

Offline-first queue for React Native with type-safe payloads and automatic sync.

Install

npm install @aegiondynamic/async-storage-sync @react-native-async-storage/async-storage @react-native-community/netinfo

Quick Start

import { initSyncQueue, getSyncQueue } from '@aegiondynamic/async-storage-sync';

await initSyncQueue({
  driver: 'asyncstorage',
  serverUrl: 'https://api.example.com',
  credentials: { Authorization: 'Token abc123' },
  endpoint: '/submit',
  idResolver: (item) => String(item.id ?? ''),
  autoSync: true,
  syncOnSave: true,
});

type Submission = {
  id: string;
  formId: string;
  name: string;
};

const store = getSyncQueue().asType<Submission>();

const saved = await store.save('submissions', {
  id: 'sub_1',
  formId: 'form_a',
  name: 'John',
});

console.log(saved.meta.id);     // internal id used by queue
console.log(saved.data.name);   // your payload

const result = await store.flushWithResult();
console.log(`Synced: ${result.synced}, Failed: ${result.failed}`);

If queue access may happen during startup (for example from screens/services), use:

import { ensureInitialized } from '@aegiondynamic/async-storage-sync';

await ensureInitialized({
  driver: 'asyncstorage',
  serverUrl: 'https://api.example.com',
  credentials: { Authorization: 'Token abc123' },
});

What Changed

  • Generic API: save<T>(), getAll<T>(), getById<T>(), flushWithResult<T>().
  • Metadata is separated from payload in storage and reads/writes.
  • Identity is configurable with idResolver.
  • getSyncQueue() is non-generic and safe on a singleton; use asType<T>() for typed access.

Configuration

initSyncQueue({
  driver: 'asyncstorage',
  serverUrl: 'https://api.example.com',
  credentials: {
    Authorization: 'Token abc123',
    'x-api-key': 'my-custom-key',
  },

  endpoint: '/submit',
  autoSync: true,
  syncOnSave: true,
  autoSyncCollections: ['submissions'],

  onSyncSuccess: 'delete',
  ttl: 7 * 24 * 60 * 60 * 1000,
  duplicateStrategy: 'append',

  idResolver: (item) => String(item.id ?? ''),
  payloadTransformer: (payload) => payload,
});

API

Setup

initSyncQueue(config)
isInitialized()
ensureInitialized(config?)
getSyncQueue()
getTypedSyncQueue<T>()

Typed access

type Invoice = { invoiceNo: string; amount: number };

const store = getSyncQueue().asType<Invoice>();

await store.save('invoices', { invoiceNo: 'INV-1', amount: 100 });
const all = await store.getAll('invoices');
const one = await store.getById('invoices', all[0].meta.id);

Using the helper export:

import { getTypedSyncQueue } from '@aegiondynamic/async-storage-sync';

type Invoice = { invoiceNo: string; amount: number };
const store = getTypedSyncQueue<Invoice>();

Record shape

type StoredRecord<T> = {
  meta: {
    id: string;
    ts: number;
    synced: 'pending' | 'synced' | 'failed';
    type: string;
    retries: number;
  };
  data: T;
};

Sync

const store = getSyncQueue().asType<{ amount: number }>();

await store.flushWithResult();
await getSyncQueue().syncWithResult('invoices');
await getSyncQueue().syncManyWithResult(['invoices', 'receipts']);
await getSyncQueue().syncById('invoices', 'record-id');

Events

const queue = getSyncQueue();

queue.onSynced((item) => {
  console.log('Synced queue item:', item.id);
});

queue.onAuthError((statusCode, item) => {
  console.log('Auth error:', statusCode, item.recordId);
});

queue.onStorageFull(() => {
  console.log('Storage full');
});

Notes

  • payloadTransformer receives only your payload (record.data), not metadata.
  • Queue payload and collection records are persisted across app restarts.
  • Max 5 retries per record with exponential backoff for 5xx errors.
  • getSyncQueue() throws if not initialized yet; use ensureInitialized(config) for boot-safe access.
  • ensureInitialized() without config works only after first init; otherwise pass config.

Sync Modes

  • autoSync: sync on connectivity/app-open signals (NetInfo-driven behavior).
  • syncOnSave: schedule immediate debounced best-effort sync after each save().
  • Use both for most apps: autoSync handles reconnects, syncOnSave reduces delay when already online.