Type-safe PocketBase development — automatically.
pocketbase-schema
is a utility that generates TypeScript types from your PocketBase collections. It’s built for developers who want safety, clarity, and DX improvements when building apps on top of PocketBase.
Features
- Automatic Type Generation: Pull your PocketBase schema and generate complete TypeScript definitions for collections and records.
Collections
Enum: Access collection names as constants instead of raw strings.- Field Type Enums: Automatically generate enums for
select
field options. - Flexible CLI & API: Run it as a script or import it into your toolchain. It supports both approaches cleanly.
- Local-First Config: Uses
cosmiconfig
so you can configure it withpocketbase-schema.config.js
,package.json
, or a custom location.
Installation
npm install @sparkstone/pocketbase-schema --save-dev
or
pnpm add @sparkstone/pocketbase-schema --save-dev
Usage
Once installed, run the CLI to generate types from your schema export:
pocketbase-schema generate --input=pb_schema.json --output=src/lib/pb-types.ts
You can also run it programmatically in a Node script:
import { generate } from '@sparkstone/pocketbase-schema';
generate({
input: './pb_schema.json',
output: './src/lib/pb-types.ts',
});
“We built pocketbase-schema because we love PocketBase — and we wanted full type safety without manual copy-pasting.”
— The Sparkstone Team