npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

pulsea.db

v0.0.5

Published

A secure, multi-format database with built-in encryption, data validation, and automatic backups.

Downloads

59

Readme

Banner

pulsea.db

A secure, multi-format database with built-in encryption, data validation, and automatic backups.

Features

  • 🔐 Secure Storage: Built-in encryption for sensitive data
  • 📁 Flexible Storage Format: Choose between YAML, JSON, or SQL format
  • 🗜️ Data Compression: Automatic zlib compression for efficient storage
  • 🔄 Automatic Backups: Configurable backup intervals with retention policies
  • 📊 Table Support: SQL-like table operations with validation and relations
  • 🔍 Rich Query API: Complex queries with where clauses, ordering, and pagination
  • 🛡️ Data Validation: Schema validation with type checking and custom rules
  • 🔗 Relationship Support: Define and maintain relationships between tables
  • 💾 Auto-save: Automatic saving of changes (configurable)
  • 🚀 Async/Promise Based: Modern asynchronous API

Installation

npm install pulsea.db

Quick Start

const PulseaDB = require('pulsea.db');

// Initialize the database with encryption and file format
const db = new PulseaDB({
    file: 'database.json',      // Choose format: database.json, database.yml, or database.sql
    encryption: {
        secretKey: 'your-secret-key'
    },
    dir: './data',              // Optional: default is './data'
    autoSave: true,             // Optional: default is true
    debug: true                 // Optional: enables debug logging
});

// Basic Operations
await db.set('user.1', { name: 'John', age: 30 });
const user = await db.get('user.1');
console.log(user); // { name: 'John', age: 30 }

Table Operations

Creating a Table

await db.createTable({
    name: 'users',
    columns: ['name', 'email', 'age'],
    validations: {
        name: { type: 'string', pattern: '^[A-Za-z ]+$' },
        email: { type: 'string', pattern: '^[^@]+@[^@]+\.[^@]+$' },
        age: { type: 'number', min: 0, max: 120 }
    },
    indexes: ['email'],
    relations: {
        groupId: { table: 'groups', column: 'id' }
    }
});

Querying Data

// Insert data
await db.set('users.1', {
    name: 'John Doe',
    email: '[email protected]',
    age: 30
});

// Query with conditions
const users = await db.query('users', {
    where: {
        age: { $gt: 25 },
        name: { $like: 'John%' }
    },
    orderBy: 'age desc',
    limit: 10,
    offset: 0
});

Detailed API Reference

Core Database Methods

Constructor

const db = new PulseaDB({
    file: 'database.json',        // Required: database file with format extension
    encryption: {
        secretKey: 'required-key' // Required: encryption key
    },
    dir: './data',               // Optional: database directory
    debug: false,                // Optional: debug mode
    autoSave: true,              // Optional: auto-save changes
    backupInterval: 3600000,     // Optional: backup interval (ms)
    maxBackups: 5,               // Optional: maximum backups to keep
    enableAutoBackup: true       // Optional: enable automatic backups
});

The constructor initializes a new PulseaDB instance with the following features:

  • Single file format support (YAML, JSON, or SQL)
  • Automatic directory creation for database and backups
  • File locking mechanism for concurrent operations
  • Built-in encryption with zlib compression
  • Auto-backup scheduling if enabled

Storage Optimization

PulseaDB automatically optimizes storage using zlib compression. This feature:

  • Reduces database file size by 50-90% depending on data type
  • Compresses data before encryption for maximum efficiency
  • Automatically handles compression/decompression transparently
  • Works with all storage formats (JSON, YAML, SQL)
  • Maintains data integrity with efficient binary compression

Security Mechanism

PulseaDB implements a robust security mechanism to protect critical database operations:

  • 🔒 Method Protection: Core methods are locked and cannot be modified
  • 🛡️ Class Protection: Database class structure is frozen and immutable
  • 🔐 Instance Protection: Each database instance has its own protected method registry
  • Runtime Verification: Critical method calls are verified during execution
  • 🚫 Tamper Detection: Attempts to modify protected methods trigger security errors

Protected methods include:

  • encryptValue: Data encryption
  • decryptValue: Data decryption
  • validateTableData: Data validation
  • sanitizePath: Path security
  • init: Initialization process

Data Management

set(key, value)

Stores an encrypted value in the database.

// Simple key-value storage
await db.set('user.preferences', { theme: 'dark' });

// Table record storage
await db.set('users.123', {
    name: 'John',
    email: '[email protected]'
});
  • Validates key format and type
  • Encrypts values automatically
  • Supports nested objects and arrays
  • Handles table data with validation
  • Auto-saves if enabled
get(key, defaultValue = null)

Retrieves and decrypts a value from the database.

// Get with default value
const theme = await db.get('user.preferences.theme', 'light');

// Get table record
const user = await db.get('users.123');
  • Returns decrypted data
  • Supports deep object paths
  • Returns defaultValue if key doesn't exist
  • Handles table metadata and relations
delete(key)

Removes a key and its value from the database.

// Delete user
await db.delete('users.123');

// Delete nested value
await db.delete('user.preferences.theme');
  • Cleans up empty parent objects
  • Returns boolean indicating success
  • Auto-saves if enabled

Backup Operations

backup()

Creates a backup of the database in the selected format.

const backupPath = await db.backup();
console.log(`Backup created at: ${backupPath}`);
  • Creates timestamped backup file
  • Maintains specified number of backups
  • Supports all storage formats

restoreFromBackup(backupPath)

Restores the database from a backup file.

await db.restoreFromBackup('./data/backups/backup-2024-01-01.json');
  • Validates backup file format
  • Restores data with encryption
  • Maintains data integrity

Connect With Us