pocketbase-zod-schema 0.3.2 → 0.3.3
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/dist/cli/index.cjs +28 -6
- package/dist/cli/index.cjs.map +1 -1
- package/dist/cli/index.d.cts +1 -1
- package/dist/cli/index.d.ts +1 -1
- package/dist/cli/index.js +28 -6
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/migrate.cjs +28 -6
- package/dist/cli/migrate.cjs.map +1 -1
- package/dist/cli/migrate.js +28 -6
- package/dist/cli/migrate.js.map +1 -1
- package/dist/cli/utils/index.d.cts +1 -1
- package/dist/cli/utils/index.d.ts +1 -1
- package/dist/index.cjs +42 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +42 -9
- package/dist/index.js.map +1 -1
- package/dist/migration/analyzer.d.cts +1 -1
- package/dist/migration/analyzer.d.ts +1 -1
- package/dist/migration/diff.cjs +10 -1
- package/dist/migration/diff.cjs.map +1 -1
- package/dist/migration/diff.d.cts +1 -1
- package/dist/migration/diff.d.ts +1 -1
- package/dist/migration/diff.js +10 -1
- package/dist/migration/diff.js.map +1 -1
- package/dist/migration/generator.cjs +32 -8
- package/dist/migration/generator.cjs.map +1 -1
- package/dist/migration/generator.d.cts +2 -2
- package/dist/migration/generator.d.ts +2 -2
- package/dist/migration/generator.js +32 -8
- package/dist/migration/generator.js.map +1 -1
- package/dist/migration/index.cjs +42 -9
- 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 +42 -9
- package/dist/migration/index.js.map +1 -1
- package/dist/migration/snapshot.d.cts +1 -1
- package/dist/migration/snapshot.d.ts +1 -1
- package/dist/{types-Dfp-NP2D.d.ts → types-BWhwQxG-.d.ts} +5 -0
- package/dist/{types-CVxPCgWX.d.cts → types-d0yBwHoN.d.cts} +5 -0
- package/package.json +1 -1
package/dist/cli/migrate.js
CHANGED
|
@@ -1939,10 +1939,19 @@ function aggregateChanges(currentSchema, previousSnapshot, config) {
|
|
|
1939
1939
|
collectionsToModify.push(modification);
|
|
1940
1940
|
}
|
|
1941
1941
|
}
|
|
1942
|
+
const existingCollectionIds = /* @__PURE__ */ new Map();
|
|
1943
|
+
if (previousSnapshot) {
|
|
1944
|
+
for (const [name, collection] of previousSnapshot.collections) {
|
|
1945
|
+
if (collection.id) {
|
|
1946
|
+
existingCollectionIds.set(name, collection.id);
|
|
1947
|
+
}
|
|
1948
|
+
}
|
|
1949
|
+
}
|
|
1942
1950
|
return {
|
|
1943
1951
|
collectionsToCreate: collectionsWithIds,
|
|
1944
1952
|
collectionsToDelete: filteredCollectionsToDelete,
|
|
1945
|
-
collectionsToModify
|
|
1953
|
+
collectionsToModify,
|
|
1954
|
+
existingCollectionIds
|
|
1946
1955
|
};
|
|
1947
1956
|
}
|
|
1948
1957
|
function categorizeChangesBySeverity(diff, _config) {
|
|
@@ -2408,7 +2417,7 @@ function generateFieldAddition(collectionName, field, varName, isLast = false, c
|
|
|
2408
2417
|
lines.push(isLast ? ` return app.save(${collectionVar});` : ` app.save(${collectionVar});`);
|
|
2409
2418
|
return lines.join("\n");
|
|
2410
2419
|
}
|
|
2411
|
-
function generateFieldModification(collectionName, modification, varName, isLast = false) {
|
|
2420
|
+
function generateFieldModification(collectionName, modification, varName, isLast = false, collectionIdMap) {
|
|
2412
2421
|
const lines = [];
|
|
2413
2422
|
const collectionVar = varName || `collection_${collectionName}_${modification.fieldName}`;
|
|
2414
2423
|
const fieldVar = `${collectionVar}_field`;
|
|
@@ -2423,7 +2432,14 @@ function generateFieldModification(collectionName, modification, varName, isLast
|
|
|
2423
2432
|
const relationKey = change.property.replace("relation.", "");
|
|
2424
2433
|
if (relationKey === "collection") {
|
|
2425
2434
|
const isUsersCollection = String(change.newValue).toLowerCase() === "users";
|
|
2426
|
-
|
|
2435
|
+
let collectionIdValue;
|
|
2436
|
+
if (isUsersCollection) {
|
|
2437
|
+
collectionIdValue = '"_pb_users_auth_"';
|
|
2438
|
+
} else if (collectionIdMap && collectionIdMap.has(String(change.newValue))) {
|
|
2439
|
+
collectionIdValue = `"${collectionIdMap.get(String(change.newValue))}"`;
|
|
2440
|
+
} else {
|
|
2441
|
+
collectionIdValue = `app.findCollectionByNameOrId("${change.newValue}").id`;
|
|
2442
|
+
}
|
|
2427
2443
|
lines.push(` ${fieldVar}.collectionId = ${collectionIdValue};`);
|
|
2428
2444
|
} else {
|
|
2429
2445
|
lines.push(` ${fieldVar}.${relationKey} = ${formatValue(change.newValue)};`);
|
|
@@ -2499,9 +2515,10 @@ function generateOperationUpMigration(operation, collectionIdMap) {
|
|
|
2499
2515
|
const collectionName = typeof operation.collection === "string" ? operation.collection : operation.collection?.name ?? modification.collection;
|
|
2500
2516
|
let operationCount = 0;
|
|
2501
2517
|
const totalOperations = modification.fieldsToAdd.length + modification.fieldsToModify.length + modification.fieldsToRemove.length + modification.indexesToAdd.length + modification.indexesToRemove.length + modification.rulesToUpdate.length + modification.permissionsToUpdate.length;
|
|
2502
|
-
for (
|
|
2518
|
+
for (let i = 0; i < modification.fieldsToAdd.length; i++) {
|
|
2519
|
+
const field = modification.fieldsToAdd[i];
|
|
2503
2520
|
operationCount++;
|
|
2504
|
-
const varName = `collection_${collectionName}_add_${field.name}`;
|
|
2521
|
+
const varName = `collection_${collectionName}_add_${field.name}_${i}`;
|
|
2505
2522
|
const isLast = operationCount === totalOperations;
|
|
2506
2523
|
lines.push(generateFieldAddition(collectionName, field, varName, isLast, collectionIdMap));
|
|
2507
2524
|
if (!isLast) lines.push("");
|
|
@@ -2510,7 +2527,7 @@ function generateOperationUpMigration(operation, collectionIdMap) {
|
|
|
2510
2527
|
operationCount++;
|
|
2511
2528
|
const varName = `collection_${collectionName}_modify_${fieldMod.fieldName}`;
|
|
2512
2529
|
const isLast = operationCount === totalOperations;
|
|
2513
|
-
lines.push(generateFieldModification(collectionName, fieldMod, varName, isLast));
|
|
2530
|
+
lines.push(generateFieldModification(collectionName, fieldMod, varName, isLast, collectionIdMap));
|
|
2514
2531
|
if (!isLast) lines.push("");
|
|
2515
2532
|
}
|
|
2516
2533
|
for (const field of modification.fieldsToRemove) {
|
|
@@ -2704,6 +2721,11 @@ function generate(diff, config) {
|
|
|
2704
2721
|
collectionIdMap.set(collection.name, collection.id);
|
|
2705
2722
|
}
|
|
2706
2723
|
}
|
|
2724
|
+
if (diff.existingCollectionIds) {
|
|
2725
|
+
for (const [name, id] of diff.existingCollectionIds) {
|
|
2726
|
+
collectionIdMap.set(name, id);
|
|
2727
|
+
}
|
|
2728
|
+
}
|
|
2707
2729
|
const baseTimestamp = generateTimestamp(normalizedConfig);
|
|
2708
2730
|
const operations = splitDiffByCollection(diff, baseTimestamp);
|
|
2709
2731
|
const filePaths = [];
|