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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@objectql/driver-utils

v4.1.0

Published

Shared utilities for ObjectQL drivers - QueryAST parsing, FilterCondition evaluation, error handling

Downloads

19

Readme

@objectql/driver-utils

Shared utilities for ObjectQL drivers to reduce code duplication and standardize driver implementations.

Overview

This package provides common functionality used across all ObjectQL drivers:

  • QueryAST normalization - Convert between legacy and modern query formats
  • FilterCondition evaluation - MongoDB-style query evaluation and conversion
  • Error handling - Standard error codes and error creation utilities
  • ID generation - Multiple ID generation strategies (nanoid, UUID, sequential, timestamp)
  • Timestamp management - Automatic timestamp handling for create/update operations
  • Transaction utilities - Transaction state management and helpers

Installation

pnpm add @objectql/driver-utils

Usage

QueryAST Normalization

import { normalizeQuery, normalizeOrderBy, applySorting, applyPagination } from '@objectql/driver-utils';

// Normalize query from various formats
const normalized = normalizeQuery({
  filters: { role: 'admin' }, // Legacy format
  sort: [['age', 'asc']],
  skip: 10,
  limit: 20
});
// Returns: { where: {...}, orderBy: [...], offset: 10, limit: 20 }

// Apply sorting to records
const sorted = applySorting(records, [
  { field: 'age', order: 'asc' },
  { field: 'name', order: 'desc' }
]);

// Apply pagination
const paginated = applyPagination(records, 10, 20); // offset: 10, limit: 20

FilterCondition Evaluation

import { evaluateFilter, filterRecords, isFilterCondition } from '@objectql/driver-utils';

// Evaluate a single record against a condition
const matches = evaluateFilter(record, {
  age: { $gt: 18 },
  role: 'user'
});

// Filter an array of records
const filtered = filterRecords(records, {
  $or: [
    { status: 'active' },
    { priority: { $gte: 5 } }
  ]
});

// Check if value is a FilterCondition
if (isFilterCondition(query.where)) {
  // Handle MongoDB-style query
}

Error Handling

import {
  createRecordNotFoundError,
  createDuplicateRecordError,
  createValidationError,
  wrapError,
  DriverError
} from '@objectql/driver-utils';

// Throw standard errors
throw createRecordNotFoundError('users', userId);
throw createDuplicateRecordError('users', userId);

// Wrap native errors
try {
  // ... database operation
} catch (error) {
  throw wrapError(error as Error, {
    operation: 'create',
    objectName: 'users'
  });
}

ID Generation

import { IDGenerator, generateNanoId, generateUUID, generateTimestampId } from '@objectql/driver-utils';

// Using ID Generator
const idGen = new IDGenerator();
const id1 = idGen.generateSequential('users'); // "1"
const id2 = idGen.generateSequential('users', 'usr_'); // "usr_2"
const id3 = idGen.generateRandom(16); // Random nanoid

// Direct functions
const nanoId = generateNanoId(16);
const uuid = generateUUID();
const timestampId = generateTimestampId('doc');

Timestamp Utilities

import { addCreateTimestamps, addUpdateTimestamps, getCurrentTimestamp } from '@objectql/driver-utils';

// Add timestamps for create
const newRecord = addCreateTimestamps({ name: 'Alice' });
// Returns: { name: 'Alice', created_at: '2026-02-02T...', updated_at: '2026-02-02T...' }

// Add timestamps for update
const updated = addUpdateTimestamps(
  { email: '[email protected]' },
  existingRecord.created_at
);
// Returns: { email: '...', created_at: '<preserved>', updated_at: '2026-02-02T...' }

Transaction Utilities

import {
  createTransaction,
  generateTransactionId,
  isTransactionActive,
  markCommitted,
  TransactionState
} from '@objectql/driver-utils';

// Create transaction
const tx = createTransaction();
console.log(tx.id); // "tx_1234567890_abc123"
console.log(tx.state); // TransactionState.ACTIVE

// Check state
if (isTransactionActive(tx)) {
  // Execute operations
}

// Update state
markCommitted(tx);
console.log(tx.state); // TransactionState.COMMITTED

API Reference

See individual module documentation for detailed API information:

Benefits

Using @objectql/driver-utils in your driver implementation provides:

  1. Reduced Code Duplication - Common patterns extracted and tested
  2. Consistency - All drivers behave the same way for core operations
  3. Maintainability - Bug fixes and improvements benefit all drivers
  4. Type Safety - Full TypeScript support with proper type definitions
  5. Testing - Shared utilities are thoroughly tested

License

MIT