pocketbase-to-zod 1.0.3 → 1.0.5

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 (3) hide show
  1. package/dist/index.js +13 -5
  2. package/index.ts +16 -6
  3. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -32,17 +32,25 @@ program
32
32
  fileContent += `export const ${col.name}Schema = z.object({\n`;
33
33
  // Base PocketBase fields
34
34
  fileContent += ` id: z.string(),\n`;
35
- fileContent += ` created: z.string(),\n`;
36
- fileContent += ` updated: z.string(),\n`;
35
+ fileContent += ` created: z.date(),\n`;
36
+ fileContent += ` updated: z.date(),\n`;
37
37
  for (const field of col.fields) {
38
38
  let zodType = 'z.any()';
39
+ if (field.hidden)
40
+ continue;
41
+ if (['id', 'created', 'updated'].includes(field.name)) {
42
+ continue; // Skip specific fields if needed
43
+ }
44
+ console.log(` - Processing field: ${field.name} (type: ${field.type})`);
39
45
  switch (field.type) {
40
46
  case 'text':
41
47
  case 'editor':
42
48
  case 'url':
43
- case 'email':
44
49
  zodType = 'z.string()';
45
50
  break;
51
+ case 'email':
52
+ zodType = 'z.email()';
53
+ break;
46
54
  case 'number':
47
55
  zodType = 'z.number()';
48
56
  break;
@@ -50,7 +58,7 @@ program
50
58
  zodType = 'z.boolean()';
51
59
  break;
52
60
  case 'date':
53
- zodType = 'z.string().datetime()'; // PocketBase sends dates as ISO strings
61
+ zodType = 'z.date()'; // PocketBase sends dates as ISO strings
54
62
  break;
55
63
  case 'select':
56
64
  if (field.options?.values && Array.isArray(field.options.values) && field.options.values.length > 0) {
@@ -62,7 +70,7 @@ program
62
70
  zodType = field.options?.maxSelect === 1 ? 'z.string()' : 'z.array(z.string())';
63
71
  break;
64
72
  case 'file':
65
- zodType = field.options?.maxSelect === 1 ? 'z.string()' : 'z.array(z.string())';
73
+ zodType = field.options?.maxSelect === 1 ? 'z.url()' : 'z.array(z.url())';
66
74
  break;
67
75
  case 'json':
68
76
  zodType = 'z.unknown()';
package/index.ts CHANGED
@@ -36,19 +36,29 @@ program
36
36
 
37
37
  // Base PocketBase fields
38
38
  fileContent += ` id: z.string(),\n`;
39
- fileContent += ` created: z.string(),\n`;
40
- fileContent += ` updated: z.string(),\n`;
39
+ fileContent += ` created: z.date(),\n`;
40
+ fileContent += ` updated: z.date(),\n`;
41
41
 
42
42
  for (const field of col.fields) {
43
43
  let zodType = 'z.any()';
44
44
 
45
+ if (field.hidden) continue;
46
+
47
+ if (['id', 'created', 'updated'].includes(field.name)) {
48
+ continue; // Skip specific fields if needed
49
+ }
50
+
51
+ console.log(` - Processing field: ${field.name} (type: ${field.type})`);
52
+
45
53
  switch (field.type) {
46
54
  case 'text':
47
55
  case 'editor':
48
56
  case 'url':
57
+ zodType = 'z.string()';
58
+ break;
49
59
  case 'email':
50
- zodType = 'z.string()';
51
- break;
60
+ zodType = 'z.email()';
61
+ break;
52
62
  case 'number':
53
63
  zodType = 'z.number()';
54
64
  break;
@@ -56,7 +66,7 @@ program
56
66
  zodType = 'z.boolean()';
57
67
  break;
58
68
  case 'date':
59
- zodType = 'z.string().datetime()'; // PocketBase sends dates as ISO strings
69
+ zodType = 'z.date()'; // PocketBase sends dates as ISO strings
60
70
  break;
61
71
  case 'select':
62
72
  if (field.options?.values && Array.isArray(field.options.values) && field.options.values.length > 0) {
@@ -68,7 +78,7 @@ program
68
78
  zodType = field.options?.maxSelect === 1 ? 'z.string()' : 'z.array(z.string())';
69
79
  break;
70
80
  case 'file':
71
- zodType = field.options?.maxSelect === 1 ? 'z.string()' : 'z.array(z.string())';
81
+ zodType = field.options?.maxSelect === 1 ? 'z.url()' : 'z.array(z.url())';
72
82
  break;
73
83
  case 'json':
74
84
  zodType = 'z.unknown()';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pocketbase-to-zod",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
4
4
  "description": "This project is an utility to generate Zod schemas from Pocketbase instance ",
5
5
  "main": "index.js",
6
6
  "bin": {