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

pocketbase-db-collection

v0.0.3

Published

Pocketbase collection adapter for TanStack DB

Readme

pocketbase-db-collection

A PocketBase collection adapter for TanStack DB. It lets you use a PocketBase RecordService as a real-time, local-first data source for a TanStack DB collection.

Features

  • Real-time sync via PocketBase's subscribe() mechanism
  • Initial data fetch with getFullList() after subscribing (no missed events)
  • Optimistic mutations forwarded to PocketBase (create, update, delete)
  • Optional StandardSchema integration for typed records
  • Automatic unsubscribe on collection cleanup

Installation

npm install pocketbase-db-collection
# or
bun add pocketbase-db-collection
# or
pnpm add pocketbase-db-collection

You also need to install the peer dependencies if they are not already in your project:

npm install @tanstack/db pocketbase

Peer dependencies

  • @tanstack/db >=0.6.0
  • pocketbase >=0.26.0

Usage

Basic

import { createCollection } from '@tanstack/db'
import PocketBase from 'pocketbase'
import { pocketbaseCollectionOptions } from 'pocketbase-db-collection'

type Todo = {
  id: string
  title: string
  done: boolean
}

const pb = new PocketBase('http://localhost:8090')

const todos = createCollection(
  pocketbaseCollectionOptions({
    recordService: pb.collection<Todo>('todos'),
  }),
)

// Wait for the initial sync to complete
await todos.stateWhenReady()

// Read
const all = todos.toArray
const one = todos.get('record-id')

// Mutate — propagated to PocketBase, then synced back through the subscription
todos.insert({ id: '', title: 'Buy milk', done: false })
todos.update('record-id', (draft) => {
  draft.done = true
})
todos.delete('record-id')

Passing PocketBase options

The options field is forwarded to both getFullList() and subscribe(). Use it for filters, expand, fields, etc.

const todos = createCollection(
  pocketbaseCollectionOptions({
    recordService: pb.collection<Todo>('todos'),
    options: {
      filter: 'done = false',
      expand: 'author',
      sort: '-created',
    },
  }),
)

With a Standard Schema

Any Standard Schema compatible validator (Zod, Valibot, ArkType, …) can be passed via the schema field for typed records and validated mutations.

import { z } from 'zod'

const todoSchema = z.object({
  id: z.string(),
  title: z.string(),
  done: z.boolean(),
})

const todos = createCollection(
  pocketbaseCollectionOptions({
    recordService: pb.collection('todos'),
    schema: todoSchema,
  }),
)

API

pocketbaseCollectionOptions(config)

Returns a CollectionConfig that can be passed to TanStack DB's createCollection().

| Field | Type | Description | | --- | --- | --- | | recordService | RecordService<TItem> | A PocketBase record service (pb.collection('...')). Required. | | options | RecordFullListOptions | Optional. Forwarded to getFullList() and subscribe(). | | schema | StandardSchemaV1 | Optional. Provides typed records. | | Other | — | Any other BaseCollectionConfig field from TanStack DB (e.g. id, gcTime, startSync, autoIndex, compare, utils, …) is forwarded as-is. |

The returned config:

  • sets getKey to (item) => item.id (PocketBase's record id),
  • registers a sync function that subscribes first, then performs an initial getFullList() fetch,
  • registers onInsert / onUpdate / onDelete mutation handlers that call PocketBase's create / update / delete,
  • unsubscribes when the collection is cleaned up.

Development

Prerequisites

Install dependencies

bun install

Build

bun run build

Outputs ESM (dist/esm/), CJS (dist/cjs/), and TypeScript declarations.

Watch mode

bun run dev

Tests

bun test

Lint / format

bun run lint
bun run format

License

MIT