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

@lp-labs/changefeed-client

v0.1.0

Published

Ordered pull-based changefeed consumption with durable adapter checkpoints.

Readme

@lp-labs/changefeed-client

Ordered pull-based changefeed consumption with durable adapter checkpoints.

Original independent MIT TypeScript implementation with zero runtime/peer dependencies. ESM and CommonJS with separate declarations, Node 18+ (browser use when adapters/APIs are available). Development dependencies are not consumer runtime dependencies.

Install

npm install @lp-labs/changefeed-client

Complete example

import assert from 'node:assert/strict';
import { createChangefeedClient, ChangefeedError } from '@lp-labs/changefeed-client';
let checkpoint;
const seen = [];
const client = createChangefeedClient({
  async loadCheckpoint() {
    return checkpoint;
  },
  async *read() {
    yield { token: 't1', position: 1, payload: { name: 'A' } };
    yield { token: 't1', position: 1, payload: { name: 'A' } };
    yield { token: 't2', position: 2, payload: null };
  },
  async saveCheckpoint(value) {
    checkpoint = value;
  },
});
const result = await client.consume((event) => {
  seen.push(event.position);
});
assert.deepEqual(seen, [1, 2]);
assert.equal(result.duplicates, 1);
assert.equal(checkpoint.token, 't2');

CommonJS exposes the same API: const api = require('@lp-labs/changefeed-client').

Scope, customization and performance

Adapter must supply monotone integer positions and stable tokens. One consume call per adapter at a time. Handler finishes before checkpoint persistence and before pulling another event; failures can replay effects, so handlers require idempotency. Earlier positions are suppressed, equal position with a different token errors. maxItems counts pulled records (default 10,000); stoppedByLimit does not prove another record exists. Caller reconnects. Numeric bounds, finite JSON only; no DB driver or exactly-once guarantee.

Configure explicit limits, clocks, policies and adapters through the API below. Error classes and standard TypeError/RangeError reject malformed input; adapter/handler errors propagate. Await asynchronous methods and handle rejection in your application; no success-shaped fallback on failed work. Inputs must be trusted ordinary data, not hostile proxies; adapters must meet documented atomicity, isolation and ownership contracts. This package never publishes data, loads external code or starts background services at import time.

API reference

The complete exported TypeScript contract (including option defaults discussed above, method return shapes, and error codes) is included below. TypeScript users import interfaces using import type; JavaScript users pass matching ordinary objects. Signature optionals indicate intentionally optional fields, not silent recovery.

export type JsonValue =
  | null
  | boolean
  | number
  | string
  | JsonValue[]
  | {
      [key: string]: JsonValue;
    };
export interface ChangefeedEvent<T extends JsonValue = JsonValue> {
  token: string;
  position: number;
  payload: T;
}
export interface ChangefeedCheckpoint {
  token: string;
  position: number;
}
export interface ChangefeedSignal {
  readonly aborted: boolean;
}
/** Adapters expose an ordered async iterable and durable checkpoint operations. */
export interface ChangefeedAdapter<T extends JsonValue = JsonValue> {
  loadCheckpoint(): Promise<ChangefeedCheckpoint | undefined>;
  read(
    afterToken: string | undefined,
    signal: ChangefeedSignal | undefined,
  ): AsyncIterable<ChangefeedEvent<T>>;
  saveCheckpoint(checkpoint: ChangefeedCheckpoint): Promise<void>;
}
export interface ChangefeedOptions {
  maxItems?: number;
  maxTokenLength?: number;
  maxPayloadBytes?: number;
  maxPayloadNodes?: number;
}
export interface ConsumeResult {
  processed: number;
  duplicates: number;
  checkpoint: ChangefeedCheckpoint | undefined;
  stoppedByLimit: boolean;
}
export declare class ChangefeedError extends Error {
  readonly code: 'invalid' | 'capacity' | 'adapter' | 'handler' | 'aborted' | 'ordering';
  readonly phase?: 'load-checkpoint' | 'read' | 'save-checkpoint' | 'handler' | undefined;
  constructor(
    code: 'invalid' | 'capacity' | 'adapter' | 'handler' | 'aborted' | 'ordering',
    message: string,
    phase?: 'load-checkpoint' | 'read' | 'save-checkpoint' | 'handler' | undefined,
    options?: ErrorOptions,
  );
}
/** Pulls one event at a time: handlers and durable checkpoints apply backpressure to the source. */
export declare function createChangefeedClient<T extends JsonValue = JsonValue>(
  adapter: ChangefeedAdapter<T>,
  options?: ChangefeedOptions,
): {
  consume(
    handler: (event: ChangefeedEvent<T>) => void | Promise<void>,
    signal?: ChangefeedSignal,
  ): Promise<ConsumeResult>;
};

Support

If this library is useful to you, consider supporting its maintenance with a donation via PayPal.

Author

Created by Libin Prasanth. Connect on LinkedIn for updates and discussion.