pocketbase-zod-schema 1.0.1 → 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 +8 -0
  2. package/README.md +23 -67
  3. package/dist/cli/migrate.cjs +359 -625
  4. package/dist/cli/migrate.cjs.map +1 -1
  5. package/dist/cli/migrate.js +356 -622
  6. package/dist/cli/migrate.js.map +1 -1
  7. package/dist/index.cjs +9 -549
  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 +10 -534
  12. package/dist/index.js.map +1 -1
  13. package/dist/server.cjs +539 -2642
  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 +538 -2508
  18. package/dist/server.js.map +1 -1
  19. package/package.json +2 -64
  20. package/dist/cli/index.cjs +0 -8013
  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 -7959
  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-D2ZkO9Pe.d.cts +0 -511
  39. package/dist/fields-D2ZkO9Pe.d.ts +0 -511
  40. package/dist/migration/analyzer.cjs +0 -1769
  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 -1728
  45. package/dist/migration/analyzer.js.map +0 -1
  46. package/dist/migration/diff.cjs +0 -959
  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 -927
  51. package/dist/migration/diff.js.map +0 -1
  52. package/dist/migration/engine.cjs +0 -3340
  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 -3250
  57. package/dist/migration/engine.js.map +0 -1
  58. package/dist/migration/generator.cjs +0 -1632
  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 -1565
  63. package/dist/migration/generator.js.map +0 -1
  64. package/dist/migration/index.cjs +0 -8331
  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 -8155
  69. package/dist/migration/index.js.map +0 -1
  70. package/dist/migration/snapshot.cjs +0 -2891
  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 -2856
  75. package/dist/migration/snapshot.js.map +0 -1
  76. package/dist/migration/utils/index.cjs +0 -946
  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 -908
  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 -737
  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 -696
  93. package/dist/schema.js.map +0 -1
  94. package/dist/type-mapper-DElLGPUA.d.ts +0 -235
  95. package/dist/type-mapper-DRxu96CN.d.cts +0 -235
  96. package/dist/types-Bs7N3Gwt.d.cts +0 -148
  97. package/dist/types-BxJs7mmh.d.ts +0 -504
  98. package/dist/types-ByOyly4V.d.ts +0 -148
  99. package/dist/types-CY5e-ORN.d.cts +0 -504
  100. package/dist/verify-CkMwxocW.d.cts +0 -402
  101. package/dist/verify-DqY4TpV6.d.ts +0 -402
package/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
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
+
3
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)
4
12
 
5
13
 
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.
@@ -310,7 +308,7 @@ import {
310
308
  GeoPointField,
311
309
  RelationField,
312
310
  RelationsField,
313
- } from "pocketbase-zod-schema/schema";
311
+ } from "pocketbase-zod-schema";
314
312
 
315
313
  const ProductSchema = z.object({
316
314
  // Text fields
@@ -398,7 +396,7 @@ The library still supports plain Zod types for backward compatibility. The migra
398
396
  Use `RelationField()` for single relations and `RelationsField()` for multiple relations:
399
397
 
400
398
  ```typescript
401
- import { RelationField, RelationsField } from "pocketbase-zod-schema/schema";
399
+ import { RelationField, RelationsField } from "pocketbase-zod-schema";
402
400
 
403
401
  const ProjectSchema = z.object({
404
402
  name: z.string(),
@@ -436,9 +434,9 @@ const ProjectSchema = z.object({
436
434
  - `minSelect?: number` - Minimum number of relations required (default: `0`)
437
435
  - `maxSelect?: number` - Maximum number of relations allowed (default: `999`)
438
436
 
439
- > Relations can also be detected from field naming (a `z.string()` starting with an uppercase
440
- > letter, or a `z.array(z.string())` containing one). That fallback exists for backward
441
- > 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.
442
440
 
443
441
  ### Defining View Collections
444
442
 
@@ -448,7 +446,7 @@ only:
448
446
 
449
447
  ```typescript
450
448
  import { z } from "zod";
451
- import { baseSchema, defineView, sql } from "pocketbase-zod-schema/schema";
449
+ import { baseSchema, defineView, sql } from "pocketbase-zod-schema";
452
450
 
453
451
  export const ProductStatsSchema = z
454
452
  .object({
@@ -486,12 +484,12 @@ constraints into compile errors instead of apply-time failures.
486
484
 
487
485
  ### Defining Permissions
488
486
 
489
- Use `defineCollection()` with permissions, or `withPermissions()` to attach API rules to your schema:
487
+ Attach API rules to a collection through `defineCollection({ permissions })`:
490
488
 
491
489
  ```typescript
492
- import { defineCollection, withPermissions } from "pocketbase-zod-schema/schema";
490
+ import { defineCollection } from "pocketbase-zod-schema";
493
491
 
494
- // Using defineCollection (recommended)
492
+ // Explicit rules
495
493
  const PostCollection = defineCollection({
496
494
  collectionName: "posts",
497
495
  schema: z.object({ title: z.string() }),
@@ -504,7 +502,7 @@ const PostCollection = defineCollection({
504
502
  },
505
503
  });
506
504
 
507
- // Using templates with defineCollection
505
+ // Using a template
508
506
  const ProjectCollection = defineCollection({
509
507
  collectionName: "projects",
510
508
  schema: z.object({ title: z.string(), owner: RelationField({ collection: "users" }) }),
@@ -513,18 +511,6 @@ const ProjectCollection = defineCollection({
513
511
  ownerField: "owner",
514
512
  },
515
513
  });
516
-
517
- // Using withPermissions (alternative approach)
518
- const PostSchemaAlt = withPermissions(
519
- z.object({ title: z.string() }),
520
- {
521
- listRule: '@request.auth.id != ""',
522
- viewRule: "",
523
- createRule: '@request.auth.id != ""',
524
- updateRule: "author = @request.auth.id",
525
- deleteRule: "author = @request.auth.id",
526
- }
527
- );
528
514
  ```
529
515
 
530
516
  #### Permission Templates
@@ -541,7 +527,7 @@ const PostSchemaAlt = withPermissions(
541
527
  Two more have no template name; call them and pass the result as `permissions`:
542
528
 
543
529
  ```typescript
544
- import { PermissionTemplates } from "pocketbase-zod-schema/schema";
530
+ import { PermissionTemplates } from "pocketbase-zod-schema";
545
531
 
546
532
  PermissionTemplates.locked(); // every rule null (superusers only)
547
533
  PermissionTemplates.readOnlyAuthenticated(); // authenticated read, writes locked
@@ -553,7 +539,6 @@ expression. `manageRule` applies to auth collections only.
553
539
  #### Template with Custom Overrides
554
540
 
555
541
  ```typescript
556
- // Using defineCollection (recommended)
557
542
  const PostCollection = defineCollection({
558
543
  collectionName: "posts",
559
544
  schema: z.object({ title: z.string(), author: RelationField({ collection: "users" }) }),
@@ -566,26 +551,15 @@ const PostCollection = defineCollection({
566
551
  },
567
552
  },
568
553
  });
569
-
570
- // Using withPermissions (alternative)
571
- const PostSchemaAlt = withPermissions(schema, {
572
- template: "owner-only",
573
- ownerField: "author",
574
- customRules: {
575
- listRule: '@request.auth.id != ""',
576
- viewRule: "",
577
- },
578
- });
579
554
  ```
580
555
 
581
556
  ### Defining Indexes
582
557
 
583
- Use `defineCollection()` with indexes, or `withIndexes()` to define database indexes:
558
+ Declare database indexes through `defineCollection({ indexes })`:
584
559
 
585
560
  ```typescript
586
- import { defineCollection, withIndexes, withPermissions } from "pocketbase-zod-schema/schema";
561
+ import { defineCollection } from "pocketbase-zod-schema";
587
562
 
588
- // Using defineCollection (recommended)
589
563
  const UserCollection = defineCollection({
590
564
  collectionName: "users",
591
565
  schema: z.object({
@@ -600,21 +574,6 @@ const UserCollection = defineCollection({
600
574
  'CREATE INDEX idx_users_username ON users (username)',
601
575
  ],
602
576
  });
603
-
604
- // Using withIndexes (alternative)
605
- const UserSchemaAlt = withIndexes(
606
- withPermissions(
607
- z.object({
608
- email: z.string().email(),
609
- username: z.string(),
610
- }),
611
- { template: "authenticated" }
612
- ),
613
- [
614
- 'CREATE UNIQUE INDEX idx_users_email ON users (email)',
615
- 'CREATE INDEX idx_users_username ON users (username)',
616
- ]
617
- );
618
577
  ```
619
578
 
620
579
  ---
@@ -818,7 +777,7 @@ CLI > environment > config file > defaults.
818
777
 
819
778
  ## Programmatic API
820
779
 
821
- For custom workflows, use the programmatic API:
780
+ For custom workflows, use the programmatic API from `pocketbase-zod-schema/server`:
822
781
 
823
782
  ```typescript
824
783
  import {
@@ -826,14 +785,14 @@ import {
826
785
  compare,
827
786
  generate,
828
787
  loadSnapshotWithMigrations,
829
- } from "pocketbase-zod-schema/migration";
788
+ } from "pocketbase-zod-schema/server";
830
789
 
831
790
  async function generateMigration() {
832
791
  const schemaDir = "./src/schema";
833
792
  const migrationsDir = "./pocketbase/pb_migrations";
834
793
 
835
794
  // Parse all schema files
836
- const currentSchema = await parseSchemaFiles(schemaDir);
795
+ const currentSchema = await parseSchemaFiles({ schemaDir });
837
796
 
838
797
  // Reconstruct the current database state by executing the existing migrations.
839
798
  // Returns null when there is nothing to replay; throws SnapshotError if a
@@ -852,12 +811,8 @@ async function generateMigration() {
852
811
  }
853
812
  ```
854
813
 
855
- > Use `loadSnapshotWithMigrations`, not `loadSnapshotIfExists`. The latter executes **only** the
856
- > newest snapshot file and ignores every migration after it, so it is almost never the current
857
- > state.
858
-
859
814
  The execution engine, round-trip verification and the goja lint are also available directly from
860
- `pocketbase-zod-schema/migration/engine` — see the
815
+ `pocketbase-zod-schema/server` — see the
861
816
  [Execution Engine guide](https://github.com/dastron/pocketbase-zod-schema/blob/main/docs/EXECUTION_ENGINE.md).
862
817
 
863
818
  ---
@@ -869,7 +824,7 @@ Here's a complete example of a blog schema with users, posts, and comments:
869
824
  ```typescript
870
825
  // src/schema/user.ts
871
826
  import { z } from "zod";
872
- import { baseSchema, defineCollection, TextField, EmailField } from "pocketbase-zod-schema/schema";
827
+ import { baseSchema, defineCollection, TextField, EmailField } from "pocketbase-zod-schema";
873
828
 
874
829
  // Input schema for forms (includes passwordConfirm for validation)
875
830
  export const UserInputSchema = z.object({
@@ -894,6 +849,7 @@ export const UserSchema = UserCollectionSchema.extend(baseSchema);
894
849
  // Collection definition with permissions and indexes
895
850
  export const UserCollection = defineCollection({
896
851
  collectionName: "Users",
852
+ type: "auth", // auth collections must opt in explicitly; it is never inferred
897
853
  schema: UserSchema,
898
854
  permissions: {
899
855
  listRule: "id = @request.auth.id",
@@ -919,7 +875,7 @@ import {
919
875
  DateField,
920
876
  RelationField,
921
877
  RelationsField,
922
- } from "pocketbase-zod-schema/schema";
878
+ } from "pocketbase-zod-schema";
923
879
 
924
880
  // Define the Zod schema
925
881
  export const PostSchema = z.object({
@@ -953,7 +909,7 @@ export const PostCollection = defineCollection({
953
909
  ```typescript
954
910
  // src/schema/comment.ts
955
911
  import { z } from "zod";
956
- import { defineCollection, TextField, RelationField } from "pocketbase-zod-schema/schema";
912
+ import { defineCollection, TextField, RelationField } from "pocketbase-zod-schema";
957
913
 
958
914
  // Define the Zod schema
959
915
  export const CommentSchema = z.object({