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 🙏

© 2025 – Pkg Stats / Ryan Hefner

iworkdb

v1.0.0

Published

Interfaces of WorkDb

Readme

IWorkDb

TypeScript interfaces and types for the WorkDB cross-platform database system.

Overview

IWorkDb provides the core interfaces and type definitions for a lightweight, cross-platform database system that works seamlessly across Node.js, browser, and Capacitor environments.

Installation

npm install iworkdb

Types and Interfaces

Core Types

// JSON-serializable object type
export type JsonObject = { [key: string]: JsonValue }; 
export type JsonValue = string | number | boolean | null | JsonObject | JsonValue[];

// Item identification
export type ItemId = {
    id: string;
    collection: string;
};

// Item data structure
export type Item = {
    item: JsonObject;
}

// Item with metadata
export type ItemOutput = Item & {
    createdAt?: string;
}

IWorkDb Interface

Main interface for database operations:

interface IWorkDb {
    // CRUD Operations
    create(input: Item & ItemId): Promise<void>;
    createMultiple(input: (ItemId & Item)[]): Promise<void>;
    update(input: Item & ItemId): Promise<void>;
    retrieve(input: ItemId): Promise<ItemOutput | null>;
    retrieveMultiple(ids: ItemId[]): Promise<(ItemOutput | null)[]>;
    delete(input: ItemId): Promise<void>;
    
    // Collection Management
    deleteCollection(collection: string): Promise<void>;
    clearDatabase(): Promise<void>;
    getItemsInCollection(collection: string): Promise<string[]>;
    getCollections(): Promise<string[]>;
    
    // File System Operations
    ls(path: string): Promise<string[]>;
}

IWorkFileSystem Interface

Low-level file system abstraction:

interface IWorkFileSystem {
    writeFile(path: string, input: Item): Promise<void>;
    getFile(path: string): Promise<ItemOutput>;
    deleteFile(path: string): Promise<void>;
    deleteFolder(folderPath: string): Promise<void>;
    exist(path: string): Promise<boolean>;
    renameFile(oldPath: string, newPath: string): Promise<void>;
    ls(path: string): Promise<string[]>;
}

Usage Examples

Basic Item Operations

import { IWorkDb, ItemId, Item } from 'iworkdb';

// Create an item
const itemId: ItemId = { id: 'user1', collection: 'users' };
const item: Item = { item: { name: 'John', age: 30 } };
await workDb.create({ ...itemId, ...item });

// Retrieve an item
const result = await workDb.retrieve(itemId);
console.log(result?.item); // { name: 'John', age: 30 }

// Update an item
await workDb.update({ ...itemId, item: { name: 'John', age: 31 } });

// Delete an item
await workDb.delete(itemId);

Collection Management

// Get all collections
const collections = await workDb.getCollections();

// Get items in a collection
const userIds = await workDb.getItemsInCollection('users');

// Delete entire collection
await workDb.deleteCollection('users');

// Clear entire database
await workDb.clearDatabase();

Multiple Operations

// Create multiple items
const items = [
    { id: 'user1', collection: 'users', item: { name: 'John' } },
    { id: 'user2', collection: 'users', item: { name: 'Jane' } }
];
await workDb.createMultiple(items);

// Retrieve multiple items
const ids = [
    { id: 'user1', collection: 'users' },
    { id: 'user2', collection: 'users' }
];
const results = await workDb.retrieveMultiple(ids);

Data Structure

  • Collections: Logical groupings of related items (similar to tables in SQL)
  • Items: Individual data objects within collections
  • IDs: Unique identifiers for items within their collection
  • Path Structure: ./WorkDB/{collection}/{id}

Error Handling

The database will throw errors for:

  • Creating items that already exist
  • Updating items that don't exist
  • Deleting items that don't exist
  • Invalid IDs or collection names
  • Non-serializable data

TypeScript Support

Full TypeScript support with strict typing for:

  • JSON-serializable data validation
  • Required fields enforcement
  • Return type guarantees
  • Interface compliance checking

License

LGPL-3.0-or-later