LevelDB Feature Support Manifest
level-supports is a utility package within the LevelDB ecosystem designed to generate a manifest object detailing the capabilities of an `abstract-level` database instance. This manifest allows consumers of a database to programmatically check for specific features, such as `permanence`, `encodings` (like `utf8`), `implicitSnapshots`, `explicitSnapshots`, and `has` (for `has()` and `hasMany()`). The current stable version is 6.2.0. Releases are typically driven by new `abstract-level` features or Node.js compatibility updates, with a focus on semantic versioning for breaking changes. Its key differentiator is providing a standardized, merged, and enriched feature description, moving beyond simple boolean checks to handle more complex truthy values for future extensibility.
Common errors
-
TypeError: (0, level_supports_1.default) is not a function
cause Attempting to use `level-supports` v3.0.0 or higher with a default import/require syntax, but the package changed to a named export.fixChange your import statement from `import supports from 'level-supports'` to `import { supports } from 'level-supports'` or for CommonJS, `const supports = require('level-supports')` to `const { supports } = require('level-supports')`. -
Error: Persistent storage is required
cause A consumer of the database is checking for `db.supports.permanence` but the provided manifest or underlying database driver indicates `permanence: false`.fixEnsure that the `level-supports` manifest accurately reflects the underlying database's capabilities, especially for critical features like `permanence`. If persistence is required, use a database that provides it or configure the manifest accordingly.
Warnings
- breaking Version 6.0.0 dropped support for Node.js versions older than 16. Ensure your environment meets this requirement.
- breaking Version 5.0.0 removed properties that were implicitly true since 'abstract-level@1'. This streamlines the manifest, focusing on explicit feature declarations.
- breaking Version 3.0.0 introduced significant breaking changes: it is no longer compatible with `abstract-leveldown` or `levelup` directly, and it changed from a default export to a named export (`{ supports }`). Additionally, `encodings` and `events` properties are now always objects.
- gotcha Manifest properties are truthy rather than strictly boolean. When checking for support, always use `if (db.supports.feature)` instead of `if (db.supports.feature === true)` to accommodate future extensibility where features might have object values.
- deprecated `implicitSnapshots` is aliased as `snapshots` for backwards compatibility. While `snapshots` still works, `implicitSnapshots` is the preferred and more descriptive property name.
Install
-
npm install level-supports -
yarn add level-supports -
pnpm add level-supports
Imports
- supports
const supports = require('level-supports')import { supports } from 'level-supports' - supports
const { supports } = require('level-supports') - Manifest
import type { Manifest } from 'level-supports'
Quickstart
import { supports } from 'level-supports';
// Simulate a database with specific capabilities
const myCustomDb = {
// In a real scenario, these would come from the database driver
supports: supports({
permanence: true,
encodings: {
utf8: true,
json: { value: true, array: false },
binary: {} // Truthy, details allowed
},
implicitSnapshots: true,
explicitSnapshots: false,
has: true
})
};
console.log(`Database supports permanence: ${!!myCustomDb.supports.permanence}`);
console.log(`Database supports JSON encoding: ${!!myCustomDb.supports.encodings.json}`);
if (myCustomDb.supports.has) {
console.log('Database implements has() and hasMany().');
} else {
console.log('Database does not implement has().');
}
// Merge with another manifest (e.g., from a plugin)
const pluginManifest = { signals: true };
const mergedSupports = supports(myCustomDb.supports, pluginManifest);
console.log(`Database supports signals (after merge): ${!!mergedSupports.signals}`);