Registry / database / brackets-json-db

brackets-json-db

JSON →
library1.0.3jsnpmunverified

An in-memory JSON file-based implementation of the CrudInterface for brackets-manager.js. Stable version 1.0.3 uses node-json-db to persist tournament brackets data to a JSON file. Designed primarily for testing the brackets-manager.js library where a simple file-based storage is sufficient. Requires brackets-model ^1.7.0 as a peer dependency. Ships TypeScript type definitions. Low release cadence; not intended for production use.

npm install brackets-json-db
INSTALL
IMPORT
SIG · BRACKETS-JSON-DB
B
brackets-json-db
databasejavascriptv1.0.3
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.

JsonDatabase
import { JsonDatabase } from 'brackets-json-db'
import JsonDatabase from 'brackets-json-db'
JsonDatabase is a named export, not a default export.
JsonDatabaseConfig
import type { JsonDatabaseConfig } from 'brackets-json-db'
import { JsonDatabaseConfig } from 'brackets-json-db'
Type import only; use 'import type' to avoid runtime inclusion in TypeScript.
default export
import { JsonDatabase } from 'brackets-json-db'
import JsonDatabase from 'brackets-json-db'
The package does not have a default export; the class must be imported by name.

Shows how to instantiate the JsonDatabase with config and use it as storage for BracketsManager.

import { JsonDatabase } from 'brackets-json-db'; import type { CrudInterface } from 'brackets-model'; import { BracketsManager } from 'brackets-manager'; const storage: CrudInterface = new JsonDatabase({ filePath: './data/brackets.json', autoSave: true, saveInterval: 1000, }); const manager = new BracketsManager(storage); // Now use manager methods like manager.create.tournament(...) console.log('BracketsManager initialized with JSON DB storage');
Debug
Known issues
gotchaJsonDatabase only implements the CrudInterface; it does not manage file locks or concurrency. Multiple Node.js processes writing to the same JSON file will cause data corruption.
fix
Use a proper database (e.g., PostgreSQL via brackets-db) for multi-process scenarios.
affects: >=1.0
gotchaThe JSON file is rewritten entirely on every save. Large tournament data can cause memory and performance issues.
fix
Avoid using JsonDatabase for large datasets; consider a database-backed storage.
affects: >=1.0
deprecatedSince v1.0, the constructor expects a config object with 'filePath' (string). Passing a plain string as before will fail silently.
fix
Use: new JsonDatabase({ filePath: './data.json' })
affects: >=1.0
breakingVersion 1.0 dropped support for CommonJS require(). The package is ESM-only.
fix
Use dynamic import or set 'type': 'module' in package.json. Instead of require('brackets-json-db'), use import('brackets-json-db').then(mod => ...).
affects: >=1.0
gotchaThe 'saveInterval' option is in milliseconds. A value of 0 disables periodic saves but still saves on every write if 'autoSave' is true.
fix
Set autoSave: false to disable all automatic saves and manage writes manually.
affects: >=1.0
gotchaThe database file path is relative to the current working directory, not the module directory. This can lead to unexpected file locations.
fix
Use an absolute path or resolve via process.cwd() and path.resolve() to be explicit.
affects: >=1.0
gotchaJsonDatabase does not support multiple storages in the same process for different managers; it uses a global file lock internally on the same file.
fix
Ensure each JsonDatabase instance uses a unique file path.
affects: >=1.0
Errors
Common errors & fixes
Error: Cannot find module 'brackets-json-db'
Missing dependency or incorrect import after upgrading to ESM-only version.
fix
Run 'npm install brackets-json-db' and ensure your project uses ESM (type: module in package.json) or dynamic import.
TypeError: JsonDatabase is not a constructor
Importing the module as default export instead of named export.
fix
Use 'import { JsonDatabase } from 'brackets-json-db'' instead of 'import JsonDatabase from ...'.
Error: Config must be an object with a 'filePath' string property
Passing a string to constructor instead of a config object in v1.0+.
fix
Change 'new JsonDatabase('./data.json')' to 'new JsonDatabase({ filePath: './data.json' })'.
TypeError: brackets_model_1.CrudInterface is not a module
Missing peer dependency brackets-model or mismatched version.
fix
Run 'npm install brackets-model@^1.7.0' and ensure it is in node_modules.
Upgrade
Version history
1.0.3latest on npm
Audit
Dependencies
brackets-modelrequiredPeer dependency providing the types and interfaces (like CrudInterface) that this storage implementation implements.
node-json-dbrequiredUsed under the hood to read/write JSON files; it is a direct dependency, not optional.
Agent activity
21 hits · last 30 days
node
18
Google (search)
1
OpenAI (training)
1
Resources
brackets-json-db — npm install brackets-json-db · libregistry