{"library":"pocketbase-typegen","title":"PocketBase Typegen","description":"PocketBase Typegen is a utility that generates TypeScript definitions directly from your PocketBase database schema. It supports various input sources including a live PocketBase instance URL, a local SQLite database file, or an exported JSON schema. The current stable version is `1.4.1`, with releases occurring regularly to maintain compatibility with new PocketBase versions and introduce new features. Key differentiators include the automatic generation of a `TypedPocketBase` type, which allows for fully type-safe usage of the PocketBase JavaScript SDK, as well as distinct types for individual collections, expand relations, and `Create`/`Update` operations, significantly enhancing developer experience and reducing runtime errors in TypeScript projects.","language":"javascript","status":"active","last_verified":"Wed Apr 22","install":{"commands":["npm install pocketbase-typegen"],"cli":{"name":"pocketbase-typegen","version":null}},"imports":["import { TypedPocketBase } from './pocketbase-types'","import { Collections } from './pocketbase-types'","import { MyCollectionResponse } from './pocketbase-types'","import { Create, Update } from './pocketbase-types'"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import PocketBase from 'pocketbase';\nimport { TypedPocketBase } from './pocketbase-types';\nimport { Collections, Create, Update, TasksResponse, CommentsResponse, UsersResponse } from './pocketbase-types';\n\n// First, generate your types. Run this command in your terminal:\n// npx pocketbase-typegen --url https://myproject.pockethost.io --email admin@myproject.com --password 'secr3tp@ssword!'\n\nconst pb = new PocketBase('http://127.0.0.1:8090') as TypedPocketBase;\n\nasync function exampleUsage() {\n  // Fetch a single task with full type safety\n  const task = await pb.collection(Collections.Tasks).getOne('RECORD_ID');\n  console.log('Fetched task:', task.title);\n\n  // Example with expanded relations and JSON field types\n  type Metadata = { likes: number };\n  type Expand = { user: UsersResponse };\n  const commentResult = await pb.collection(Collections.Comments).getOne<CommentsResponse<Metadata, Expand>>('COMMENT_RECORD_ID', { expand: 'user' });\n  console.log('Comment metadata likes:', commentResult.metadata?.likes);\n  console.log('Comment user username:', commentResult.expand.user.username);\n\n  // Create a new user record\n  const newUser: Create<Collections.Users> = {\n    name: 'Jane Doe',\n    username: 'janedoe',\n    password: 'password123',\n    passwordConfirm: 'password123',\n    email: 'jane@example.com',\n    emailVisibility: true,\n    verified: false,\n  };\n  await pb.collection(Collections.Users).create(newUser);\n  console.log('User created successfully.');\n\n  // Update an existing user record\n  const updatedUser: Update<Collections.Users> = {\n    name: 'Jane Smith',\n  };\n  await pb.collection(Collections.Users).update('USER_RECORD_ID', updatedUser);\n  console.log('User updated successfully.');\n}\n\nexampleUsage().catch(console.error);","lang":"typescript","description":"Generates PocketBase TypeScript types from a remote instance and demonstrates fully type-safe interaction with the PocketBase SDK for fetching, creating, and updating records, including advanced use cases like expanded relations and custom JSON field types.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}