Registry / database / pocketbase-zod-schema

pocketbase-zod-schema

JSON →
library0.7.1jsnpmunverified

PocketBase migration generator using Zod schemas for type-safe database migrations. Current stable version is 0.7.1, released in early 2025. Release cadence is irregular; check GitHub for updates. Key differentiators: integrates Zod for schema validation, generates both migration files and TypeScript types with full PocketBase client support. Alternative to manual migration scripts or other migration tools.

npm install pocketbase-zod-schema
INSTALL
IMPORT
SIG · POCKETBASE-ZOD-SCH
P
pocketbase-zod-schema
databasejavascriptv0.7.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

defineCollection
import { defineCollection } from 'pocketbase-zod-schema/schema'
import { defineCollection } from 'pocketbase-zod-schema'
Must import from subpath 'pocketbase-zod-schema/schema', not the main package.
TextField, BoolField, etc.
import { TextField, BoolField } from 'pocketbase-zod-schema/schema'
import { TextField } from 'pocketbase-zod-schema'
Field types are exported from the same subpath. TypeScript typing relies on these.
TypedPocketBase
import { TypedPocketBase } from './pocketbase-types'; // generated file
import { TypedPocketBase } from 'pocketbase-zod-schema'
This type is generated by CLI; not part of the package itself. Common mistake: trying to import from package.

Defines a PocketBase collection 'posts' using Zod schema with relations. Run commands to generate migrations and TypeScript types.

// Create src/schema/post.ts import { z } from "zod"; import { defineCollection, TextField, EditorField, BoolField, RelationField } from "pocketbase-zod-schema/schema"; export const PostSchema = z.object({ title: TextField({ min: 1, max: 200 }), content: EditorField(), published: BoolField(), author: RelationField({ collection: "users" }), }); export const PostCollection = defineCollection({ collectionName: "posts", schema: PostSchema, permissions: { listRule: '@request.auth.id != ""', viewRule: "", createRule: '@request.auth.id != ""', updateRule: "author = @request.auth.id", deleteRule: "author = @request.auth.id", }, }); // Then run: npx pocketbase-migrate generate // and: npx pocketbase-migrate generate-types
Debug
Known issues
gotchaRequires Node.js >=20.0.0. Older versions will fail at runtime.
fix
Upgrade Node.js to v20 or later.
affects: >=0.0.0
gotchaGenerate-types creates a TypedPocketBase interface. You must cast PocketBase instance manually.
fix
Use: const pb = new PocketBase('url') as TypedPocketBase;
affects: >=0.0.0
gotchaField types (TextField, BoolField, etc.) must be imported from 'pocketbase-zod-schema/schema', not the main package.
fix
Import from 'pocketbase-zod-schema/schema' specifically.
affects: >=0.0.0
gotchaGenerated types file (e.g., pocketbase-types.ts) is not part of the package; it must be generated with CLI.
fix
Run 'npx pocketbase-migrate generate-types' first.
affects: >=0.0.0
Errors
Common errors & fixes
Cannot find module 'pocketbase-zod-schema/schema'
Missing or incorrect import path in Node.js (CJS requires specific path resolution).
fix
Ensure you import from 'pocketbase-zod-schema/schema' and that package is installed.
TypedPocketBase is not exported from 'pocketbase-zod-schema'
Attempting to import TypedPocketBase directly from the package; it's generated by CLI.
fix
Run 'npx pocketbase-migrate generate-types' and import from the generated file.
TypeError: defineCollection is not a function
Trying to import defineCollection from wrong path or version mismatch.
fix
Use 'import { defineCollection } from "pocketbase-zod-schema/schema";'.
Upgrade
Version history
0.7.1latest on npm
Audit
Dependencies
zodrequiredRequired for defining schema using Zod primitives
Agent activity
7 hits · last 30 days
node
6
Resources
pocketbase-zod-schema — npm install pocketbase-zod-schema · libregistry