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

@wonderlandlabs/atmo-collection

v0.0.1

Published

A high-performance collection library for managing database records with buffered writes.

Readme

Atmo Collection

A high-performance collection library for managing database records with buffered writes.

Collection Class

The Collection class is a generic class that provides a type-safe interface for working with database records. It includes features like buffered writes, batch operations, and query capabilities.

Generic Type Parameters

The Collection class takes two generic type parameters:

Collection<SourceRecord extends DataRecord, K extends keyof SourceRecord & RecordId>

Usage Example

// Define a record type
interface UserRecord extends DataRecord {
  id: string;
  name: string;
  email: string;
  age: number;
}

// Define table identity
const USER_TABLE: TableIdentity = {
  table: 'users',
  primaryKey: 'id',
  autoIncrement: false
};

// Create a collection
const userCollection = new Collection<UserRecord, 'id'>({
  tableId: USER_TABLE,
  db: database,
  flushConfig: {
    recordThreshold: 10,
    timeoutMs: 500
  }
}, columns);

// Insert records
const users = new Map<string, UserRecord>();
users.set('user1', {
  id: 'user1',
  name: 'John Doe',
  email: '[email protected]',
  age: 30
});
userCollection.create(users);

// Basic query records
const allUsers = await userCollection.queryAll({
  field: 'age',
  op: '>',
  value: 25
});

// Enhanced query with select properties
const latestUsersBySession = await userCollection.select({
  query: {
    and: [
      { field: 'key', op: '=', value: 'some_key' },
      { field: 'sessionId', op: '=', value: 'current_session_id' }
    ]
  },
  sort: [{ field: 'timestamp', desc: true }],
  limit: 1
});

Enhanced Queries

The Collection class now supports enhanced query capabilities through the queryFull method, which provides more powerful filtering, sorting, and pagination options.

SelectNode Interface

The queryFull method accepts a SelectNode object with the following properties:

interface SelectNode {
  query: QueryNode;       // Filter criteria
  sort?: SortOption[];   // Sorting options
  limit?: number;        // Maximum number of records to return
  offset?: number;       // Number of records to skip
}

interface SortOption {
  field: string;         // Field to sort by
  desc?: boolean;        // Sort in descending order if true
}

Buffer Class

The Buffer class is used internally by the Collection class to manage buffered writes. It queues write operations and flushes them to the database in batches.

BufferCommand

The BufferCommand class encapsulates all command processing logic for database operations. It supports several command types:

  • SET: A compound command that can be split into PUT and CREATE commands
  • PUT: For inserting or updating records with IDs
  • CREATE: For inserting records without IDs
  • UPDATE: For updating existing records
  • PATCH: For partially updating existing records
  • DELETE: For removing records
  • COMPOUND: A container for multiple commands

The Buffer system intelligently processes and merges commands to optimize database operations:

// The Buffer automatically handles command processing
const buffer = new Buffer<UserRecord, 'id'>({
  tableId: USER_TABLE,
  recordThreshold: 50,
  flushTimeoutMs: 500,
  onFlush: async (commands) => {
    // Process commands when buffer is flushed
  }
});

// Queue a command
buffer.queue({
  type: RECORD_STATUS.SET,
  records: userRecords
});

// Commands with the same type can be merged
buffer.queue({
  type: RECORD_STATUS.DELETE,
  keys: new Set(['user1', 'user2'])
});