pocketbase-to-zod 1.0.2 → 1.0.3

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/dist/index.js CHANGED
@@ -24,7 +24,9 @@ program
24
24
  console.log('--- Fetching collections ---');
25
25
  const collections = await pb.collections.getFullList();
26
26
  let fileContent = `import { z } from 'zod';\n\n`;
27
- for (const col of collections) {
27
+ const filteredCollections = collections.filter((col) => (col.type === 'base' || col.type === 'auth') && !col.system);
28
+ console.log(`--- Generating schemas for ${filteredCollections.length} collections ---`);
29
+ for (const col of filteredCollections) {
28
30
  console.log(`--- Generating schema for collection: ${col.name} ---`);
29
31
  fileContent += `// Schema for collection: ${col.name}\n`;
30
32
  fileContent += `export const ${col.name}Schema = z.object({\n`;
@@ -51,16 +53,16 @@ program
51
53
  zodType = 'z.string().datetime()'; // PocketBase sends dates as ISO strings
52
54
  break;
53
55
  case 'select':
54
- if (field.options.values) {
56
+ if (field.options?.values && Array.isArray(field.options.values) && field.options.values.length > 0) {
55
57
  const values = field.options.values.map((v) => `'${v}'`).join(', ');
56
58
  zodType = `z.enum([${values}])`;
57
59
  }
58
60
  break;
59
61
  case 'relation':
60
- zodType = field.options.maxSelect === 1 ? 'z.string()' : 'z.array(z.string())';
62
+ zodType = field.options?.maxSelect === 1 ? 'z.string()' : 'z.array(z.string())';
61
63
  break;
62
64
  case 'file':
63
- zodType = field.options.maxSelect === 1 ? 'z.string()' : 'z.array(z.string())';
65
+ zodType = field.options?.maxSelect === 1 ? 'z.string()' : 'z.array(z.string())';
64
66
  break;
65
67
  case 'json':
66
68
  zodType = 'z.unknown()';
package/index.ts CHANGED
@@ -25,7 +25,9 @@ program
25
25
  const collections = await pb.collections.getFullList();
26
26
 
27
27
  let fileContent = `import { z } from 'zod';\n\n`;
28
- const filteredCollections = collections.filter(col => !col.system);
28
+ const filteredCollections = collections.filter((col) => (col.type === 'base' || col.type === 'auth') && !col.system);
29
+
30
+ console.log(`--- Generating schemas for ${filteredCollections.length} collections ---`);
29
31
 
30
32
  for (const col of filteredCollections) {
31
33
  console.log(`--- Generating schema for collection: ${col.name} ---`);
@@ -57,16 +59,16 @@ program
57
59
  zodType = 'z.string().datetime()'; // PocketBase sends dates as ISO strings
58
60
  break;
59
61
  case 'select':
60
- if (field.options.values) {
62
+ if (field.options?.values && Array.isArray(field.options.values) && field.options.values.length > 0) {
61
63
  const values = field.options.values.map((v: string) => `'${v}'`).join(', ');
62
64
  zodType = `z.enum([${values}])`;
63
65
  }
64
66
  break;
65
67
  case 'relation':
66
- zodType = field.options.maxSelect === 1 ? 'z.string()' : 'z.array(z.string())';
68
+ zodType = field.options?.maxSelect === 1 ? 'z.string()' : 'z.array(z.string())';
67
69
  break;
68
70
  case 'file':
69
- zodType = field.options.maxSelect === 1 ? 'z.string()' : 'z.array(z.string())';
71
+ zodType = field.options?.maxSelect === 1 ? 'z.string()' : 'z.array(z.string())';
70
72
  break;
71
73
  case 'json':
72
74
  zodType = 'z.unknown()';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pocketbase-to-zod",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "This project is an utility to generate Zod schemas from Pocketbase instance ",
5
5
  "main": "index.js",
6
6
  "bin": {