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.
- package/CHANGELOG.md +16 -0
- package/README.md +28 -69
- package/dist/cli/migrate.cjs +548 -674
- package/dist/cli/migrate.cjs.map +1 -1
- package/dist/cli/migrate.js +545 -671
- package/dist/cli/migrate.js.map +1 -1
- package/dist/index.cjs +37 -555
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +903 -6
- package/dist/index.d.ts +903 -6
- package/dist/index.js +38 -540
- package/dist/index.js.map +1 -1
- package/dist/server.cjs +674 -2614
- package/dist/server.cjs.map +1 -1
- package/dist/server.d.cts +1344 -18
- package/dist/server.d.ts +1344 -18
- package/dist/server.js +673 -2481
- package/dist/server.js.map +1 -1
- package/package.json +2 -64
- package/dist/cli/index.cjs +0 -7873
- package/dist/cli/index.cjs.map +0 -1
- package/dist/cli/index.d.cts +0 -32
- package/dist/cli/index.d.ts +0 -32
- package/dist/cli/index.js +0 -7819
- package/dist/cli/index.js.map +0 -1
- package/dist/cli/utils/index.cjs +0 -596
- package/dist/cli/utils/index.cjs.map +0 -1
- package/dist/cli/utils/index.d.cts +0 -282
- package/dist/cli/utils/index.d.ts +0 -282
- package/dist/cli/utils/index.js +0 -542
- package/dist/cli/utils/index.js.map +0 -1
- package/dist/enums.cjs +0 -19
- package/dist/enums.cjs.map +0 -1
- package/dist/enums.d.cts +0 -11
- package/dist/enums.d.ts +0 -11
- package/dist/enums.js +0 -17
- package/dist/enums.js.map +0 -1
- package/dist/fields-B96iGprI.d.cts +0 -480
- package/dist/fields-B96iGprI.d.ts +0 -480
- package/dist/migration/analyzer.cjs +0 -1725
- package/dist/migration/analyzer.cjs.map +0 -1
- package/dist/migration/analyzer.d.cts +0 -245
- package/dist/migration/analyzer.d.ts +0 -245
- package/dist/migration/analyzer.js +0 -1684
- package/dist/migration/analyzer.js.map +0 -1
- package/dist/migration/diff.cjs +0 -943
- package/dist/migration/diff.cjs.map +0 -1
- package/dist/migration/diff.d.cts +0 -370
- package/dist/migration/diff.d.ts +0 -370
- package/dist/migration/diff.js +0 -911
- package/dist/migration/diff.js.map +0 -1
- package/dist/migration/engine.cjs +0 -3263
- package/dist/migration/engine.cjs.map +0 -1
- package/dist/migration/engine.d.cts +0 -105
- package/dist/migration/engine.d.ts +0 -105
- package/dist/migration/engine.js +0 -3173
- package/dist/migration/engine.js.map +0 -1
- package/dist/migration/generator.cjs +0 -1596
- package/dist/migration/generator.cjs.map +0 -1
- package/dist/migration/generator.d.cts +0 -493
- package/dist/migration/generator.d.ts +0 -493
- package/dist/migration/generator.js +0 -1529
- package/dist/migration/generator.js.map +0 -1
- package/dist/migration/index.cjs +0 -8190
- package/dist/migration/index.cjs.map +0 -1
- package/dist/migration/index.d.cts +0 -193
- package/dist/migration/index.d.ts +0 -193
- package/dist/migration/index.js +0 -8015
- package/dist/migration/index.js.map +0 -1
- package/dist/migration/snapshot.cjs +0 -2814
- package/dist/migration/snapshot.cjs.map +0 -1
- package/dist/migration/snapshot.d.cts +0 -186
- package/dist/migration/snapshot.d.ts +0 -186
- package/dist/migration/snapshot.js +0 -2779
- package/dist/migration/snapshot.js.map +0 -1
- package/dist/migration/utils/index.cjs +0 -891
- package/dist/migration/utils/index.cjs.map +0 -1
- package/dist/migration/utils/index.d.cts +0 -66
- package/dist/migration/utils/index.d.ts +0 -66
- package/dist/migration/utils/index.js +0 -854
- package/dist/migration/utils/index.js.map +0 -1
- package/dist/mutator.cjs +0 -355
- package/dist/mutator.cjs.map +0 -1
- package/dist/mutator.d.cts +0 -164
- package/dist/mutator.d.ts +0 -164
- package/dist/mutator.js +0 -353
- package/dist/mutator.js.map +0 -1
- package/dist/schema.cjs +0 -715
- package/dist/schema.cjs.map +0 -1
- package/dist/schema.d.cts +0 -563
- package/dist/schema.d.ts +0 -563
- package/dist/schema.js +0 -674
- package/dist/schema.js.map +0 -1
- package/dist/type-mapper-BSPTj8t5.d.cts +0 -216
- package/dist/type-mapper-D31WYDee.d.ts +0 -216
- package/dist/types-B_MLb1Ob.d.ts +0 -475
- package/dist/types-CnzfX6JH.d.cts +0 -148
- package/dist/types-Do3jyFBm.d.ts +0 -148
- package/dist/types-upZBVMfb.d.cts +0 -475
- package/dist/verify-BF72n2df.d.ts +0 -402
- 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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
437
|
-
>
|
|
438
|
-
>
|
|
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
|
|
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
|
-
|
|
487
|
+
Attach API rules to a collection through `defineCollection({ permissions })`:
|
|
487
488
|
|
|
488
489
|
```typescript
|
|
489
|
-
import { defineCollection
|
|
490
|
+
import { defineCollection } from "pocketbase-zod-schema";
|
|
490
491
|
|
|
491
|
-
//
|
|
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
|
|
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
|
|
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
|
-
|
|
558
|
+
Declare database indexes through `defineCollection({ indexes })`:
|
|
581
559
|
|
|
582
560
|
```typescript
|
|
583
|
-
import { defineCollection
|
|
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/
|
|
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/
|
|
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
|
|
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
|
|
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
|
|
912
|
+
import { defineCollection, TextField, RelationField } from "pocketbase-zod-schema";
|
|
954
913
|
|
|
955
914
|
// Define the Zod schema
|
|
956
915
|
export const CommentSchema = z.object({
|