Skip to content

Diagnostics

Status: Stable
Import: @jayoncode/storage/diagnostics

Previous: Observable · Next: Transactions

Developer report, counters, and activity ring buffer for one createStorage instance. Not on the default export — keep it off the production hot path (DEV panels / Lab).

ts
import { createStorage, createMemoryAdapter } from "@jayoncode/storage";
import { createDiagnostics } from "@jayoncode/storage/diagnostics";

const storage = createStorage({
  namespace: "app",
  adapter: createMemoryAdapter(),
});

const diagnostics = createDiagnostics(storage);

storage.set("theme", "dark");
storage.get("theme");

diagnostics.stats();
// { sets, gets, peeks, removes, clears, expired, migrated }

diagnostics.activity();
// newest-first ring buffer: set / remove / clear / expired / migrated

const report = diagnostics.report();
// namespace, entryCount, expiredCount, invalidCount, approxBytes, stats, activity

Options

OptionDefaultMeaning
activityLimit100Max activity entries (first attach only)

Notes

  • Idempotent — one session per storage instance
  • approxBytes is the sum of raw string lengths, not remaining browser quota
  • report() requires adapter.keys() (same as clear / cleanup)
  • Uses observe() internally; plain successful reads do not appear in activity (only counted in gets / peeks)
  • disconnect() stops activity listeners; counters and wraps remain

See also: Core · Observable · Maintenance

An ecosystem of independent, headless TypeScript libraries engineered for modern web development. Every package includes interactive playgrounds and documentation that evolves alongside the code.