pocketbase-zod-schema 0.1.4 → 0.2.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/CHANGELOG.md +7 -0
- package/README.md +233 -98
- package/dist/cli/index.cjs +43 -6
- package/dist/cli/index.cjs.map +1 -1
- package/dist/cli/index.js +43 -6
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/migrate.cjs +43 -6
- package/dist/cli/migrate.cjs.map +1 -1
- package/dist/cli/migrate.js +43 -6
- package/dist/cli/migrate.js.map +1 -1
- package/dist/index.cjs +84 -22
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +79 -21
- package/dist/index.js.map +1 -1
- package/dist/migration/analyzer.cjs +44 -6
- package/dist/migration/analyzer.cjs.map +1 -1
- package/dist/migration/analyzer.d.cts +11 -1
- package/dist/migration/analyzer.d.ts +11 -1
- package/dist/migration/analyzer.js +44 -7
- package/dist/migration/analyzer.js.map +1 -1
- package/dist/migration/index.cjs +43 -6
- package/dist/migration/index.cjs.map +1 -1
- package/dist/migration/index.js +43 -6
- package/dist/migration/index.js.map +1 -1
- package/dist/mutator.cjs +20 -21
- package/dist/mutator.cjs.map +1 -1
- package/dist/mutator.d.cts +2 -2
- package/dist/mutator.d.ts +2 -2
- package/dist/mutator.js +20 -21
- package/dist/mutator.js.map +1 -1
- package/dist/schema.cjs +41 -16
- package/dist/schema.cjs.map +1 -1
- package/dist/schema.d.cts +98 -8
- package/dist/schema.d.ts +98 -8
- package/dist/schema.js +36 -15
- package/dist/schema.js.map +1 -1
- package/dist/types.d.cts +1 -1
- package/dist/types.d.ts +1 -1
- package/dist/{user-_AM523hb.d.cts → user-DTJQIj4K.d.cts} +31 -5
- package/dist/{user-_AM523hb.d.ts → user-DTJQIj4K.d.ts} +31 -5
- package/package.json +2 -1
package/dist/cli/index.js
CHANGED
|
@@ -1049,6 +1049,16 @@ function isFieldRequired(zodType) {
|
|
|
1049
1049
|
}
|
|
1050
1050
|
|
|
1051
1051
|
// src/migration/analyzer.ts
|
|
1052
|
+
var tsxLoaderRegistered = false;
|
|
1053
|
+
async function ensureTsxLoader() {
|
|
1054
|
+
if (tsxLoaderRegistered) return;
|
|
1055
|
+
try {
|
|
1056
|
+
await import('tsx/esm');
|
|
1057
|
+
tsxLoaderRegistered = true;
|
|
1058
|
+
} catch {
|
|
1059
|
+
tsxLoaderRegistered = false;
|
|
1060
|
+
}
|
|
1061
|
+
}
|
|
1052
1062
|
var DEFAULT_CONFIG = {
|
|
1053
1063
|
workspaceRoot: process.cwd(),
|
|
1054
1064
|
excludePatterns: [
|
|
@@ -1146,24 +1156,37 @@ async function importSchemaModule(filePath, config) {
|
|
|
1146
1156
|
} else {
|
|
1147
1157
|
resolvedPath = jsPath;
|
|
1148
1158
|
}
|
|
1159
|
+
if (resolvedPath.endsWith(".ts")) {
|
|
1160
|
+
await ensureTsxLoader();
|
|
1161
|
+
if (!tsxLoaderRegistered) {
|
|
1162
|
+
throw new SchemaParsingError(
|
|
1163
|
+
`Failed to import TypeScript schema file. The 'tsx' package is required to load TypeScript files.
|
|
1164
|
+
Please install tsx: npm install tsx (or yarn add tsx, or pnpm add tsx)
|
|
1165
|
+
Alternatively, compile your schema files to JavaScript first.`,
|
|
1166
|
+
filePath
|
|
1167
|
+
);
|
|
1168
|
+
}
|
|
1169
|
+
}
|
|
1149
1170
|
const fileUrl = new URL(`file://${path5.resolve(resolvedPath)}`);
|
|
1150
1171
|
const module = await import(fileUrl.href);
|
|
1151
1172
|
return module;
|
|
1152
1173
|
} catch (error) {
|
|
1153
1174
|
const tsPath = `${filePath}.ts`;
|
|
1154
1175
|
const isTypeScriptFile = fs5.existsSync(tsPath);
|
|
1176
|
+
if (isTypeScriptFile && error instanceof SchemaParsingError) {
|
|
1177
|
+
throw error;
|
|
1178
|
+
}
|
|
1155
1179
|
if (isTypeScriptFile) {
|
|
1156
1180
|
throw new SchemaParsingError(
|
|
1157
|
-
`Failed to import TypeScript schema file.
|
|
1158
|
-
Please
|
|
1159
|
-
|
|
1160
|
-
2. Use tsx to run the migration tool (e.g., "npx tsx package/dist/cli/migrate.js status" or "tsx package/dist/cli/migrate.js status")`,
|
|
1181
|
+
`Failed to import TypeScript schema file. The 'tsx' package is required to load TypeScript files.
|
|
1182
|
+
Please install tsx: npm install tsx (or yarn add tsx, or pnpm add tsx)
|
|
1183
|
+
Alternatively, compile your schema files to JavaScript first.`,
|
|
1161
1184
|
filePath,
|
|
1162
1185
|
error
|
|
1163
1186
|
);
|
|
1164
1187
|
}
|
|
1165
1188
|
throw new SchemaParsingError(
|
|
1166
|
-
`Failed to import schema module. Make sure the schema files
|
|
1189
|
+
`Failed to import schema module. Make sure the schema files exist and are valid.`,
|
|
1167
1190
|
filePath,
|
|
1168
1191
|
error
|
|
1169
1192
|
);
|
|
@@ -1173,6 +1196,19 @@ function getCollectionNameFromFile(filePath) {
|
|
|
1173
1196
|
const filename = path5.basename(filePath).replace(/\.(ts|js)$/, "");
|
|
1174
1197
|
return toCollectionName(filename);
|
|
1175
1198
|
}
|
|
1199
|
+
function extractCollectionNameFromSchema(zodSchema) {
|
|
1200
|
+
if (!zodSchema.description) {
|
|
1201
|
+
return null;
|
|
1202
|
+
}
|
|
1203
|
+
try {
|
|
1204
|
+
const metadata = JSON.parse(zodSchema.description);
|
|
1205
|
+
if (metadata.collectionName && typeof metadata.collectionName === "string") {
|
|
1206
|
+
return metadata.collectionName;
|
|
1207
|
+
}
|
|
1208
|
+
} catch {
|
|
1209
|
+
}
|
|
1210
|
+
return null;
|
|
1211
|
+
}
|
|
1176
1212
|
function extractSchemaDefinitions(module, patterns = ["Schema", "InputSchema"]) {
|
|
1177
1213
|
const result = {};
|
|
1178
1214
|
for (const [key, value] of Object.entries(module)) {
|
|
@@ -1348,7 +1384,8 @@ async function buildSchemaDefinition(config) {
|
|
|
1348
1384
|
console.warn(`No valid schema found in ${filePath}, skipping...`);
|
|
1349
1385
|
continue;
|
|
1350
1386
|
}
|
|
1351
|
-
const
|
|
1387
|
+
const collectionNameFromSchema = extractCollectionNameFromSchema(zodSchema);
|
|
1388
|
+
const collectionName = collectionNameFromSchema ?? getCollectionNameFromFile(filePath);
|
|
1352
1389
|
const collectionSchema = convertZodSchemaToCollectionSchema(collectionName, zodSchema);
|
|
1353
1390
|
collections.set(collectionName, collectionSchema);
|
|
1354
1391
|
} catch (error) {
|