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/migrate.cjs
CHANGED
|
@@ -1081,6 +1081,16 @@ function isFieldRequired(zodType) {
|
|
|
1081
1081
|
}
|
|
1082
1082
|
|
|
1083
1083
|
// src/migration/analyzer.ts
|
|
1084
|
+
var tsxLoaderRegistered = false;
|
|
1085
|
+
async function ensureTsxLoader() {
|
|
1086
|
+
if (tsxLoaderRegistered) return;
|
|
1087
|
+
try {
|
|
1088
|
+
await import('tsx/esm');
|
|
1089
|
+
tsxLoaderRegistered = true;
|
|
1090
|
+
} catch {
|
|
1091
|
+
tsxLoaderRegistered = false;
|
|
1092
|
+
}
|
|
1093
|
+
}
|
|
1084
1094
|
var DEFAULT_CONFIG = {
|
|
1085
1095
|
workspaceRoot: process.cwd(),
|
|
1086
1096
|
excludePatterns: [
|
|
@@ -1178,24 +1188,37 @@ async function importSchemaModule(filePath, config) {
|
|
|
1178
1188
|
} else {
|
|
1179
1189
|
resolvedPath = jsPath;
|
|
1180
1190
|
}
|
|
1191
|
+
if (resolvedPath.endsWith(".ts")) {
|
|
1192
|
+
await ensureTsxLoader();
|
|
1193
|
+
if (!tsxLoaderRegistered) {
|
|
1194
|
+
throw new SchemaParsingError(
|
|
1195
|
+
`Failed to import TypeScript schema file. The 'tsx' package is required to load TypeScript files.
|
|
1196
|
+
Please install tsx: npm install tsx (or yarn add tsx, or pnpm add tsx)
|
|
1197
|
+
Alternatively, compile your schema files to JavaScript first.`,
|
|
1198
|
+
filePath
|
|
1199
|
+
);
|
|
1200
|
+
}
|
|
1201
|
+
}
|
|
1181
1202
|
const fileUrl = new URL(`file://${path5__namespace.resolve(resolvedPath)}`);
|
|
1182
1203
|
const module = await import(fileUrl.href);
|
|
1183
1204
|
return module;
|
|
1184
1205
|
} catch (error) {
|
|
1185
1206
|
const tsPath = `${filePath}.ts`;
|
|
1186
1207
|
const isTypeScriptFile = fs5__namespace.existsSync(tsPath);
|
|
1208
|
+
if (isTypeScriptFile && error instanceof SchemaParsingError) {
|
|
1209
|
+
throw error;
|
|
1210
|
+
}
|
|
1187
1211
|
if (isTypeScriptFile) {
|
|
1188
1212
|
throw new SchemaParsingError(
|
|
1189
|
-
`Failed to import TypeScript schema file.
|
|
1190
|
-
Please
|
|
1191
|
-
|
|
1192
|
-
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")`,
|
|
1213
|
+
`Failed to import TypeScript schema file. The 'tsx' package is required to load TypeScript files.
|
|
1214
|
+
Please install tsx: npm install tsx (or yarn add tsx, or pnpm add tsx)
|
|
1215
|
+
Alternatively, compile your schema files to JavaScript first.`,
|
|
1193
1216
|
filePath,
|
|
1194
1217
|
error
|
|
1195
1218
|
);
|
|
1196
1219
|
}
|
|
1197
1220
|
throw new SchemaParsingError(
|
|
1198
|
-
`Failed to import schema module. Make sure the schema files
|
|
1221
|
+
`Failed to import schema module. Make sure the schema files exist and are valid.`,
|
|
1199
1222
|
filePath,
|
|
1200
1223
|
error
|
|
1201
1224
|
);
|
|
@@ -1205,6 +1228,19 @@ function getCollectionNameFromFile(filePath) {
|
|
|
1205
1228
|
const filename = path5__namespace.basename(filePath).replace(/\.(ts|js)$/, "");
|
|
1206
1229
|
return toCollectionName(filename);
|
|
1207
1230
|
}
|
|
1231
|
+
function extractCollectionNameFromSchema(zodSchema) {
|
|
1232
|
+
if (!zodSchema.description) {
|
|
1233
|
+
return null;
|
|
1234
|
+
}
|
|
1235
|
+
try {
|
|
1236
|
+
const metadata = JSON.parse(zodSchema.description);
|
|
1237
|
+
if (metadata.collectionName && typeof metadata.collectionName === "string") {
|
|
1238
|
+
return metadata.collectionName;
|
|
1239
|
+
}
|
|
1240
|
+
} catch {
|
|
1241
|
+
}
|
|
1242
|
+
return null;
|
|
1243
|
+
}
|
|
1208
1244
|
function extractSchemaDefinitions(module, patterns = ["Schema", "InputSchema"]) {
|
|
1209
1245
|
const result = {};
|
|
1210
1246
|
for (const [key, value] of Object.entries(module)) {
|
|
@@ -1380,7 +1416,8 @@ async function buildSchemaDefinition(config) {
|
|
|
1380
1416
|
console.warn(`No valid schema found in ${filePath}, skipping...`);
|
|
1381
1417
|
continue;
|
|
1382
1418
|
}
|
|
1383
|
-
const
|
|
1419
|
+
const collectionNameFromSchema = extractCollectionNameFromSchema(zodSchema);
|
|
1420
|
+
const collectionName = collectionNameFromSchema ?? getCollectionNameFromFile(filePath);
|
|
1384
1421
|
const collectionSchema = convertZodSchemaToCollectionSchema(collectionName, zodSchema);
|
|
1385
1422
|
collections.set(collectionName, collectionSchema);
|
|
1386
1423
|
} catch (error) {
|