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

svelte-pocketbase-sync

v0.0.2

Published

A reactive wrapper for PocketBase collections and records in SvelteKit, allowing automatic updates and reactivity.

Readme

Svelte PocketBase Reactive Wrapper

A reactive wrapper for PocketBase collections and records in SvelteKit, allowing automatic updates and reactivity.

Installation

Ensure you have pocketbase installed:

npm install pocketbase

Then, add the wrapper files to your SvelteKit project.


Usage

1. Initialize PocketBase

pocketbase.svelte.ts provides a reactive user store and PocketBase instance. The PocketBase URL should be set via an environment variable:

export const pb = new PocketBase(process.env.POCKETBASE_URL);

Additionally, user.current is a reactive store that holds the current authenticated user.

import { pb, user } from '$lib/pocketbase/pocketbase.svelte.js';

You can authenticate users:

const login = async () => {
	const auth = await pb.collection('users').authWithPassword('[email protected]', 'password');
	console.log(auth);
};

const logout = async () => {
	user.logout();
};

2. Working with Collections

Reactive List of Records

Use CollectionList<T> to track a collection reactively, where T is the type of the record.

import { CollectionList } from '$lib/pocketbase/CollectionList.svelte.js';

type TestRecord = { id: string; content: string };

const test = new CollectionList<TestRecord>({
	name: 'test',
	onInit: async (collection) => await collection.getFullList(),
	onUpdate: (record) => ({ ...record, updated: true }),
	onCreate: (record) => ({ ...record, new: true }),
	onDelete: (record) => console.log(`Record deleted: ${record.id}`)
});
  • onInit(collection): An optional function that runs when the collection is initialized. It should return a list of records.
  • onUpdate(record): Called when a record is updated. Can modify and return the updated record.
  • onCreate(record): Called when a new record is created. Can modify and return the newly created record.
  • onDelete(record): Called when a record is deleted. Can be used for cleanup actions.

Render in a Svelte component:

<ul>
	{#each test.records as record}
		<li>{record.id}</li>
	{/each}
</ul>

Creating a New Record

const createTest = async () => {
	await pb.collection('test').create({ content: 'test ' + Math.random() });
};

3. Working with a Single Record

Use CollectionRecord<T> to track a single record reactively, where T is the type of the record.

import { CollectionRecord } from '$lib/pocketbase/CollectionRecord.svelte.js';

type TestRecord = { id: string; content: string };

const record = new CollectionRecord<TestRecord>({
	name: 'test',
	recordId: '119p42gj5817e6u',
	onInit: async (collection) => await collection.getOne('119p42gj5817e6u'),
	onUpdate: (record) => ({ ...record, modified: true }),
	onCreate: (record) => ({ ...record, initialized: true }),
	onDelete: (record) => console.log(`Record ${record.id} deleted`)
});
  • onInit(collection): Runs when the record is initialized. Should return the specific record.
  • onUpdate(record): Called when the record is updated. Can modify and return the updated record.
  • onCreate(record): Called when the record is created. Can modify and return the newly created record.
  • onDelete(record): Called when the record is deleted.

Render in a Svelte component:

<p>Record Content: {record.record?.content}</p>

Features

  • 🔄 Reactive Collections & Records: Automatically update on changes.
  • 🔑 Authentication Handling: Tracks authenticated users.
  • 🔥 Real-time Updates: Uses PocketBase's subscription system.
  • 🏗 Lightweight & Modular: Designed for SvelteKit applications.