Registry / storage / storage-mixin

storage-mixin

JSON →
library5.1.5jsnpmunverified

An Ampersand.js model mixin for persisting data across multiple storage backends. Stable version 5.1.5, released as part of MongoDB Compass ecosystem. Provides pluggable storage adapters (indexedDB, local storage, LevelDB, S3, MongoDB) with automatic serialization. Key differentiator: seamless integration with Ampersand models and reactive data synchronization.

npm install storage-mixin
INSTALL
IMPORT
SIG · STORAGE-MIXIN
S
storage-mixin
storagejavascriptv5.1.5
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

storageMixin
import storageMixin from 'storage-mixin'
const storageMixin = require('storage-mixin')
ESM-only since v5. Use default export.
StorageBackend
import { StorageBackend } from 'storage-mixin'
import StorageBackend from 'storage-mixin'
Type-only export for custom backend implementation.
backends
import { backends } from 'storage-mixin'
import backends from 'storage-mixin'
Named export object mapping backend names to classes.
StorageMixinOptions
import type { StorageMixinOptions } from 'storage-mixin'
import { StorageMixinOptions } from 'storage-mixin'
TypeScript: use type import for interfaces.

Shows how to use storage-mixin with Ampersand Model, LevelUP backend, namespace, and saving.

import storageMixin from 'storage-mixin'; import Model from 'ampersand-model'; import backends from 'storage-mixin/backends'; const MyModel = Model.extend({ props: { name: 'string', email: 'string' }, session: { token: 'string', }, mixins: [storageMixin({ backend: backends.levelup, namespace: 'myapp', levelup: { dbPath: './mydb' } })] }); const model = new MyModel({ name: 'Alice' }); model.save();
Debug
Known issues
breakingDefault export changed from object to function in v5
fix
Use default export directly (import storageMixin from 'storage-mixin') instead of destructuring.
affects: >=5.0.0
gotchaStorage backends require peer dependencies
fix
Install required peer dependency like 'levelup' for LevelDB backend.
affects: >=4.0.0
deprecatedLocalStorage backend may not work in non-browser environments
fix
Use indexedDB backend for cross-platform persistence.
affects: >=3.0.0
gotchaSerialization uses JSON.stringify; custom types not automatically handled
fix
Override serialize/deserialize in your model if needed.
affects: >=2.0.0
Errors
Common errors & fixes
Cannot find module 'storage-mixin'
Package not installed or import path incorrect
fix
Install with `npm install storage-mixin` and check import statement.
TypeError: storageMixin is not a function
Using old import pattern (object destructuring)
fix
Use `import storageMixin from 'storage-mixin'` directly.
Error: No valid backend specified
Missing or incorrect backend configuration
fix
Specify a backend property with one of the supported backends, e.g., `backend: backends.local`.
Error: LevelUP backend requires 'levelup' dependency
Missing peer dependency for LevelUP
fix
Run `npm install levelup`.
Upgrade
Version history
5.1.5latest on npm
Audit
Dependencies
ampersand-modelrequiredPeer dependency for model mixin functionality
ampersand-collectionoptionalPeer dependency for collection mixin
Agent activity
45 hits · last 30 days
node
42
Meta
2
Resources
storage-mixin — npm install storage-mixin · libregistry