pocketbase-zod-schema 1.0.0 → 1.0.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.
Files changed (101) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/README.md +28 -69
  3. package/dist/cli/migrate.cjs +548 -674
  4. package/dist/cli/migrate.cjs.map +1 -1
  5. package/dist/cli/migrate.js +545 -671
  6. package/dist/cli/migrate.js.map +1 -1
  7. package/dist/index.cjs +37 -555
  8. package/dist/index.cjs.map +1 -1
  9. package/dist/index.d.cts +903 -6
  10. package/dist/index.d.ts +903 -6
  11. package/dist/index.js +38 -540
  12. package/dist/index.js.map +1 -1
  13. package/dist/server.cjs +674 -2614
  14. package/dist/server.cjs.map +1 -1
  15. package/dist/server.d.cts +1344 -18
  16. package/dist/server.d.ts +1344 -18
  17. package/dist/server.js +673 -2481
  18. package/dist/server.js.map +1 -1
  19. package/package.json +2 -64
  20. package/dist/cli/index.cjs +0 -7873
  21. package/dist/cli/index.cjs.map +0 -1
  22. package/dist/cli/index.d.cts +0 -32
  23. package/dist/cli/index.d.ts +0 -32
  24. package/dist/cli/index.js +0 -7819
  25. package/dist/cli/index.js.map +0 -1
  26. package/dist/cli/utils/index.cjs +0 -596
  27. package/dist/cli/utils/index.cjs.map +0 -1
  28. package/dist/cli/utils/index.d.cts +0 -282
  29. package/dist/cli/utils/index.d.ts +0 -282
  30. package/dist/cli/utils/index.js +0 -542
  31. package/dist/cli/utils/index.js.map +0 -1
  32. package/dist/enums.cjs +0 -19
  33. package/dist/enums.cjs.map +0 -1
  34. package/dist/enums.d.cts +0 -11
  35. package/dist/enums.d.ts +0 -11
  36. package/dist/enums.js +0 -17
  37. package/dist/enums.js.map +0 -1
  38. package/dist/fields-B96iGprI.d.cts +0 -480
  39. package/dist/fields-B96iGprI.d.ts +0 -480
  40. package/dist/migration/analyzer.cjs +0 -1725
  41. package/dist/migration/analyzer.cjs.map +0 -1
  42. package/dist/migration/analyzer.d.cts +0 -245
  43. package/dist/migration/analyzer.d.ts +0 -245
  44. package/dist/migration/analyzer.js +0 -1684
  45. package/dist/migration/analyzer.js.map +0 -1
  46. package/dist/migration/diff.cjs +0 -943
  47. package/dist/migration/diff.cjs.map +0 -1
  48. package/dist/migration/diff.d.cts +0 -370
  49. package/dist/migration/diff.d.ts +0 -370
  50. package/dist/migration/diff.js +0 -911
  51. package/dist/migration/diff.js.map +0 -1
  52. package/dist/migration/engine.cjs +0 -3263
  53. package/dist/migration/engine.cjs.map +0 -1
  54. package/dist/migration/engine.d.cts +0 -105
  55. package/dist/migration/engine.d.ts +0 -105
  56. package/dist/migration/engine.js +0 -3173
  57. package/dist/migration/engine.js.map +0 -1
  58. package/dist/migration/generator.cjs +0 -1596
  59. package/dist/migration/generator.cjs.map +0 -1
  60. package/dist/migration/generator.d.cts +0 -493
  61. package/dist/migration/generator.d.ts +0 -493
  62. package/dist/migration/generator.js +0 -1529
  63. package/dist/migration/generator.js.map +0 -1
  64. package/dist/migration/index.cjs +0 -8190
  65. package/dist/migration/index.cjs.map +0 -1
  66. package/dist/migration/index.d.cts +0 -193
  67. package/dist/migration/index.d.ts +0 -193
  68. package/dist/migration/index.js +0 -8015
  69. package/dist/migration/index.js.map +0 -1
  70. package/dist/migration/snapshot.cjs +0 -2814
  71. package/dist/migration/snapshot.cjs.map +0 -1
  72. package/dist/migration/snapshot.d.cts +0 -186
  73. package/dist/migration/snapshot.d.ts +0 -186
  74. package/dist/migration/snapshot.js +0 -2779
  75. package/dist/migration/snapshot.js.map +0 -1
  76. package/dist/migration/utils/index.cjs +0 -891
  77. package/dist/migration/utils/index.cjs.map +0 -1
  78. package/dist/migration/utils/index.d.cts +0 -66
  79. package/dist/migration/utils/index.d.ts +0 -66
  80. package/dist/migration/utils/index.js +0 -854
  81. package/dist/migration/utils/index.js.map +0 -1
  82. package/dist/mutator.cjs +0 -355
  83. package/dist/mutator.cjs.map +0 -1
  84. package/dist/mutator.d.cts +0 -164
  85. package/dist/mutator.d.ts +0 -164
  86. package/dist/mutator.js +0 -353
  87. package/dist/mutator.js.map +0 -1
  88. package/dist/schema.cjs +0 -715
  89. package/dist/schema.cjs.map +0 -1
  90. package/dist/schema.d.cts +0 -563
  91. package/dist/schema.d.ts +0 -563
  92. package/dist/schema.js +0 -674
  93. package/dist/schema.js.map +0 -1
  94. package/dist/type-mapper-BSPTj8t5.d.cts +0 -216
  95. package/dist/type-mapper-D31WYDee.d.ts +0 -216
  96. package/dist/types-B_MLb1Ob.d.ts +0 -475
  97. package/dist/types-CnzfX6JH.d.cts +0 -148
  98. package/dist/types-Do3jyFBm.d.ts +0 -148
  99. package/dist/types-upZBVMfb.d.cts +0 -475
  100. package/dist/verify-BF72n2df.d.ts +0 -402
  101. package/dist/verify-DTzYpiXX.d.cts +0 -402
package/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # Changelog
2
2
 
3
+ ## [1.0.2](https://github.com/dastron/pocketbase-zod-schema/compare/pocketbase-zod-schema-v1.0.1...pocketbase-zod-schema-v1.0.2) (2026-07-28)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * tighten library exports ([81221a6](https://github.com/dastron/pocketbase-zod-schema/commit/81221a6c3d5e8ed28f20a90ea57b862aa00b5713))
9
+ * tighten library exports ([b228a10](https://github.com/dastron/pocketbase-zod-schema/commit/b228a105d29e05f24feb266faafeb24e9b091f8d))
10
+
11
+ ## [1.0.1](https://github.com/dastron/pocketbase-zod-schema/compare/pocketbase-zod-schema-v1.0.0...pocketbase-zod-schema-v1.0.1) (2026-07-28)
12
+
13
+
14
+ ### Bug Fixes
15
+
16
+ * bug fixes for schema ([7007f4d](https://github.com/dastron/pocketbase-zod-schema/commit/7007f4dda37bef732cfcdb126e1a8dba79ece120))
17
+ * bug fixes for schema ([17bd233](https://github.com/dastron/pocketbase-zod-schema/commit/17bd23392a0455ff5b94d8cb54b30fbdcad7ffbc))
18
+
3
19
  ## [1.0.0](https://github.com/dastron/pocketbase-zod-schema/compare/pocketbase-zod-schema-v0.7.2...pocketbase-zod-schema-v1.0.0) (2026-07-28)
4
20
 
5
21
 
package/README.md CHANGED
@@ -41,7 +41,7 @@ import {
41
41
  BoolField,
42
42
  RelationField,
43
43
  RelationsField,
44
- } from "pocketbase-zod-schema/schema";
44
+ } from "pocketbase-zod-schema";
45
45
 
46
46
  // Define the Zod schema
47
47
  export const PostSchema = z.object({
@@ -142,7 +142,7 @@ The recommended way to define collections is using `defineCollection()`, which p
142
142
 
143
143
  ```typescript
144
144
  import { z } from "zod";
145
- import { defineCollection, TextField, EditorField, RelationField } from "pocketbase-zod-schema/schema";
145
+ import { defineCollection, TextField, EditorField, RelationField } from "pocketbase-zod-schema";
146
146
 
147
147
  export const PostCollectionSchema = z.object({
148
148
  title: TextField({ min: 1, max: 200 }),
@@ -191,8 +191,6 @@ This pattern allows:
191
191
  - `PostSchema` - Used for type inference (`z.infer<typeof PostSchema>`) and validation
192
192
  - `PostCollection` - Used by the migration generator (has collection metadata)
193
193
 
194
- **Note:** You can still use `withPermissions()` and `withIndexes()` separately if you prefer, but `defineCollection()` is recommended for new code.
195
-
196
194
  ### Field Types
197
195
 
198
196
  The library provides explicit field helper functions for all PocketBase field types. These helpers embed PocketBase-specific metadata and provide type-safe configuration options.
@@ -212,7 +210,7 @@ The library provides explicit field helper functions for all PocketBase field ty
212
210
  | `SelectField(values, options?)` | select | Single or multiple select field | `status: SelectField(["draft", "published"])` |
213
211
  | `FileField(options?)` | file | Single file upload field | `avatar: FileField({ mimeTypes: ["image/*"] })` |
214
212
  | `FilesField(options?)` | file | Multiple file upload field | `images: FilesField({ maxSelect: 5 })` |
215
- | `JSONField(schema?)` | json | JSON field with optional schema | `metadata: JSONField()` |
213
+ | `JSONField(schema?, options?)` | json | JSON field with optional schema and size cap | `metadata: JSONField({ maxSize: "5M" })` |
216
214
  | `GeoPointField()` | geoPoint | Geographic coordinates field | `location: GeoPointField()` |
217
215
  | `RelationField(config)` | relation | Single relation field | `author: RelationField({ collection: "users" })` |
218
216
  | `RelationsField(config)` | relation | Multiple relation field | `tags: RelationsField({ collection: "tags" })` |
@@ -278,8 +276,11 @@ The library provides explicit field helper functions for all PocketBase field ty
278
276
  - `maxSelect?: number` - Maximum number of files allowed
279
277
  - Returns: `z.ZodType<string[], (File | string)[]>`
280
278
 
281
- **JSONField(schema?)**
279
+ **JSONField(schema?, options?)**
282
280
  - `schema?: z.ZodTypeAny` - Optional Zod schema for JSON structure validation
281
+ - `options?.maxSize?: number | "5M"` - Maximum serialized size, in bytes or with a `K`/`M`/`G`
282
+ suffix. PocketBase applies a 1MB default when unset, so larger payloads must set it. Either
283
+ argument may be passed alone: `JSONField({ maxSize: "5M" })`
283
284
  - Returns: `T | z.ZodRecord<z.ZodString, z.ZodAny>`
284
285
 
285
286
  **GeoPointField()**
@@ -307,7 +308,7 @@ import {
307
308
  GeoPointField,
308
309
  RelationField,
309
310
  RelationsField,
310
- } from "pocketbase-zod-schema/schema";
311
+ } from "pocketbase-zod-schema";
311
312
 
312
313
  const ProductSchema = z.object({
313
314
  // Text fields
@@ -395,7 +396,7 @@ The library still supports plain Zod types for backward compatibility. The migra
395
396
  Use `RelationField()` for single relations and `RelationsField()` for multiple relations:
396
397
 
397
398
  ```typescript
398
- import { RelationField, RelationsField } from "pocketbase-zod-schema/schema";
399
+ import { RelationField, RelationsField } from "pocketbase-zod-schema";
399
400
 
400
401
  const ProjectSchema = z.object({
401
402
  name: z.string(),
@@ -433,9 +434,9 @@ const ProjectSchema = z.object({
433
434
  - `minSelect?: number` - Minimum number of relations required (default: `0`)
434
435
  - `maxSelect?: number` - Maximum number of relations allowed (default: `999`)
435
436
 
436
- > Relations can also be detected from field naming (a `z.string()` starting with an uppercase
437
- > letter, or a `z.array(z.string())` containing one). That fallback exists for backward
438
- > compatibility — prefer the helpers, which name the target collection explicitly.
437
+ > Relations are explicit-only. There is no naming-convention fallback — a field is a relation only
438
+ > when it's built with `RelationField()`/`RelationsField()`; a bare `z.array(z.string())` maps to a
439
+ > `json` field, not a relation.
439
440
 
440
441
  ### Defining View Collections
441
442
 
@@ -445,7 +446,7 @@ only:
445
446
 
446
447
  ```typescript
447
448
  import { z } from "zod";
448
- import { baseSchema, defineView, sql } from "pocketbase-zod-schema/schema";
449
+ import { baseSchema, defineView, sql } from "pocketbase-zod-schema";
449
450
 
450
451
  export const ProductStatsSchema = z
451
452
  .object({
@@ -483,12 +484,12 @@ constraints into compile errors instead of apply-time failures.
483
484
 
484
485
  ### Defining Permissions
485
486
 
486
- Use `defineCollection()` with permissions, or `withPermissions()` to attach API rules to your schema:
487
+ Attach API rules to a collection through `defineCollection({ permissions })`:
487
488
 
488
489
  ```typescript
489
- import { defineCollection, withPermissions } from "pocketbase-zod-schema/schema";
490
+ import { defineCollection } from "pocketbase-zod-schema";
490
491
 
491
- // Using defineCollection (recommended)
492
+ // Explicit rules
492
493
  const PostCollection = defineCollection({
493
494
  collectionName: "posts",
494
495
  schema: z.object({ title: z.string() }),
@@ -501,7 +502,7 @@ const PostCollection = defineCollection({
501
502
  },
502
503
  });
503
504
 
504
- // Using templates with defineCollection
505
+ // Using a template
505
506
  const ProjectCollection = defineCollection({
506
507
  collectionName: "projects",
507
508
  schema: z.object({ title: z.string(), owner: RelationField({ collection: "users" }) }),
@@ -510,18 +511,6 @@ const ProjectCollection = defineCollection({
510
511
  ownerField: "owner",
511
512
  },
512
513
  });
513
-
514
- // Using withPermissions (alternative approach)
515
- const PostSchemaAlt = withPermissions(
516
- z.object({ title: z.string() }),
517
- {
518
- listRule: '@request.auth.id != ""',
519
- viewRule: "",
520
- createRule: '@request.auth.id != ""',
521
- updateRule: "author = @request.auth.id",
522
- deleteRule: "author = @request.auth.id",
523
- }
524
- );
525
514
  ```
526
515
 
527
516
  #### Permission Templates
@@ -538,7 +527,7 @@ const PostSchemaAlt = withPermissions(
538
527
  Two more have no template name; call them and pass the result as `permissions`:
539
528
 
540
529
  ```typescript
541
- import { PermissionTemplates } from "pocketbase-zod-schema/schema";
530
+ import { PermissionTemplates } from "pocketbase-zod-schema";
542
531
 
543
532
  PermissionTemplates.locked(); // every rule null (superusers only)
544
533
  PermissionTemplates.readOnlyAuthenticated(); // authenticated read, writes locked
@@ -550,7 +539,6 @@ expression. `manageRule` applies to auth collections only.
550
539
  #### Template with Custom Overrides
551
540
 
552
541
  ```typescript
553
- // Using defineCollection (recommended)
554
542
  const PostCollection = defineCollection({
555
543
  collectionName: "posts",
556
544
  schema: z.object({ title: z.string(), author: RelationField({ collection: "users" }) }),
@@ -563,26 +551,15 @@ const PostCollection = defineCollection({
563
551
  },
564
552
  },
565
553
  });
566
-
567
- // Using withPermissions (alternative)
568
- const PostSchemaAlt = withPermissions(schema, {
569
- template: "owner-only",
570
- ownerField: "author",
571
- customRules: {
572
- listRule: '@request.auth.id != ""',
573
- viewRule: "",
574
- },
575
- });
576
554
  ```
577
555
 
578
556
  ### Defining Indexes
579
557
 
580
- Use `defineCollection()` with indexes, or `withIndexes()` to define database indexes:
558
+ Declare database indexes through `defineCollection({ indexes })`:
581
559
 
582
560
  ```typescript
583
- import { defineCollection, withIndexes, withPermissions } from "pocketbase-zod-schema/schema";
561
+ import { defineCollection } from "pocketbase-zod-schema";
584
562
 
585
- // Using defineCollection (recommended)
586
563
  const UserCollection = defineCollection({
587
564
  collectionName: "users",
588
565
  schema: z.object({
@@ -597,21 +574,6 @@ const UserCollection = defineCollection({
597
574
  'CREATE INDEX idx_users_username ON users (username)',
598
575
  ],
599
576
  });
600
-
601
- // Using withIndexes (alternative)
602
- const UserSchemaAlt = withIndexes(
603
- withPermissions(
604
- z.object({
605
- email: z.string().email(),
606
- username: z.string(),
607
- }),
608
- { template: "authenticated" }
609
- ),
610
- [
611
- 'CREATE UNIQUE INDEX idx_users_email ON users (email)',
612
- 'CREATE INDEX idx_users_username ON users (username)',
613
- ]
614
- );
615
577
  ```
616
578
 
617
579
  ---
@@ -815,7 +777,7 @@ CLI > environment > config file > defaults.
815
777
 
816
778
  ## Programmatic API
817
779
 
818
- For custom workflows, use the programmatic API:
780
+ For custom workflows, use the programmatic API from `pocketbase-zod-schema/server`:
819
781
 
820
782
  ```typescript
821
783
  import {
@@ -823,14 +785,14 @@ import {
823
785
  compare,
824
786
  generate,
825
787
  loadSnapshotWithMigrations,
826
- } from "pocketbase-zod-schema/migration";
788
+ } from "pocketbase-zod-schema/server";
827
789
 
828
790
  async function generateMigration() {
829
791
  const schemaDir = "./src/schema";
830
792
  const migrationsDir = "./pocketbase/pb_migrations";
831
793
 
832
794
  // Parse all schema files
833
- const currentSchema = await parseSchemaFiles(schemaDir);
795
+ const currentSchema = await parseSchemaFiles({ schemaDir });
834
796
 
835
797
  // Reconstruct the current database state by executing the existing migrations.
836
798
  // Returns null when there is nothing to replay; throws SnapshotError if a
@@ -849,12 +811,8 @@ async function generateMigration() {
849
811
  }
850
812
  ```
851
813
 
852
- > Use `loadSnapshotWithMigrations`, not `loadSnapshotIfExists`. The latter executes **only** the
853
- > newest snapshot file and ignores every migration after it, so it is almost never the current
854
- > state.
855
-
856
814
  The execution engine, round-trip verification and the goja lint are also available directly from
857
- `pocketbase-zod-schema/migration/engine` — see the
815
+ `pocketbase-zod-schema/server` — see the
858
816
  [Execution Engine guide](https://github.com/dastron/pocketbase-zod-schema/blob/main/docs/EXECUTION_ENGINE.md).
859
817
 
860
818
  ---
@@ -866,7 +824,7 @@ Here's a complete example of a blog schema with users, posts, and comments:
866
824
  ```typescript
867
825
  // src/schema/user.ts
868
826
  import { z } from "zod";
869
- import { baseSchema, defineCollection, TextField, EmailField } from "pocketbase-zod-schema/schema";
827
+ import { baseSchema, defineCollection, TextField, EmailField } from "pocketbase-zod-schema";
870
828
 
871
829
  // Input schema for forms (includes passwordConfirm for validation)
872
830
  export const UserInputSchema = z.object({
@@ -891,6 +849,7 @@ export const UserSchema = UserCollectionSchema.extend(baseSchema);
891
849
  // Collection definition with permissions and indexes
892
850
  export const UserCollection = defineCollection({
893
851
  collectionName: "Users",
852
+ type: "auth", // auth collections must opt in explicitly; it is never inferred
894
853
  schema: UserSchema,
895
854
  permissions: {
896
855
  listRule: "id = @request.auth.id",
@@ -916,7 +875,7 @@ import {
916
875
  DateField,
917
876
  RelationField,
918
877
  RelationsField,
919
- } from "pocketbase-zod-schema/schema";
878
+ } from "pocketbase-zod-schema";
920
879
 
921
880
  // Define the Zod schema
922
881
  export const PostSchema = z.object({
@@ -950,7 +909,7 @@ export const PostCollection = defineCollection({
950
909
  ```typescript
951
910
  // src/schema/comment.ts
952
911
  import { z } from "zod";
953
- import { defineCollection, TextField, RelationField } from "pocketbase-zod-schema/schema";
912
+ import { defineCollection, TextField, RelationField } from "pocketbase-zod-schema";
954
913
 
955
914
  // Define the Zod schema
956
915
  export const CommentSchema = z.object({