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

@velastack/pocketbase

v0.0.52

Published

PocketBase bindings for SvelteKit: a hooks.server.ts middleware, type-safe collection schemas, and dev-time type sync.

Readme

@velastack/pocketbase

PocketBase bindings for SvelteKit. Provides a hooks.server.ts middleware that proxies the PocketBase admin UI and API, manages user/admin auth on event.locals, and (in dev) keeps your generated types in sync with the live PocketBase schema.

Install

npm install @velastack/pocketbase

Quick start

// src/hooks.server.ts
import { env } from '$env/dynamic/private';
import { handlePocketbase } from '@velastack/pocketbase';

export const handle = handlePocketbase({
	pocketbaseUrl: env.POCKETBASE_URL,
	superuserEmail: env.POCKETBASE_SUPERUSER_EMAIL,
	superuserPassword: env.POCKETBASE_SUPERUSER_PASSWORD
});

The middleware sets event.locals.pb (per-request user client) and event.locals.admin (superuser client, when credentials are provided).

handlePocketbase(config)

| Option | Type | Default | Description | | ------------------- | ---------------- | ------------------- | -------------------------------------------------------------------------------------------------------------- | | pocketbaseUrl | string | required | Base URL of the upstream PocketBase server. | | superuserEmail | string \| null | null | Superuser email. Required for the admin proxy, type sync, OAuth post-processing, and the team/role lookup. | | superuserPassword | string \| null | null | Superuser password. Pair with superuserEmail. | | adminPath | string | '/admin' | URL path under which the PocketBase admin UI is proxied. Visit ${adminPath}/_/ for the dashboard. | | auth | AuthConfig | see below | Route protection. | | api | ApiConfig | see below | API proxying and API-key auth. | | files | FilesConfig | { enabled: true } | Proxy /api/files/* to PocketBase. |

auth

auth: {
	protectedRoutes?: string[] | null; // route ids that require a valid session
	loginPath?: string;                // default: '/login'
}

Unauthenticated requests to a protected route are redirected to ${loginPath}?redirect=... and the pb_auth cookie is cleared.

handlePocketbase({
	pocketbaseUrl: env.POCKETBASE_URL,
	auth: {
		protectedRoutes: ['/(app)'],
		loginPath: '/login'
	}
});

api

api: {
	enabled?: boolean; // default: false — when false, only the admin path is proxied
	apiKeys?: {
		enabled?: boolean;    // default: false
		collection?: string;  // default: 'api_keys' — must contain `key_hash` (argon2) and `user`
	};
}

When api.enabled is true, PocketBase API routes (/api/batch, /api/collections, /api/realtime, /api/files, /api/settings, /api/logs, /api/crons, /api/backups, /api/health) are proxied through SvelteKit. When apiKeys.enabled is also true, requests with Authorization: Bearer <keyId>.<secret> are authenticated against the configured collection and rewritten to an impersonated user token.

files

files: {
	enabled?: boolean; // default: true
}

When enabled, /api/files/* is proxied directly to PocketBase without going through SvelteKit auth (files are public per PocketBase's own rules).

Type sync

In dev mode, schema changes made through the proxied admin UI trigger a regenerate of .svelte-kit/types/pocketbase/$types.d.ts. The file declares three types under the @velastack/pocketbase module:

  • Models — the read shape of each collection (pb.collection('leads').getOne(...)).
  • Schemas — a z.ZodType<...> per collection, used to validate user-authored zod schemas at the type level.
  • Collections — record-service typings for pb.collections.getOne(...).

The Schemas mapping is what catches drift between your Zod validators and the live PocketBase schema. Add satisfies Schemas['<name>'] to any Zod schema and the file will fail to type-check whenever the collection changes:

import { z } from 'zod';
import type { Schemas } from '@velastack/pocketbase';

export const leadSchema = z.object({
	id: z.string().optional(),
	collectionId: z.string().optional(),
	name: z.string(),
	phone: z.string().optional(),
	message: z.string().optional()
}) satisfies Schemas['leads'];

If a field is added, removed, or its required-ness changes in PocketBase, tsc will reject this file until the Zod schema is updated.

Type sync runs within vela dev or as a one-off with vela sync.

License

MIT