pocketbase-to-zod 1.0.5 → 1.1.0
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/README.md +2 -1
- package/dist/index.js +16 -3
- package/index.ts +17 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -20,7 +20,7 @@ npx pocketbase-to-zod [options]
|
|
|
20
20
|
## Usage
|
|
21
21
|
|
|
22
22
|
```bash
|
|
23
|
-
pocketbase-to-zod --url http://localhost:8090 --email admin@example.com --password yourpassword --output ./schemas.ts
|
|
23
|
+
pocketbase-to-zod --url http://localhost:8090 --email admin@example.com --password yourpassword --output ./schemas.ts --split
|
|
24
24
|
```
|
|
25
25
|
|
|
26
26
|
## Options
|
|
@@ -28,6 +28,7 @@ pocketbase-to-zod --url http://localhost:8090 --email admin@example.com --passwo
|
|
|
28
28
|
- `--email <email>`: Admin email for authentication [Required]
|
|
29
29
|
- `--password <password>`: Admin password for authentication [Required]
|
|
30
30
|
- `--output <file>`: Output file path for generated schemas (default: `./pocketbase-schemas.ts`) [Optional]
|
|
31
|
+
- `--split`: Generate a separate file for each collection [Optional]
|
|
31
32
|
|
|
32
33
|
## Example Output
|
|
33
34
|
|
package/dist/index.js
CHANGED
|
@@ -16,6 +16,7 @@ program
|
|
|
16
16
|
.requiredOption('-e, --email <char>', 'Admin email')
|
|
17
17
|
.requiredOption('-p, --password <char>', 'Admin password')
|
|
18
18
|
.option('-o, --output <char>', 'Output file path', './pocketbase-schema.ts')
|
|
19
|
+
.option('-s, --split', 'Generate a file per collection', false)
|
|
19
20
|
.action(async (options) => {
|
|
20
21
|
const pb = new pocketbase_1.default(options.url);
|
|
21
22
|
try {
|
|
@@ -83,10 +84,22 @@ program
|
|
|
83
84
|
}
|
|
84
85
|
fileContent += `});\n\n`;
|
|
85
86
|
fileContent += `export type ${col.name.charAt(0).toUpperCase() + col.name.slice(1)} = z.infer<typeof ${col.name}Schema>;\n\n`;
|
|
87
|
+
if (options.split) {
|
|
88
|
+
const outputDir = path_1.default.resolve(process.cwd(), path_1.default.dirname(options.output));
|
|
89
|
+
if (!fs_1.default.existsSync(outputDir)) {
|
|
90
|
+
fs_1.default.mkdirSync(outputDir, { recursive: true });
|
|
91
|
+
}
|
|
92
|
+
const outputPath = path_1.default.resolve(outputDir, `${col.name}-schema.ts`);
|
|
93
|
+
fs_1.default.writeFileSync(outputPath, fileContent);
|
|
94
|
+
console.log(`✅ Schema for collection '${col.name}' generated at: ${outputPath}`);
|
|
95
|
+
fileContent = `import { z } from 'zod';\n\n`; // Reset for next file
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
if (!options.split) {
|
|
99
|
+
const outputPath = path_1.default.resolve(process.cwd(), options.output);
|
|
100
|
+
fs_1.default.writeFileSync(outputPath, fileContent);
|
|
101
|
+
console.log(`✅ Schemas generated successfully at: ${outputPath}`);
|
|
86
102
|
}
|
|
87
|
-
const outputPath = path_1.default.resolve(process.cwd(), options.output);
|
|
88
|
-
fs_1.default.writeFileSync(outputPath, fileContent);
|
|
89
|
-
console.log(`✅ Schemas generated successfully at: ${outputPath}`);
|
|
90
103
|
}
|
|
91
104
|
catch (error) {
|
|
92
105
|
console.error('❌ Error:', error.message);
|
package/index.ts
CHANGED
|
@@ -14,6 +14,7 @@ program
|
|
|
14
14
|
.requiredOption('-e, --email <char>', 'Admin email')
|
|
15
15
|
.requiredOption('-p, --password <char>', 'Admin password')
|
|
16
16
|
.option('-o, --output <char>', 'Output file path', './pocketbase-schema.ts')
|
|
17
|
+
.option('-s, --split', 'Generate a file per collection', false)
|
|
17
18
|
.action(async (options) => {
|
|
18
19
|
const pb = new PocketBase(options.url);
|
|
19
20
|
|
|
@@ -94,11 +95,24 @@ program
|
|
|
94
95
|
|
|
95
96
|
fileContent += `});\n\n`;
|
|
96
97
|
fileContent += `export type ${col.name.charAt(0).toUpperCase() + col.name.slice(1)} = z.infer<typeof ${col.name}Schema>;\n\n`;
|
|
98
|
+
|
|
99
|
+
if (options.split) {
|
|
100
|
+
const outputDir = path.resolve(process.cwd(), path.dirname(options.output));
|
|
101
|
+
if (!fs.existsSync(outputDir)) {
|
|
102
|
+
fs.mkdirSync(outputDir, { recursive: true });
|
|
103
|
+
}
|
|
104
|
+
const outputPath = path.resolve(outputDir, `${col.name}-schema.ts`);
|
|
105
|
+
fs.writeFileSync(outputPath, fileContent);
|
|
106
|
+
console.log(`✅ Schema for collection '${col.name}' generated at: ${outputPath}`);
|
|
107
|
+
fileContent = `import { z } from 'zod';\n\n`; // Reset for next file
|
|
108
|
+
}
|
|
97
109
|
}
|
|
98
110
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
111
|
+
if (!options.split) {
|
|
112
|
+
const outputPath = path.resolve(process.cwd(), options.output);
|
|
113
|
+
fs.writeFileSync(outputPath, fileContent);
|
|
114
|
+
console.log(`✅ Schemas generated successfully at: ${outputPath}`);
|
|
115
|
+
}
|
|
102
116
|
|
|
103
117
|
} catch (error: any) {
|
|
104
118
|
console.error('❌ Error:', error.message);
|