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.
Files changed (43) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/README.md +233 -98
  3. package/dist/cli/index.cjs +43 -6
  4. package/dist/cli/index.cjs.map +1 -1
  5. package/dist/cli/index.js +43 -6
  6. package/dist/cli/index.js.map +1 -1
  7. package/dist/cli/migrate.cjs +43 -6
  8. package/dist/cli/migrate.cjs.map +1 -1
  9. package/dist/cli/migrate.js +43 -6
  10. package/dist/cli/migrate.js.map +1 -1
  11. package/dist/index.cjs +84 -22
  12. package/dist/index.cjs.map +1 -1
  13. package/dist/index.d.cts +2 -2
  14. package/dist/index.d.ts +2 -2
  15. package/dist/index.js +79 -21
  16. package/dist/index.js.map +1 -1
  17. package/dist/migration/analyzer.cjs +44 -6
  18. package/dist/migration/analyzer.cjs.map +1 -1
  19. package/dist/migration/analyzer.d.cts +11 -1
  20. package/dist/migration/analyzer.d.ts +11 -1
  21. package/dist/migration/analyzer.js +44 -7
  22. package/dist/migration/analyzer.js.map +1 -1
  23. package/dist/migration/index.cjs +43 -6
  24. package/dist/migration/index.cjs.map +1 -1
  25. package/dist/migration/index.js +43 -6
  26. package/dist/migration/index.js.map +1 -1
  27. package/dist/mutator.cjs +20 -21
  28. package/dist/mutator.cjs.map +1 -1
  29. package/dist/mutator.d.cts +2 -2
  30. package/dist/mutator.d.ts +2 -2
  31. package/dist/mutator.js +20 -21
  32. package/dist/mutator.js.map +1 -1
  33. package/dist/schema.cjs +41 -16
  34. package/dist/schema.cjs.map +1 -1
  35. package/dist/schema.d.cts +98 -8
  36. package/dist/schema.d.ts +98 -8
  37. package/dist/schema.js +36 -15
  38. package/dist/schema.js.map +1 -1
  39. package/dist/types.d.cts +1 -1
  40. package/dist/types.d.ts +1 -1
  41. package/dist/{user-_AM523hb.d.cts → user-DTJQIj4K.d.cts} +31 -5
  42. package/dist/{user-_AM523hb.d.ts → user-DTJQIj4K.d.ts} +31 -5
  43. package/package.json +2 -1
@@ -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. Node.js cannot import TypeScript files directly.
1190
- Please either:
1191
- 1. Compile your schema files to JavaScript first, or
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 are compiled to JavaScript.`,
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 collectionName = getCollectionNameFromFile(filePath);
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) {