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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@sparkstone/pocketbase-schema

v0.10.0

Published

`@sparkstone/pocketbase-schema` is an open-source utility to generate TypeScript typings from [PocketBase](https://pocketbase.io/) schemas, enabling type-safe development with PocketBase APIs.

Readme

PocketBase Schema Generator

@sparkstone/pocketbase-schema is an open-source utility to generate TypeScript typings from PocketBase schemas, enabling type-safe development with PocketBase APIs.

Features

  • Automatically generate TypeScript definitions from your PocketBase schema.
  • Outputs a Collections enum for easy, type-safe querying.
  • Generates enums for select field types.
  • Supports modular usage as a CLI tool or a Node.js module.
  • Compatible with modern JavaScript and TypeScript projects.
  • Local-first and flexible configuration using cosmiconfig.

Installation

Install the package using npm:

npm install @sparkstone/pocketbase-schema --save-dev

Or with yarn:

yarn add @sparkstone/pocketbase-schema --dev

Or with pnpm:

pnpm add @sparkstone/pocketbase-schema --save-dev

Usage

CLI

You can use the tool directly from the command line to generate typings from a PocketBase instance:

pocketbase-schema

Configuration

The package supports configuration using a configuration file. Supported file formats include .json, .yaml, .js, or .ts. The default configuration file name is .pocketbase-schema.config.ts

Be sure to add your configuration file to .gitignore to prevent leaking credentials.

Example .pocketbase-schema.config.ts:

export default {
  email: '[email protected]', // Admin email for authentication
  password: 'yourpassword', // Admin password for authentication
  url: 'http://127.0.0.1:8090', // URL of the PocketBase instance
  schema: {
    outputPath: 'src/lib/pb.schema.json', // Path to save schema JSON
  },
  types: {
    outputPath: 'src/lib/pb.types.ts', // Path to save TypeScript definitions
  },
};

Required Configuration Fields

  • email: Admin email for authentication.
  • password: Admin password for authentication.
  • url: The URL of the PocketBase instance.

Optional Configuration Fields

  • schema.outputPath: Path to save the generated schema JSON.
  • types.outputPath: Path to save the generated TypeScript definitions.

Generated Types

The generated TypeScript definitions now include:

  • A Collections enum that maps to your PocketBase collections for type-safe queries.
  • Enums for any select field types defined in your schema, ensuring strict typing for these fields.

Example Usage

Here's how you can use the generated Collections enum and type-safe queries in your project:

import PocketBase from 'pocketbase';
import { Collections, YourCollection } from './path/to/pb.types';

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

async function fetchData() {
  const data = await pb.collection(Collections.YourCollection).getFullList<YourCollection>();
  console.log(data);
}

fetchData();

Replace YourCollection with the actual collection name, the names are PascalCase.

Expanding types

The recommended way to expand types it to create an interface that extends the main type

import { Comments, Posts, Reactions } from './path/to/pb.types';

interface Post extends Posts {
  expand: {
    comments: Comments[];
    reactions: Reactions[]
  }
}

pb.collection(Collections.Posts).getFullList<Post>({ expand: 'comments,reactions'});

Development

Scripts

  • pnpm run build: Build the package using microbundle.
  • pnpm run dev: Watch for changes and rebuild automatically.

Contributing

Contributions are welcome! Feel free to open issues or submit pull requests to enhance the functionality.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Acknowledgments


For more details and updates, visit the repository.