pocketbase-zod-schema 0.4.1 → 0.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.4.2](https://github.com/dastron/pocketbase-zod-schema/compare/pocketbase-zod-schema-v0.4.1...pocketbase-zod-schema-v0.4.2) (2026-01-21)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * create server export ([fda62fb](https://github.com/dastron/pocketbase-zod-schema/commit/fda62fb7fe359901e346de56247e37294f405f1f))
9
+
3
10
  ## [0.4.1](https://github.com/dastron/pocketbase-zod-schema/compare/pocketbase-zod-schema-v0.4.0...pocketbase-zod-schema-v0.4.1) (2026-01-19)
4
11
 
5
12
 
package/README.md CHANGED
@@ -91,6 +91,42 @@ This will create a migration file in your PocketBase migrations directory.
91
91
 
92
92
  **TypeScript Support:** You can use TypeScript (`.ts`) schema files directly - no compilation needed! The tool automatically handles TypeScript files using `tsx`.
93
93
 
94
+ ### 4. Generate TypeScript types
95
+
96
+ Generate type-safe TypeScript definitions from your schemas:
97
+
98
+ ```bash
99
+ # Generate types to pocketbase-types.ts
100
+ npx pocketbase-migrate generate-types
101
+
102
+ # Or specify a custom output path
103
+ npx pocketbase-migrate generate-types --output ./src/types/pocketbase.ts
104
+ ```
105
+
106
+ This creates a `pocketbase-types.ts` file with:
107
+ - Type-safe record interfaces for each collection (e.g., `PostsRecord`, `UsersRecord`)
108
+ - Response types with expand support (e.g., `PostsResponse`, `UsersResponse`)
109
+ - A `TypedPocketBase` interface for type-safe PocketBase client usage
110
+
111
+ **Usage in your application:**
112
+
113
+ ```typescript
114
+ import PocketBase from "pocketbase";
115
+ import { TypedPocketBase } from "./pocketbase-types";
116
+
117
+ const pb = new PocketBase("http://localhost:8090") as TypedPocketBase;
118
+
119
+ // Full type safety with autocomplete!
120
+ const post = await pb.collection("posts").getOne("post-id");
121
+ // post is typed as PostsResponse with full autocomplete
122
+
123
+ // Expand relations with type safety
124
+ const postWithAuthor = await pb.collection("posts").getOne("post-id", {
125
+ expand: "author"
126
+ });
127
+ // postWithAuthor.expand?.author is typed as UsersResponse
128
+ ```
129
+
94
130
  ---
95
131
 
96
132
  ## Schema Definition
@@ -521,10 +557,83 @@ npx pocketbase-migrate generate
521
557
  # Show what would be generated without writing files
522
558
  npx pocketbase-migrate status
523
559
 
560
+ # Generate TypeScript definitions from schemas
561
+ npx pocketbase-migrate generate-types
562
+
524
563
  # Force generation even with destructive changes
525
564
  npx pocketbase-migrate generate --force
526
565
  ```
527
566
 
567
+ ### `generate-types` Command
568
+
569
+ Generate type-safe TypeScript definitions from your Zod schemas.
570
+
571
+ ```bash
572
+ pocketbase-migrate generate-types [options]
573
+
574
+ Options:
575
+ -c, --config <path> Configuration file path
576
+ -o, --output <path> Output file path (default: pocketbase-types.ts)
577
+ --schema-dir <directory> Directory containing Zod schema files
578
+ -v, --verbose Enable verbose logging
579
+ ```
580
+
581
+ **What it generates:**
582
+
583
+ The `generate-types` command analyzes your Zod schemas and generates a TypeScript file (default: `pocketbase-types.ts`) containing:
584
+
585
+ 1. **Record interfaces** - Type-safe interfaces for each collection's data structure
586
+ ```typescript
587
+ export interface PostsRecord {
588
+ id: string;
589
+ created: string;
590
+ updated: string;
591
+ collectionId: string;
592
+ collectionName: "posts";
593
+ title: string;
594
+ content: string;
595
+ // ... other fields
596
+ }
597
+ ```
598
+
599
+ 2. **Response types** - Extended types with expand support for relations
600
+ ```typescript
601
+ export interface PostsResponse extends PostsRecord {
602
+ expand?: {
603
+ author?: UsersResponse;
604
+ tags?: TagsResponse[];
605
+ };
606
+ }
607
+ ```
608
+
609
+ 3. **TypedPocketBase interface** - Type-safe PocketBase client wrapper
610
+ ```typescript
611
+ export interface TypedPocketBase extends PocketBase {
612
+ collection(idOrName: "posts"): RecordService<PostsResponse>;
613
+ collection(idOrName: "users"): RecordService<UsersResponse>;
614
+ // ... other collections
615
+ }
616
+ ```
617
+
618
+ **Example usage:**
619
+
620
+ ```typescript
621
+ import PocketBase from "pocketbase";
622
+ import { TypedPocketBase } from "./pocketbase-types";
623
+
624
+ const pb = new PocketBase("http://localhost:8090") as TypedPocketBase;
625
+
626
+ // Full type safety!
627
+ const post = await pb.collection("posts").getOne("post-id");
628
+ // Type: PostsResponse
629
+
630
+ // Expand relations with type safety
631
+ const postWithAuthor = await pb.collection("posts").getOne("post-id", {
632
+ expand: "author"
633
+ });
634
+ // postWithAuthor.expand?.author is typed as UsersResponse | undefined
635
+ ```
636
+
528
637
  ### Configuration Options
529
638
 
530
639
  ```javascript