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

roam-block-reconciler

v1.0.0

Published

A library for efficiently syncing data from external sources to Roam Research blocks

Downloads

17

Readme

roam-block-reconciler

CI npm version

A library for efficiently syncing data from external sources to Roam Research blocks. Only creates, updates, or deletes blocks when necessary.

Features

  • Efficient reconciliation: Only modifies blocks that actually changed
  • Configurable: Custom ID extraction, block building, and preservation rules
  • Progress tracking: Callbacks for monitoring sync progress
  • Children support: Reconcile nested block structures
  • Testable: Adapter pattern for easy mocking of Roam API

Installation

npm install roam-block-reconciler
# or
pnpm add roam-block-reconciler

Usage

import { BlockReconciler, createRoamApiAdapter } from "roam-block-reconciler";

// Create the Roam API adapter
const adapter = createRoamApiAdapter({
  getBasicTreeByParentUid: (uid) => {
    // Your Roam API call to get children
    return window.roamAlphaAPI.q(`...`);
  },
  createBlock: async ({ parentUid, order, node }) => {
    return await window.roamAlphaAPI.createBlock({
      location: { "parent-uid": parentUid, order },
      block: { string: node.text, children: node.children },
    });
  },
  updateBlock: async ({ uid, text }) => {
    await window.roamAlphaAPI.updateBlock({
      block: { uid, string: text },
    });
  },
  deleteBlock: async (uid) => {
    await window.roamAlphaAPI.deleteBlock({ block: { uid } });
  },
});

// Define your item type
interface Task {
  id: number;
  content: string;
  completed: boolean;
}

// Create the reconciler
const reconciler = new BlockReconciler<Task>(
  {
    extractId: (task) => String(task.id),
    buildBlock: (task) => ({
      text: `{{[[TODO]]}} ${task.content} #task-${task.id}`,
      children: [],
    }),
    extractIdFromBlock: (node) => {
      const match = node.text.match(/#task-(\d+)/);
      return match ? match[1] : undefined;
    },
    options: {
      preserveWhen: (node) => node.text.includes("{{[[DONE]]}}"),
      onProgress: (stats) => console.log("Progress:", stats),
    },
  },
  adapter
);

// Reconcile tasks with Roam blocks
const tasks: Task[] = [
  { id: 1, content: "Buy milk", completed: false },
  { id: 2, content: "Walk the dog", completed: false },
];

const stats = await reconciler.reconcile("page-uid", tasks);
console.log(`Created: ${stats.created}, Updated: ${stats.updated}, Skipped: ${stats.skipped}`);

API

BlockReconciler

The main class for reconciling items with Roam blocks.

Constructor

new BlockReconciler<T>(config: ReconcilerConfig<T>, adapter: RoamApiAdapter)

Methods

  • reconcile(parentUid: string, items: T[]): Promise<SyncStats> - Reconciles items with blocks
  • withChildrenReconciler(config: ChildReconcilerConfig): this - Adds children reconciliation

Types

ReconcilerConfig

interface ReconcilerConfig<T> {
  extractId: (item: T) => string;
  buildBlock: (item: T) => BlockPayload;
  extractIdFromBlock: (node: RoamNode) => string | undefined;
  options?: ReconcilerOptions;
}

ReconcilerOptions

interface ReconcilerOptions {
  preserveWhen?: (node: RoamNode) => boolean;
  onProgress?: (stats: SyncStats) => void;
  mutationDelayMs?: number; // default: 100
  yieldBatchSize?: number; // default: 3
  logger?: Logger;
}

SyncStats

interface SyncStats {
  total: number;
  skipped: number;
  created: number;
  updated: number;
  deleted: number;
}

createRoamApiAdapter

Factory function to create a Roam API adapter.

const adapter = createRoamApiAdapter({
  getBasicTreeByParentUid: (uid) => RoamBasicNode[],
  createBlock: async (params) => string,
  updateBlock: async (params) => void,
  deleteBlock: async (uid) => void,
});

Used By

Plugins using this library:

Development

# Install dependencies
npm install

# Run tests
npm test

# Run tests in watch mode
npm run test:watch

# Run tests with coverage
npm run test:coverage

# Lint and type check
npm run check

# Build
npm run build

License

MIT