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.cjs
CHANGED
|
@@ -1967,10 +1967,19 @@ function aggregateChanges(currentSchema, previousSnapshot, config) {
|
|
|
1967
1967
|
collectionsToModify.push(modification);
|
|
1968
1968
|
}
|
|
1969
1969
|
}
|
|
1970
|
+
const existingCollectionIds = /* @__PURE__ */ new Map();
|
|
1971
|
+
if (previousSnapshot) {
|
|
1972
|
+
for (const [name, collection] of previousSnapshot.collections) {
|
|
1973
|
+
if (collection.id) {
|
|
1974
|
+
existingCollectionIds.set(name, collection.id);
|
|
1975
|
+
}
|
|
1976
|
+
}
|
|
1977
|
+
}
|
|
1970
1978
|
return {
|
|
1971
1979
|
collectionsToCreate: collectionsWithIds,
|
|
1972
1980
|
collectionsToDelete: filteredCollectionsToDelete,
|
|
1973
|
-
collectionsToModify
|
|
1981
|
+
collectionsToModify,
|
|
1982
|
+
existingCollectionIds
|
|
1974
1983
|
};
|
|
1975
1984
|
}
|
|
1976
1985
|
function categorizeChangesBySeverity(diff, _config) {
|
|
@@ -2436,7 +2445,7 @@ function generateFieldAddition(collectionName, field, varName, isLast = false, c
|
|
|
2436
2445
|
lines.push(isLast ? ` return app.save(${collectionVar});` : ` app.save(${collectionVar});`);
|
|
2437
2446
|
return lines.join("\n");
|
|
2438
2447
|
}
|
|
2439
|
-
function generateFieldModification(collectionName, modification, varName, isLast = false) {
|
|
2448
|
+
function generateFieldModification(collectionName, modification, varName, isLast = false, collectionIdMap) {
|
|
2440
2449
|
const lines = [];
|
|
2441
2450
|
const collectionVar = varName || `collection_${collectionName}_${modification.fieldName}`;
|
|
2442
2451
|
const fieldVar = `${collectionVar}_field`;
|
|
@@ -2451,7 +2460,14 @@ function generateFieldModification(collectionName, modification, varName, isLast
|
|
|
2451
2460
|
const relationKey = change.property.replace("relation.", "");
|
|
2452
2461
|
if (relationKey === "collection") {
|
|
2453
2462
|
const isUsersCollection = String(change.newValue).toLowerCase() === "users";
|
|
2454
|
-
|
|
2463
|
+
let collectionIdValue;
|
|
2464
|
+
if (isUsersCollection) {
|
|
2465
|
+
collectionIdValue = '"_pb_users_auth_"';
|
|
2466
|
+
} else if (collectionIdMap && collectionIdMap.has(String(change.newValue))) {
|
|
2467
|
+
collectionIdValue = `"${collectionIdMap.get(String(change.newValue))}"`;
|
|
2468
|
+
} else {
|
|
2469
|
+
collectionIdValue = `app.findCollectionByNameOrId("${change.newValue}").id`;
|
|
2470
|
+
}
|
|
2455
2471
|
lines.push(` ${fieldVar}.collectionId = ${collectionIdValue};`);
|
|
2456
2472
|
} else {
|
|
2457
2473
|
lines.push(` ${fieldVar}.${relationKey} = ${formatValue(change.newValue)};`);
|
|
@@ -2527,9 +2543,10 @@ function generateOperationUpMigration(operation, collectionIdMap) {
|
|
|
2527
2543
|
const collectionName = typeof operation.collection === "string" ? operation.collection : operation.collection?.name ?? modification.collection;
|
|
2528
2544
|
let operationCount = 0;
|
|
2529
2545
|
const totalOperations = modification.fieldsToAdd.length + modification.fieldsToModify.length + modification.fieldsToRemove.length + modification.indexesToAdd.length + modification.indexesToRemove.length + modification.rulesToUpdate.length + modification.permissionsToUpdate.length;
|
|
2530
|
-
for (
|
|
2546
|
+
for (let i = 0; i < modification.fieldsToAdd.length; i++) {
|
|
2547
|
+
const field = modification.fieldsToAdd[i];
|
|
2531
2548
|
operationCount++;
|
|
2532
|
-
const varName = `collection_${collectionName}_add_${field.name}`;
|
|
2549
|
+
const varName = `collection_${collectionName}_add_${field.name}_${i}`;
|
|
2533
2550
|
const isLast = operationCount === totalOperations;
|
|
2534
2551
|
lines.push(generateFieldAddition(collectionName, field, varName, isLast, collectionIdMap));
|
|
2535
2552
|
if (!isLast) lines.push("");
|
|
@@ -2538,7 +2555,7 @@ function generateOperationUpMigration(operation, collectionIdMap) {
|
|
|
2538
2555
|
operationCount++;
|
|
2539
2556
|
const varName = `collection_${collectionName}_modify_${fieldMod.fieldName}`;
|
|
2540
2557
|
const isLast = operationCount === totalOperations;
|
|
2541
|
-
lines.push(generateFieldModification(collectionName, fieldMod, varName, isLast));
|
|
2558
|
+
lines.push(generateFieldModification(collectionName, fieldMod, varName, isLast, collectionIdMap));
|
|
2542
2559
|
if (!isLast) lines.push("");
|
|
2543
2560
|
}
|
|
2544
2561
|
for (const field of modification.fieldsToRemove) {
|
|
@@ -2732,6 +2749,11 @@ function generate(diff, config) {
|
|
|
2732
2749
|
collectionIdMap.set(collection.name, collection.id);
|
|
2733
2750
|
}
|
|
2734
2751
|
}
|
|
2752
|
+
if (diff.existingCollectionIds) {
|
|
2753
|
+
for (const [name, id] of diff.existingCollectionIds) {
|
|
2754
|
+
collectionIdMap.set(name, id);
|
|
2755
|
+
}
|
|
2756
|
+
}
|
|
2735
2757
|
const baseTimestamp = generateTimestamp(normalizedConfig);
|
|
2736
2758
|
const operations = splitDiffByCollection(diff, baseTimestamp);
|
|
2737
2759
|
const filePaths = [];
|