pocketbase-to-zod 1.0.1 → 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 +6 -4
- package/index.ts +7 -4
- package/package.json +1 -1
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
|
-
|
|
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
|
|
62
|
+
zodType = field.options?.maxSelect === 1 ? 'z.string()' : 'z.array(z.string())';
|
|
61
63
|
break;
|
|
62
64
|
case 'file':
|
|
63
|
-
zodType = field.options
|
|
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,8 +25,11 @@ 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.type === 'base' || col.type === 'auth') && !col.system);
|
|
28
29
|
|
|
29
|
-
|
|
30
|
+
console.log(`--- Generating schemas for ${filteredCollections.length} collections ---`);
|
|
31
|
+
|
|
32
|
+
for (const col of filteredCollections) {
|
|
30
33
|
console.log(`--- Generating schema for collection: ${col.name} ---`);
|
|
31
34
|
fileContent += `// Schema for collection: ${col.name}\n`;
|
|
32
35
|
fileContent += `export const ${col.name}Schema = z.object({\n`;
|
|
@@ -56,16 +59,16 @@ program
|
|
|
56
59
|
zodType = 'z.string().datetime()'; // PocketBase sends dates as ISO strings
|
|
57
60
|
break;
|
|
58
61
|
case 'select':
|
|
59
|
-
if (field.options.values) {
|
|
62
|
+
if (field.options?.values && Array.isArray(field.options.values) && field.options.values.length > 0) {
|
|
60
63
|
const values = field.options.values.map((v: string) => `'${v}'`).join(', ');
|
|
61
64
|
zodType = `z.enum([${values}])`;
|
|
62
65
|
}
|
|
63
66
|
break;
|
|
64
67
|
case 'relation':
|
|
65
|
-
zodType = field.options
|
|
68
|
+
zodType = field.options?.maxSelect === 1 ? 'z.string()' : 'z.array(z.string())';
|
|
66
69
|
break;
|
|
67
70
|
case 'file':
|
|
68
|
-
zodType = field.options
|
|
71
|
+
zodType = field.options?.maxSelect === 1 ? 'z.string()' : 'z.array(z.string())';
|
|
69
72
|
break;
|
|
70
73
|
case 'json':
|
|
71
74
|
zodType = 'z.unknown()';
|