{"id":13410094,"url":"https://github.com/patmood/pocketbase-typegen","last_synced_at":"2026-01-18T11:07:48.771Z","repository":{"id":62746430,"uuid":"551224363","full_name":"patmood/pocketbase-typegen","owner":"patmood","description":"Typescript generation for pocketbase records","archived":false,"fork":false,"pushed_at":"2023-10-30T04:54:58.000Z","size":451,"stargazers_count":513,"open_issues_count":9,"forks_count":16,"subscribers_count":4,"default_branch":"main","last_synced_at":"2024-09-30T22:11:58.713Z","etag":null,"topics":["pocketbase","typegen","typescript"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/pocketbase-typegen","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/patmood.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2022-10-14T03:03:47.000Z","updated_at":"2024-09-30T21:21:21.000Z","dependencies_parsed_at":"2024-01-06T00:21:30.205Z","dependency_job_id":"941d8a14-5d68-4392-9131-e3ee60cc6824","html_url":"https://github.com/patmood/pocketbase-typegen","commit_stats":{"total_commits":83,"total_committers":5,"mean_commits":16.6,"dds":"0.15662650602409633","last_synced_commit":"45a1c1fc7dfd955b08523337a35525a286e2382b"},"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/patmood%2Fpocketbase-typegen","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/patmood%2Fpocketbase-typegen/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/patmood%2Fpocketbase-typegen/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/patmood%2Fpocketbase-typegen/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/patmood","download_url":"https://codeload.github.com/patmood/pocketbase-typegen/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221481989,"owners_count":16829979,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["pocketbase","typegen","typescript"],"created_at":"2024-07-30T20:01:04.937Z","updated_at":"2025-03-14T15:31:54.751Z","avatar_url":"https://github.com/patmood.png","language":"TypeScript","funding_links":[],"categories":["Typescript tools","TypeScript","Tools/Plugin","Top PocketBase-specific Projects (\u003e100 stars)"],"sub_categories":["TypeScript"],"readme":"# Pocketbase Typegen\n\nGenerate typescript definitions from your [pocketbase.io](https://pocketbase.io/) schema.\n\n## Quickstart\n\n`npx pocketbase-typegen --db ./pb_data/data.db --out pocketbase-types.ts`\n\nThis will produce types for all your PocketBase collections to use in your frontend typescript codebase.\n\n## Version Support\n\n| PocketBase | pocketbase-typegen | npx command                                                                    |\n| ---------- | ------------------ | ------------------------------------------------------------------------------ |\n| v0.23.x    | v1.3.x             | npx pocketbase-typegen --db ./pb_data/data.db --out pocketbase-types.ts        |\n| v0.18.x    | v1.2.x             | npx pocketbase-typegen@1.2.1 --db ./pb_data/data.db --out pocketbase-types.ts  |\n| v0.8.x     | v1.1.x             | npx pocketbase-typegen@1.1.1 --db ./pb_data/data.db --out pocketbase-types.ts  |\n| v0.7.x     | v1.0.x             | npx pocketbase-typegen@1.0.13 --db ./pb_data/data.db --out pocketbase-types.ts |\n\n## Usage\n\n```\nOptions:\n  -V, --version          output the version number\n  -d, --db \u003cchar\u003e        path to the pocketbase SQLite database\n  -j, --json \u003cchar\u003e      path to JSON schema exported from pocketbase admin UI\n  -u, --url \u003cchar\u003e       URL to your hosted pocketbase instance. When using this options you must also provide email and password options.\n  --email \u003cchar\u003e     email for an admin pocketbase user. Use this with the --url option\n  -p, --password \u003cchar\u003e  password for an admin pocketbase user. Use this with the --url option\n  -o, --out \u003cchar\u003e       path to save the typescript output file (default: \"pocketbase-types.ts\")\n  --no-sdk               remove the pocketbase package dependency. A typed version of the SDK will not be generated.\n  --env [path]       flag to use environment variables for configuration. Add PB_TYPEGEN_URL, PB_TYPEGEN_EMAIL, PB_TYPEGEN_PASSWORD to your .env file. Optionally provide a path to your .env file\n  -h, --help             display help for command\n```\n\nDB example:\n\n`npx pocketbase-typegen --db ./pb_data/data.db`\n\nJSON example (export JSON schema from the pocketbase admin dashboard):\n\n`npx pocketbase-typegen --json ./pb_schema.json`\n\nURL example:\n\n`npx pocketbase-typegen --url https://myproject.pockethost.io --email admin@myproject.com --password 'secr3tp@ssword!'`\n\nENV example (add PB_TYPEGEN_URL, PB_TYPEGEN_EMAIL and PB_TYPEGEN_PASSWORD to your .env file):\n\n`npx pocketbase-typegen --env`\n\n.env:\n\n```\nPB_TYPEGEN_URL=https://myproject.pockethost.io\nPB_TYPEGEN_EMAIL=admin@myproject.com\nPB_TYPEGEN_PASSWORD=secr3tp@ssword!\n```\n\nAdd it to your projects `package.json`:\n\n```\n\"scripts\": {\n  \"typegen\": \"pocketbase-typegen --db ./pb_data/data.db\",\n},\n```\n\n## Example Output\n\nThe output is a typescript file `pocketbase-types.ts` ([example](./test/pocketbase-types-example.ts)) which will contain:\n\n- `Collections` An enum of all collections.\n- `[CollectionName]Record` One type for each collection (eg ProfilesRecord).\n- `[CollectionName]Response` One response type for each collection (eg ProfilesResponse) which includes system fields. This is what is returned from the PocketBase API.\n  - `[CollectionName][FieldName]Options` If the collection contains a select field with set values, an enum of the options will be generated.\n- `CollectionRecords` A type mapping each collection name to the record type.\n- `CollectionResponses` A type mapping each collection name to the response type.\n- `TypedPocketBase` A type for usage with type asserted PocketBase instance.\n\n## Example Usage\n\nUsing PocketBase SDK v0.18.3+, collections can be [automatically typed](https://github.com/pocketbase/js-sdk#specify-typescript-definitions) using the generated `TypedPocketBase` type:\n\n```typescript\nimport { TypedPocketBase } from \"./pocketbase-types\"\n\nconst pb = new PocketBase(\"http://127.0.0.1:8090\") as TypedPocketBase\n\nawait pb.collection(\"tasks\").getOne(\"RECORD_ID\") // -\u003e results in TaskResponse\nawait pb.collection(\"posts\").getOne(\"RECORD_ID\") // -\u003e results in PostResponse\n```\n\nAlternatively, you can use generic types for each request, eg:\n\n```typescript\nimport { Collections, TasksResponse } from \"./pocketbase-types\"\n\nawait pb.collection(Collections.Tasks).getOne\u003cTasksResponse\u003e(\"RECORD_ID\") // -\u003e results in TaskResponse\n```\n\n## Example Advanced Usage\n\nYou can provide types for JSON fields and [expanded relations](https://pocketbase.io/docs/expanding-relations/) by passing generic arguments to the Response types:\n\n```typescript\nimport { Collections, CommentsResponse, UserResponse } from \"./pocketbase-types\"\n\n/**\n  type CommentsRecord\u003cTmetadata = unknown\u003e = {\n    text: string\n    metadata: null | Tmetadata // This is a json field\n    user: RecordIdString // This is a relation field\n  }\n*/\ntype Metadata = {\n  likes: number\n}\ntype Expand = {\n  user: UsersResponse\n}\nconst result = await pb\n  .collection(Collections.Comments)\n  .getOne\u003cCommentsResponse\u003cMetadata, Expand\u003e\u003e(\"RECORD_ID\", { expand: \"user\" })\n\n// Now you can access the expanded relation with type safety and hints in your IDE\nresult.expand?.user.username\n```\n\n## Status\n\n![](https://github.com/patmood/pocketbase-typegen/actions/workflows/test.yml/badge.svg?branch=main) ![](https://github.com/patmood/pocketbase-typegen/actions/workflows/integration.yml/badge.svg?branch=main)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpatmood%2Fpocketbase-typegen","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpatmood%2Fpocketbase-typegen","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpatmood%2Fpocketbase-typegen/lists"}