pocketbase-zod-schema 0.1.3 → 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 +14 -0
- package/README.md +233 -98
- package/dist/cli/index.cjs +449 -108
- package/dist/cli/index.cjs.map +1 -1
- package/dist/cli/index.js +447 -106
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/migrate.cjs +452 -111
- package/dist/cli/migrate.cjs.map +1 -1
- package/dist/cli/migrate.js +447 -106
- package/dist/cli/migrate.js.map +1 -1
- package/dist/index.cjs +593 -175
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +583 -172
- 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/diff.cjs +21 -3
- package/dist/migration/diff.cjs.map +1 -1
- package/dist/migration/diff.js +21 -3
- package/dist/migration/diff.js.map +1 -1
- package/dist/migration/index.cjs +500 -129
- package/dist/migration/index.cjs.map +1 -1
- package/dist/migration/index.d.cts +1 -1
- package/dist/migration/index.d.ts +1 -1
- package/dist/migration/index.js +499 -129
- package/dist/migration/index.js.map +1 -1
- package/dist/migration/snapshot.cjs +432 -118
- package/dist/migration/snapshot.cjs.map +1 -1
- package/dist/migration/snapshot.d.cts +34 -12
- package/dist/migration/snapshot.d.ts +34 -12
- package/dist/migration/snapshot.js +430 -117
- package/dist/migration/snapshot.js.map +1 -1
- package/dist/mutator.cjs +20 -21
- package/dist/mutator.cjs.map +1 -1
- package/dist/mutator.d.cts +4 -4
- package/dist/mutator.d.ts +4 -4
- package/dist/mutator.js +20 -21
- package/dist/mutator.js.map +1 -1
- package/dist/schema.cjs +69 -10
- 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 +62 -9
- package/dist/schema.js.map +1 -1
- package/dist/types.d.cts +5 -2
- package/dist/types.d.ts +5 -2
- package/dist/user-DTJQIj4K.d.cts +149 -0
- package/dist/user-DTJQIj4K.d.ts +149 -0
- package/package.json +3 -3
- package/dist/user-C39DQ40N.d.cts +0 -53
- package/dist/user-C39DQ40N.d.ts +0 -53
|
@@ -980,6 +980,16 @@ function isFieldRequired(zodType) {
|
|
|
980
980
|
}
|
|
981
981
|
|
|
982
982
|
// src/migration/analyzer.ts
|
|
983
|
+
var tsxLoaderRegistered = false;
|
|
984
|
+
async function ensureTsxLoader() {
|
|
985
|
+
if (tsxLoaderRegistered) return;
|
|
986
|
+
try {
|
|
987
|
+
await import('tsx/esm');
|
|
988
|
+
tsxLoaderRegistered = true;
|
|
989
|
+
} catch {
|
|
990
|
+
tsxLoaderRegistered = false;
|
|
991
|
+
}
|
|
992
|
+
}
|
|
983
993
|
var DEFAULT_CONFIG = {
|
|
984
994
|
workspaceRoot: process.cwd(),
|
|
985
995
|
excludePatterns: [
|
|
@@ -1077,24 +1087,37 @@ async function importSchemaModule(filePath, config) {
|
|
|
1077
1087
|
} else {
|
|
1078
1088
|
resolvedPath = jsPath;
|
|
1079
1089
|
}
|
|
1090
|
+
if (resolvedPath.endsWith(".ts")) {
|
|
1091
|
+
await ensureTsxLoader();
|
|
1092
|
+
if (!tsxLoaderRegistered) {
|
|
1093
|
+
throw new SchemaParsingError(
|
|
1094
|
+
`Failed to import TypeScript schema file. The 'tsx' package is required to load TypeScript files.
|
|
1095
|
+
Please install tsx: npm install tsx (or yarn add tsx, or pnpm add tsx)
|
|
1096
|
+
Alternatively, compile your schema files to JavaScript first.`,
|
|
1097
|
+
filePath
|
|
1098
|
+
);
|
|
1099
|
+
}
|
|
1100
|
+
}
|
|
1080
1101
|
const fileUrl = new URL(`file://${path__namespace.resolve(resolvedPath)}`);
|
|
1081
1102
|
const module = await import(fileUrl.href);
|
|
1082
1103
|
return module;
|
|
1083
1104
|
} catch (error) {
|
|
1084
1105
|
const tsPath = `${filePath}.ts`;
|
|
1085
1106
|
const isTypeScriptFile = fs__namespace.existsSync(tsPath);
|
|
1107
|
+
if (isTypeScriptFile && error instanceof SchemaParsingError) {
|
|
1108
|
+
throw error;
|
|
1109
|
+
}
|
|
1086
1110
|
if (isTypeScriptFile) {
|
|
1087
1111
|
throw new SchemaParsingError(
|
|
1088
|
-
`Failed to import TypeScript schema file.
|
|
1089
|
-
Please
|
|
1090
|
-
|
|
1091
|
-
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")`,
|
|
1112
|
+
`Failed to import TypeScript schema file. The 'tsx' package is required to load TypeScript files.
|
|
1113
|
+
Please install tsx: npm install tsx (or yarn add tsx, or pnpm add tsx)
|
|
1114
|
+
Alternatively, compile your schema files to JavaScript first.`,
|
|
1092
1115
|
filePath,
|
|
1093
1116
|
error
|
|
1094
1117
|
);
|
|
1095
1118
|
}
|
|
1096
1119
|
throw new SchemaParsingError(
|
|
1097
|
-
`Failed to import schema module. Make sure the schema files
|
|
1120
|
+
`Failed to import schema module. Make sure the schema files exist and are valid.`,
|
|
1098
1121
|
filePath,
|
|
1099
1122
|
error
|
|
1100
1123
|
);
|
|
@@ -1104,6 +1127,19 @@ function getCollectionNameFromFile(filePath) {
|
|
|
1104
1127
|
const filename = path__namespace.basename(filePath).replace(/\.(ts|js)$/, "");
|
|
1105
1128
|
return toCollectionName(filename);
|
|
1106
1129
|
}
|
|
1130
|
+
function extractCollectionNameFromSchema(zodSchema) {
|
|
1131
|
+
if (!zodSchema.description) {
|
|
1132
|
+
return null;
|
|
1133
|
+
}
|
|
1134
|
+
try {
|
|
1135
|
+
const metadata = JSON.parse(zodSchema.description);
|
|
1136
|
+
if (metadata.collectionName && typeof metadata.collectionName === "string") {
|
|
1137
|
+
return metadata.collectionName;
|
|
1138
|
+
}
|
|
1139
|
+
} catch {
|
|
1140
|
+
}
|
|
1141
|
+
return null;
|
|
1142
|
+
}
|
|
1107
1143
|
function extractSchemaDefinitions(module, patterns = ["Schema", "InputSchema"]) {
|
|
1108
1144
|
const result = {};
|
|
1109
1145
|
for (const [key, value] of Object.entries(module)) {
|
|
@@ -1279,7 +1315,8 @@ async function buildSchemaDefinition(config) {
|
|
|
1279
1315
|
console.warn(`No valid schema found in ${filePath}, skipping...`);
|
|
1280
1316
|
continue;
|
|
1281
1317
|
}
|
|
1282
|
-
const
|
|
1318
|
+
const collectionNameFromSchema = extractCollectionNameFromSchema(zodSchema);
|
|
1319
|
+
const collectionName = collectionNameFromSchema ?? getCollectionNameFromFile(filePath);
|
|
1283
1320
|
const collectionSchema = convertZodSchemaToCollectionSchema(collectionName, zodSchema);
|
|
1284
1321
|
collections.set(collectionName, collectionSchema);
|
|
1285
1322
|
} catch (error) {
|
|
@@ -1328,6 +1365,7 @@ exports.buildFieldDefinition = buildFieldDefinition;
|
|
|
1328
1365
|
exports.buildSchemaDefinition = buildSchemaDefinition;
|
|
1329
1366
|
exports.convertZodSchemaToCollectionSchema = convertZodSchemaToCollectionSchema;
|
|
1330
1367
|
exports.discoverSchemaFiles = discoverSchemaFiles;
|
|
1368
|
+
exports.extractCollectionNameFromSchema = extractCollectionNameFromSchema;
|
|
1331
1369
|
exports.extractFieldDefinitions = extractFieldDefinitions;
|
|
1332
1370
|
exports.extractIndexes = extractIndexes;
|
|
1333
1371
|
exports.extractSchemaDefinitions = extractSchemaDefinitions;
|