Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

unstorage

unjs3.8mMIT1.14.4TypeScript support: included

Universal Storage Layer

readme

💾 Unstorage

npm version npm downloads Codecov bundle License

Unstorage provides an async Key-Value storage API with conventional features like multi driver mounting, watching and working with metadata, dozens of built-in drivers and a tiny core.

👉 Documentation

Features

  • Designed for all environments: Browser, NodeJS, and Workers
  • Lots of Built-in drivers
  • Asynchronous API
  • Unix-style driver mounting to combine storages
  • Default in-memory storage
  • Tree-shakable utils and tiny core
  • Auto JSON value serialization and deserialization
  • Binary and raw value support
  • State snapshots and hydration
  • Storage watcher
  • HTTP Storage with built-in server

Usage

Install unstorage npm package:

# yarn
yarn add unstorage

# npm
npm install unstorage

# pnpm
pnpm add unstorage
import { createStorage } from "unstorage";

const storage = createStorage(/* opts */);

await storage.getItem("foo:bar"); // or storage.getItem('/foo/bar')

👉 Check out the the documentation for usage information.

Nightly release channel

You can use the nightly release channel to try the latest changes in the main branch via unstorage-nightly.

If directly using unstorage in your project:

{
  "devDependencies": {
    "unstorage": "npm:unstorage-nightly"
  }
}

If using unstorage via another tool in your project:

{
  "resolutions": {
    "unstorage": "npm:unstorage-nightly"
  }
}

Contribution

  • Clone repository
  • Install dependencies with pnpm install
  • Use pnpm dev to start jest watcher verifying changes
  • Use pnpm test before pushing to ensure all tests and lint checks passing

License

MIT

changelog

Changelog

All notable changes to this project will be documented in this file. See standard-version for commit guidelines.

v1.14.4

compare changes

🩹 Fixes

  • s3: Use / as separator (#545)

❤️ Contributors

  • Pooya Parsa (@pi0)

v1.14.3

compare changes

🩹 Fixes

  • types: Allow passing generic to untyped storage (#543)

❤️ Contributors

v1.14.2

compare changes

🩹 Fixes

  • db: Escape mysql queries (#542)

📖 Documentation

  • cloudflare: Fix example comments (#534)

📦 Build

  • Remove extra cli deps (#538)

❤️ Contributors

v1.14.1

compare changes

🩹 Fixes

  • types: Fallback to StorageValue for un-typed stores (#532)

📖 Documentation

  • Add driver name to each usage section (#533)

📦 Build

  • Fix netlify options type (756fee4)

❤️ Contributors

v1.14.0

compare changes

🚀 Enhancements

  • Add upstash driver (#500)
  • cloudflare-r2-binding: Allow specify raw type (#519)
  • indexedb: Support raw storage (#520)
  • Add experimental db0 driver (#476)
  • Add vercel-blob driver (#472)
  • Add deno-kv driver (#233)
  • deno-kv-node driver (#521)
  • Typed storage interface (#509)
  • Add s3 driver (#361)
  • Add uploadthing driver (#390)
  • Support raw conversion in envs without Buffer (#364)

🩹 Fixes

  • cloudflare-r2-binding: Return null for non existing getItem (fb8e00e)
  • upstash: Drop base prefix from keyKeys (8711a94)
  • Capture stacktrace of thrown errors (c704fef)
  • http: Return arrayBuffer for getItemRaw (#527)
  • localstorage: Consider base for clear and getKeys (#529)

💅 Refactors

  • More strict type checks (c8ed5cf)
  • cloudflare-kv-http: Use new bulk/delete api for clear() (0231775)
  • Reuse localstorage logic for session-storage (#530)

📖 Documentation

  • Add notes about nightly channel (de31652)
  • netlify: Add consistency option (#525)
  • cloudflare: Add note about r2 over http (1f2d444)

📦 Build

  • Update unbuild to v3 (1528c3c)
  • Generate drivers meta (#526)

🏡 Chore

✅ Tests

  • Add missing await (7730923)
  • cloudflare: Use wrangler dev proxy (#518)
  • Enable cloudflare-r2-binding tests (0c4d9fd)
  • upstash, vercel-blob: Use random base (65a10cc)
  • cloudflare-kv-http: Use sandbox tests (8043897)
  • Add retry (5ab4afd)
  • Lazy init driver for conditional tests (33d90a9)
  • s3: Skip if not setup (ce9685e)

🤖 CI

❤️ Contributors

v1.13.1

compare changes

🩹 Fixes

  • Revert chokidar to v3 (#502)

❤️ Contributors

  • Pooya Parsa (@pi0)

v1.13.0

compare changes

🚀 Enhancements

  • Bump chokidar v4 (#489)
  • Add null driver (#495)

🩹 Fixes

  • cloudflare-kv: Use min ttl of 60 seconds (#496)

💅 Refactors

  • netlify: Support @netlify/blobs v8 and improve options types (#486)
  • cli: Migrate to citty (#498)

📖 Documentation

  • Missing values return null, not undefined (#487)

🏡 Chore

❤️ Contributors

v1.12.0

compare changes

🚀 Enhancements

  • http, server: Support native ttl (#479)

🏡 Chore

🤖 CI

  • Setup nightly release (258fd4a)
  • Fetch full history to preserve nightly changelog (329ff2b)

❤️ Contributors

  • Pooya Parsa (@pi0)

v1.11.1

compare changes

🔥 Performance

  • cloudflare-kv-binding: Add missing base argument on getKeys (#475)

❤️ Contributors

v1.11.0

compare changes

🚀 Enhancements

  • Add keys, get, set, has and del aliases (#402)
  • Expose underlying client instance (#446)
  • cloudflare-kv-binding: Support ttl for setItem (#470)
  • cloudflare-kv-http: Support ttl for setItem (#448)

🔥 Performance

  • getKeys: Avoid duplicate iteration (#386)
  • Use direct array access instead of endsWIth (#387)

🩹 Fixes

  • cloudflare-kv-binding: Allow passing transaction options for setItem to binding.put (#423)
  • Fix driver types (#433)
  • server: Avoid decoding raw request body (#434)
  • cloudflare-kv-binding: Go through all pages to list the keys (#459)

📖 Documentation

  • Using undocs package manager component (#414)
  • Fix link (#429)
  • Fix typographical errors (#432)
  • Jsdocs for the server functions (#438)
  • Improve drivers (f6f547e)

🏡 Chore

🤖 CI

❤️ Contributors

v1.10.2

compare changes

🩹 Fixes

  • http, server: Handle missing resources with http 404 (#367)
  • pkg: Make ioredis dependency optional (#410)
  • vercel-kv: Add missing driver name (#355)
  • setItems: Call driver native setItems only to avoid duplicate write (#392)
  • getItems, setItems types (#395)

💅 Refactors

  • cloudflare-kv, cloudflare-r2: Move getBindings to utils and add default BUCKET for r2 (#292)
  • netlify-blobs: Update to v7 (#407)

📖 Documentation

  • planetscale: Correct table option name (#359)
  • vercel-kv: Fix typo (#362)
  • Refactor with unjs-docs and nuxt ui pro (#374)
  • Improvements (a64e941)
  • Fix links and add redirects (166498f)
  • Update unjs-docs version and add redirects (f2a408d)
  • Fix typo in http-server (#385)
  • Update deps (bfbf423)
  • Update link (#408)

📦 Build

  • Update mkdist for cjs dist hotfix (cae8533)

🏡 Chore

✅ Tests

  • Skip netlify-blobs for now (75b2353)
  • http: Add tests for null value (#365)

❤️ Contributors

v1.10.1

compare changes

📦 Build

  • Update mkdist for cjs dist hotfix (cae8533)

❤️ Contributors

  • Pooya Parsa (@pi0)

v1.10.0

compare changes

🚀 Enhancements

  • Add netlify-blobs driver (#337)

🩹 Fixes

  • server: Read body as string (dfda25f)
  • azure-key-vault-driver: Fix character encoding (#308)
  • lru-cache, memory, mongodb, redis: Return falsy values when set in storage (#320)

📖 Documentation

  • Fix memory driver description (#286)
  • fs: Fix typo (#290)
  • Fix typo in getMount usage (#297)
  • Update deps (#310)
  • indexedb: Fix typo in import (#327)

🏡 Chore

✅ Tests

  • mongo: Update and disable tests (44ffe1d)

🤖 CI

❤️ Contributors

v1.9.0

compare changes

🚀 Enhancements

  • Expose BuiltinDriverOptions type (#273)
  • vercel-kv: Support ttl for setItem (#269)
  • Add indexedb driver (#221)
  • Add capacitor-preferences driver (#283)
  • fs-lite driver (#284)

🩹 Fixes

  • cloudflare-r2-binding: Get binding for r2 getMeta (#272)

💅 Refactors

  • Fix typo in removeMeta option for removeItem (#281)

📖 Documentation

🏡 Chore

🎨 Styles

  • Format with prettier v3 (22b797e)

❤️ Contributors

v1.8.0

compare changes

🚀 Enhancements

  • Experimental operation batching (#240)
  • cloudflare-kv: Support base option for keys (#261)
  • cloudflare-r2-binding driver (#235)

🩹 Fixes

  • Add missing cloudflareR2Binding to the builtinDrivers (48d6842)

📖 Documentation

🏡 Chore

  • Update dev dependencies (ba44aed)

✅ Tests

  • Add test for github driver (#259)

❤️ Contributors

v1.7.0

compare changes

🚀 Enhancements

  • Generic type support (#237)

💅 Refactors

  • Fix issues with typescript strict (#250)

📖 Documentation

🏡 Chore

🤖 CI

❤️ Contributors

v1.6.1

compare changes

🩹 Fixes

  • prefixStorage: Prefix getItemRaw and setItemRaw (#232)
  • github: FetchFiles should return files (#229)

💅 Refactors

🏡 Chore

✅ Tests

  • Skip cloudflare-kv-http on node >= 18 (33bc9c0)

❤️ Contributors

v1.6.0

compare changes

🚀 Enhancements

  • Add vercel-kv driver (#213)

🩹 Fixes

  • redis: Support getKeys and clear with base (#216)
  • azure-cosmos: Always cast mtime to Date (129a935)

💅 Refactors

  • Use shared util for driver errors (5ecca54)

📖 Documentation

  • vercel-kv: Add beta notice (7a75f5f)

🏡 Chore

✅ Tests

❤️ Contributors

v1.5.0

compare changes

🚀 Enhancements

  • drivers: Added session storage driver (#179)
  • lru-cache: Upgrade to lru-cache v9 (5b8fc62)

🩹 Fixes

  • Removed duplicate line (#190)
  • planetscale: Fix hasItem (#200)
  • github: Optional properties (#196)
  • cloudflare: Allow lazy access to env bindings (#202)

📖 Documentation

🏡 Chore

❤️ Contributors

v1.4.1

compare changes

🩹 Fixes

  • pkg: Use optional peer dependencies (#183)

📖 Documentation

🏡 Chore

❤️ Contributors

v1.4.0

compare changes

🚀 Enhancements

  • lru-cache: Support size calculation (#177)
  • Expose name and options from driver instances (#178)
  • http: Support custom headers (4fe7da7)

🩹 Fixes

  • lru-cache: Use max instead of maxSize (012fc62)
  • redis: Remove trailing : from base (82647e0)

📖 Documentation

  • Fix 404 links in readme (4a63a54)

🏡 Chore

✅ Tests

❤️ Contributors

v1.3.0

compare changes

🚀 Enhancements

  • server: Support authorize (#175)
  • server: Support resolvePath (4717851)

🩹 Fixes

  • redis: Remove strict options validation (9294121)
  • redis: Respect both global and operation options for ttl (a491333)
  • pkg: Move types field to the first (f2b08f6)
  • pkg: Export compat types for /server subpath (3cc2c48)

📖 Documentation

  • Update snapshots page (4619326)
  • Improvements on http server (a4b8fb8)

🏡 Chore

❤️ Contributors

v1.2.0

compare changes

🚀 Enhancements

  • mongodb driver (#155)
  • azure-storage-blob driver (#154)
  • azure-cosmos driver (#158)
  • azure-key-vault driver (#159)
  • azure-app-configuration driver (#156)
  • azure-storage-table (#148)
  • getMount and getMounts utils (#167)
  • Allow passing transaction options to drivers (#168)
  • redis: Support native ttl (#169)
  • http and server improvements (#170)

🩹 Fixes

  • redis: Fix clear method (#163)

💅 Refactors

  • redis: Driver improvements (#160)

📖 Documentation

  • Start splitting docs (6bca2a8)
  • Add docs website (#166)

🏡 Chore

  • Remove unused dependencies (#153)
  • Add vercel.json (10d2610)

✅ Tests

  • Add unit test for redis driver (#164)

❤️ Contributors

v1.1.5

compare changes

🏡 Chore

❤️ Contributors

v1.1.4

compare changes

🩹 Fixes

  • Strip query param from keys (cc3ebb7)

❤️ Contributors

v1.1.3

compare changes

🩹 Fixes

  • Allow stringify array (#147)

❤️ Contributors

v1.1.2

compare changes

📦 Build

❤️ Contributors

v1.1.1

compare changes

📦 Build

  • Fix output drivers to top level drivers (ff3959c)

❤️ Contributors

v1.1.0

compare changes

🚀 Enhancements

  • Serialize values implementing toJSON() (#139)
  • Experimental raw data support (#141)
  • driver: Add planetscale driver (#140)
  • fs: Support readOnly and noClear options (f2dddbd)
  • fs: Support birthtime and ctime meta (#136)
  • lru-cache driver (#146)

🩹 Fixes

  • cloudflare: Pass params to kv request (#138)
  • planetscale: Use birthtime for created_at value (#144)
  • Update driver defenition types (#143)

💅 Refactors

  • Use type import for node builtin (#133)

📖 Documentation

  • Fix readme typo (#134)
  • Add experimental link for raw support (98a6466)

📦 Build

  • Provide backwards-compatible type entries (#132)

🏡 Chore

🎨 Styles

  • Format and lint code (fd4e006)
  • Format readme with prettier (ec7c7c2)

❤️ Contributors

1.0.1 (2022-11-15)

1.0.0 (2022-11-15)

0.5.0 (2022-06-13)

⚠ BREAKING CHANGES

  • rename cloudflare-kv to cloudflare-kv-binding

Features

  • rename cloudflare-kv to cloudflare-kv-binding (e361f36)

0.4.1 (2022-05-04)

Features

  • expose key utils normalizeKey, joinKeys and normalizeBaseKey (be81fa8)

0.4.0 (2022-05-02)

⚠ BREAKING CHANGES

  • use ./dist for all subpath exports

Features

Bug Fixes

build

  • use ./dist for all subpath exports (4f2a211)

0.3.3 (2021-11-18)

Bug Fixes

0.3.2 (2021-11-05)

Features

  • create driver for Cloudflare KV store (#30) (5f2f677)

0.3.1 (2021-11-04)

Bug Fixes

  • build: use cjs extension for drivers (#29) (e42cea2)

0.3.0 (2021-10-22)

⚠ BREAKING CHANGES

  • pkg: update depenencies and use explicit cjs extension

Features

  • pkg: update depenencies and use explicit cjs extension (477aa26)

0.2.9 (2021-10-06)

Features

  • allow driver getKey to receive base key (#26) (9fd89b1)

0.2.8 (2021-09-09)

Bug Fixes

  • prefixStorage: handle when key is not provided (#18) (3c754cb)

0.2.7 (2021-09-09)

0.2.6 (2021-09-08)

Features

  • namespaced storage (prefixStorage) (d58beaa)

0.2.5 (2021-09-08)

Features

  • support readonly drivers without setItem, removeItem and clear (22de631)

0.2.4 (2021-09-08)

Features

Bug Fixes

  • omit meta keys for getKeys (34dec7d)

0.2.3 (2021-06-07)

Bug Fixes

0.2.2 (2021-05-24)

Bug Fixes

0.2.1 (2021-05-24)

Bug Fixes

  • pkg: use unbuild and fix drivers/* export (251182b)

0.2.0 (2021-05-24)

⚠ BREAKING CHANGES

  • update dependencies and use mjs for drivers build

Bug Fixes

  • http: use isolated utils (fc4b23b)
  • update dependencies and use mjs for drivers build (e7a6c27)

0.1.6 (2021-05-24)

Bug Fixes

  • fallback value for readdir (ea7d73b)

0.1.5 (2021-04-16)

Bug Fixes

  • fs: race condition for ensuredir (437cc76)

0.1.4 (2021-04-14)

0.1.3 (2021-04-14)

Features

0.1.2 (2021-03-24)

Bug Fixes

  • fs-drivers: typo in error message (0e7e063)
  • pkg: avoid extra index build (5233de6)

0.1.1 (2021-03-13)

Bug Fixes

  • move defineDriver to driver/utils (6ddaceb)

0.1.0 (2021-03-13)

⚠ BREAKING CHANGES

  • restoreSnapshot
  • simplify mount usage

Features

  • allow passing default driver to factory fn (bbca3c3)
  • restoreSnapshot (6e75a61)
  • simplify mount usage (3eccf84)

Bug Fixes

0.0.4 (2021-03-12)

Bug Fixes

0.0.3 (2021-03-11)

Features

  • unstorage command for standalone server (171eb37)
  • server: returns keys on get if val not found (79fd997)
  • support more http methods (45d4771)
  • support storage server (5240591)

Bug Fixes

  • handle mountpoints qurty shorter than mountpoint (9cc1904)

0.0.2 (2021-03-11)

Features

Bug Fixes

  • add mount prefix to watch key (0bb634d)

0.0.1 (2021-03-11)

Features

Bug Fixes