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/migration/index.cjs
CHANGED
|
@@ -3098,10 +3098,19 @@ function aggregateChanges(currentSchema, previousSnapshot, config) {
|
|
|
3098
3098
|
collectionsToModify.push(modification);
|
|
3099
3099
|
}
|
|
3100
3100
|
}
|
|
3101
|
+
const existingCollectionIds = /* @__PURE__ */ new Map();
|
|
3102
|
+
if (previousSnapshot) {
|
|
3103
|
+
for (const [name, collection] of previousSnapshot.collections) {
|
|
3104
|
+
if (collection.id) {
|
|
3105
|
+
existingCollectionIds.set(name, collection.id);
|
|
3106
|
+
}
|
|
3107
|
+
}
|
|
3108
|
+
}
|
|
3101
3109
|
return {
|
|
3102
3110
|
collectionsToCreate: collectionsWithIds,
|
|
3103
3111
|
collectionsToDelete: filteredCollectionsToDelete,
|
|
3104
|
-
collectionsToModify
|
|
3112
|
+
collectionsToModify,
|
|
3113
|
+
existingCollectionIds
|
|
3105
3114
|
};
|
|
3106
3115
|
}
|
|
3107
3116
|
function detectDestructiveChanges(diff, config) {
|
|
@@ -3757,7 +3766,7 @@ function generateFieldAddition(collectionName, field, varName, isLast = false, c
|
|
|
3757
3766
|
lines.push(isLast ? ` return app.save(${collectionVar});` : ` app.save(${collectionVar});`);
|
|
3758
3767
|
return lines.join("\n");
|
|
3759
3768
|
}
|
|
3760
|
-
function generateFieldModification(collectionName, modification, varName, isLast = false) {
|
|
3769
|
+
function generateFieldModification(collectionName, modification, varName, isLast = false, collectionIdMap) {
|
|
3761
3770
|
const lines = [];
|
|
3762
3771
|
const collectionVar = varName || `collection_${collectionName}_${modification.fieldName}`;
|
|
3763
3772
|
const fieldVar = `${collectionVar}_field`;
|
|
@@ -3772,7 +3781,14 @@ function generateFieldModification(collectionName, modification, varName, isLast
|
|
|
3772
3781
|
const relationKey = change.property.replace("relation.", "");
|
|
3773
3782
|
if (relationKey === "collection") {
|
|
3774
3783
|
const isUsersCollection = String(change.newValue).toLowerCase() === "users";
|
|
3775
|
-
|
|
3784
|
+
let collectionIdValue;
|
|
3785
|
+
if (isUsersCollection) {
|
|
3786
|
+
collectionIdValue = '"_pb_users_auth_"';
|
|
3787
|
+
} else if (collectionIdMap && collectionIdMap.has(String(change.newValue))) {
|
|
3788
|
+
collectionIdValue = `"${collectionIdMap.get(String(change.newValue))}"`;
|
|
3789
|
+
} else {
|
|
3790
|
+
collectionIdValue = `app.findCollectionByNameOrId("${change.newValue}").id`;
|
|
3791
|
+
}
|
|
3776
3792
|
lines.push(` ${fieldVar}.collectionId = ${collectionIdValue};`);
|
|
3777
3793
|
} else {
|
|
3778
3794
|
lines.push(` ${fieldVar}.${relationKey} = ${formatValue(change.newValue)};`);
|
|
@@ -3848,9 +3864,10 @@ function generateOperationUpMigration(operation, collectionIdMap) {
|
|
|
3848
3864
|
const collectionName = typeof operation.collection === "string" ? operation.collection : operation.collection?.name ?? modification.collection;
|
|
3849
3865
|
let operationCount = 0;
|
|
3850
3866
|
const totalOperations = modification.fieldsToAdd.length + modification.fieldsToModify.length + modification.fieldsToRemove.length + modification.indexesToAdd.length + modification.indexesToRemove.length + modification.rulesToUpdate.length + modification.permissionsToUpdate.length;
|
|
3851
|
-
for (
|
|
3867
|
+
for (let i = 0; i < modification.fieldsToAdd.length; i++) {
|
|
3868
|
+
const field = modification.fieldsToAdd[i];
|
|
3852
3869
|
operationCount++;
|
|
3853
|
-
const varName = `collection_${collectionName}_add_${field.name}`;
|
|
3870
|
+
const varName = `collection_${collectionName}_add_${field.name}_${i}`;
|
|
3854
3871
|
const isLast = operationCount === totalOperations;
|
|
3855
3872
|
lines.push(generateFieldAddition(collectionName, field, varName, isLast, collectionIdMap));
|
|
3856
3873
|
if (!isLast) lines.push("");
|
|
@@ -3859,7 +3876,7 @@ function generateOperationUpMigration(operation, collectionIdMap) {
|
|
|
3859
3876
|
operationCount++;
|
|
3860
3877
|
const varName = `collection_${collectionName}_modify_${fieldMod.fieldName}`;
|
|
3861
3878
|
const isLast = operationCount === totalOperations;
|
|
3862
|
-
lines.push(generateFieldModification(collectionName, fieldMod, varName, isLast));
|
|
3879
|
+
lines.push(generateFieldModification(collectionName, fieldMod, varName, isLast, collectionIdMap));
|
|
3863
3880
|
if (!isLast) lines.push("");
|
|
3864
3881
|
}
|
|
3865
3882
|
for (const field of modification.fieldsToRemove) {
|
|
@@ -4044,6 +4061,11 @@ function generateUpMigration(diff) {
|
|
|
4044
4061
|
collectionIdMap.set(collection.name, collection.id);
|
|
4045
4062
|
}
|
|
4046
4063
|
}
|
|
4064
|
+
if (diff.existingCollectionIds) {
|
|
4065
|
+
for (const [name, id] of diff.existingCollectionIds) {
|
|
4066
|
+
collectionIdMap.set(name, id);
|
|
4067
|
+
}
|
|
4068
|
+
}
|
|
4047
4069
|
if (diff.collectionsToCreate.length > 0) {
|
|
4048
4070
|
lines.push(` // Create new collections`);
|
|
4049
4071
|
for (let i = 0; i < diff.collectionsToCreate.length; i++) {
|
|
@@ -4059,8 +4081,9 @@ function generateUpMigration(diff) {
|
|
|
4059
4081
|
const collectionName = modification.collection;
|
|
4060
4082
|
if (modification.fieldsToAdd.length > 0) {
|
|
4061
4083
|
lines.push(` // Add fields to ${collectionName}`);
|
|
4062
|
-
for (
|
|
4063
|
-
const
|
|
4084
|
+
for (let i = 0; i < modification.fieldsToAdd.length; i++) {
|
|
4085
|
+
const field = modification.fieldsToAdd[i];
|
|
4086
|
+
const varName = `collection_${collectionName}_add_${field.name}_${i}`;
|
|
4064
4087
|
lines.push(generateFieldAddition(collectionName, field, varName, false, collectionIdMap));
|
|
4065
4088
|
lines.push(``);
|
|
4066
4089
|
}
|
|
@@ -4069,7 +4092,7 @@ function generateUpMigration(diff) {
|
|
|
4069
4092
|
lines.push(` // Modify fields in ${collectionName}`);
|
|
4070
4093
|
for (const fieldMod of modification.fieldsToModify) {
|
|
4071
4094
|
const varName = `collection_${collectionName}_modify_${fieldMod.fieldName}`;
|
|
4072
|
-
lines.push(generateFieldModification(collectionName, fieldMod, varName));
|
|
4095
|
+
lines.push(generateFieldModification(collectionName, fieldMod, varName, false, collectionIdMap));
|
|
4073
4096
|
lines.push(``);
|
|
4074
4097
|
}
|
|
4075
4098
|
}
|
|
@@ -4166,6 +4189,11 @@ function generateDownMigration(diff) {
|
|
|
4166
4189
|
collectionIdMap.set(collection.name, collection.id);
|
|
4167
4190
|
}
|
|
4168
4191
|
}
|
|
4192
|
+
if (diff.existingCollectionIds) {
|
|
4193
|
+
for (const [name, id] of diff.existingCollectionIds) {
|
|
4194
|
+
collectionIdMap.set(name, id);
|
|
4195
|
+
}
|
|
4196
|
+
}
|
|
4169
4197
|
if (diff.collectionsToDelete.length > 0) {
|
|
4170
4198
|
lines.push(` // Recreate deleted collections`);
|
|
4171
4199
|
for (let i = 0; i < diff.collectionsToDelete.length; i++) {
|
|
@@ -4303,6 +4331,11 @@ function generate(diff, config) {
|
|
|
4303
4331
|
collectionIdMap.set(collection.name, collection.id);
|
|
4304
4332
|
}
|
|
4305
4333
|
}
|
|
4334
|
+
if (diff.existingCollectionIds) {
|
|
4335
|
+
for (const [name, id] of diff.existingCollectionIds) {
|
|
4336
|
+
collectionIdMap.set(name, id);
|
|
4337
|
+
}
|
|
4338
|
+
}
|
|
4306
4339
|
const baseTimestamp = generateTimestamp(normalizedConfig);
|
|
4307
4340
|
const operations = splitDiffByCollection(diff, baseTimestamp);
|
|
4308
4341
|
const filePaths = [];
|