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.js
CHANGED
|
@@ -1053,6 +1053,16 @@ function isFieldRequired(zodType) {
|
|
|
1053
1053
|
}
|
|
1054
1054
|
|
|
1055
1055
|
// src/migration/analyzer.ts
|
|
1056
|
+
var tsxLoaderRegistered = false;
|
|
1057
|
+
async function ensureTsxLoader() {
|
|
1058
|
+
if (tsxLoaderRegistered) return;
|
|
1059
|
+
try {
|
|
1060
|
+
await import('tsx/esm');
|
|
1061
|
+
tsxLoaderRegistered = true;
|
|
1062
|
+
} catch {
|
|
1063
|
+
tsxLoaderRegistered = false;
|
|
1064
|
+
}
|
|
1065
|
+
}
|
|
1056
1066
|
var DEFAULT_CONFIG = {
|
|
1057
1067
|
workspaceRoot: process.cwd(),
|
|
1058
1068
|
excludePatterns: [
|
|
@@ -1150,24 +1160,37 @@ async function importSchemaModule(filePath, config) {
|
|
|
1150
1160
|
} else {
|
|
1151
1161
|
resolvedPath = jsPath;
|
|
1152
1162
|
}
|
|
1163
|
+
if (resolvedPath.endsWith(".ts")) {
|
|
1164
|
+
await ensureTsxLoader();
|
|
1165
|
+
if (!tsxLoaderRegistered) {
|
|
1166
|
+
throw new SchemaParsingError(
|
|
1167
|
+
`Failed to import TypeScript schema file. The 'tsx' package is required to load TypeScript files.
|
|
1168
|
+
Please install tsx: npm install tsx (or yarn add tsx, or pnpm add tsx)
|
|
1169
|
+
Alternatively, compile your schema files to JavaScript first.`,
|
|
1170
|
+
filePath
|
|
1171
|
+
);
|
|
1172
|
+
}
|
|
1173
|
+
}
|
|
1153
1174
|
const fileUrl = new URL(`file://${path5.resolve(resolvedPath)}`);
|
|
1154
1175
|
const module = await import(fileUrl.href);
|
|
1155
1176
|
return module;
|
|
1156
1177
|
} catch (error) {
|
|
1157
1178
|
const tsPath = `${filePath}.ts`;
|
|
1158
1179
|
const isTypeScriptFile = fs5.existsSync(tsPath);
|
|
1180
|
+
if (isTypeScriptFile && error instanceof SchemaParsingError) {
|
|
1181
|
+
throw error;
|
|
1182
|
+
}
|
|
1159
1183
|
if (isTypeScriptFile) {
|
|
1160
1184
|
throw new SchemaParsingError(
|
|
1161
|
-
`Failed to import TypeScript schema file.
|
|
1162
|
-
Please
|
|
1163
|
-
|
|
1164
|
-
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")`,
|
|
1185
|
+
`Failed to import TypeScript schema file. The 'tsx' package is required to load TypeScript files.
|
|
1186
|
+
Please install tsx: npm install tsx (or yarn add tsx, or pnpm add tsx)
|
|
1187
|
+
Alternatively, compile your schema files to JavaScript first.`,
|
|
1165
1188
|
filePath,
|
|
1166
1189
|
error
|
|
1167
1190
|
);
|
|
1168
1191
|
}
|
|
1169
1192
|
throw new SchemaParsingError(
|
|
1170
|
-
`Failed to import schema module. Make sure the schema files
|
|
1193
|
+
`Failed to import schema module. Make sure the schema files exist and are valid.`,
|
|
1171
1194
|
filePath,
|
|
1172
1195
|
error
|
|
1173
1196
|
);
|
|
@@ -1177,6 +1200,19 @@ function getCollectionNameFromFile(filePath) {
|
|
|
1177
1200
|
const filename = path5.basename(filePath).replace(/\.(ts|js)$/, "");
|
|
1178
1201
|
return toCollectionName(filename);
|
|
1179
1202
|
}
|
|
1203
|
+
function extractCollectionNameFromSchema(zodSchema) {
|
|
1204
|
+
if (!zodSchema.description) {
|
|
1205
|
+
return null;
|
|
1206
|
+
}
|
|
1207
|
+
try {
|
|
1208
|
+
const metadata = JSON.parse(zodSchema.description);
|
|
1209
|
+
if (metadata.collectionName && typeof metadata.collectionName === "string") {
|
|
1210
|
+
return metadata.collectionName;
|
|
1211
|
+
}
|
|
1212
|
+
} catch {
|
|
1213
|
+
}
|
|
1214
|
+
return null;
|
|
1215
|
+
}
|
|
1180
1216
|
function extractSchemaDefinitions(module, patterns = ["Schema", "InputSchema"]) {
|
|
1181
1217
|
const result = {};
|
|
1182
1218
|
for (const [key, value] of Object.entries(module)) {
|
|
@@ -1352,7 +1388,8 @@ async function buildSchemaDefinition(config) {
|
|
|
1352
1388
|
console.warn(`No valid schema found in ${filePath}, skipping...`);
|
|
1353
1389
|
continue;
|
|
1354
1390
|
}
|
|
1355
|
-
const
|
|
1391
|
+
const collectionNameFromSchema = extractCollectionNameFromSchema(zodSchema);
|
|
1392
|
+
const collectionName = collectionNameFromSchema ?? getCollectionNameFromFile(filePath);
|
|
1356
1393
|
const collectionSchema = convertZodSchemaToCollectionSchema(collectionName, zodSchema);
|
|
1357
1394
|
collections.set(collectionName, collectionSchema);
|
|
1358
1395
|
} catch (error) {
|