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/index.cjs
CHANGED
|
@@ -3848,10 +3848,19 @@ function aggregateChanges(currentSchema, previousSnapshot, config) {
|
|
|
3848
3848
|
collectionsToModify.push(modification);
|
|
3849
3849
|
}
|
|
3850
3850
|
}
|
|
3851
|
+
const existingCollectionIds = /* @__PURE__ */ new Map();
|
|
3852
|
+
if (previousSnapshot) {
|
|
3853
|
+
for (const [name, collection] of previousSnapshot.collections) {
|
|
3854
|
+
if (collection.id) {
|
|
3855
|
+
existingCollectionIds.set(name, collection.id);
|
|
3856
|
+
}
|
|
3857
|
+
}
|
|
3858
|
+
}
|
|
3851
3859
|
return {
|
|
3852
3860
|
collectionsToCreate: collectionsWithIds,
|
|
3853
3861
|
collectionsToDelete: filteredCollectionsToDelete,
|
|
3854
|
-
collectionsToModify
|
|
3862
|
+
collectionsToModify,
|
|
3863
|
+
existingCollectionIds
|
|
3855
3864
|
};
|
|
3856
3865
|
}
|
|
3857
3866
|
function detectDestructiveChanges(diff, config) {
|
|
@@ -4507,7 +4516,7 @@ function generateFieldAddition(collectionName, field, varName, isLast = false, c
|
|
|
4507
4516
|
lines.push(isLast ? ` return app.save(${collectionVar});` : ` app.save(${collectionVar});`);
|
|
4508
4517
|
return lines.join("\n");
|
|
4509
4518
|
}
|
|
4510
|
-
function generateFieldModification(collectionName, modification, varName, isLast = false) {
|
|
4519
|
+
function generateFieldModification(collectionName, modification, varName, isLast = false, collectionIdMap) {
|
|
4511
4520
|
const lines = [];
|
|
4512
4521
|
const collectionVar = varName || `collection_${collectionName}_${modification.fieldName}`;
|
|
4513
4522
|
const fieldVar = `${collectionVar}_field`;
|
|
@@ -4522,7 +4531,14 @@ function generateFieldModification(collectionName, modification, varName, isLast
|
|
|
4522
4531
|
const relationKey = change.property.replace("relation.", "");
|
|
4523
4532
|
if (relationKey === "collection") {
|
|
4524
4533
|
const isUsersCollection = String(change.newValue).toLowerCase() === "users";
|
|
4525
|
-
|
|
4534
|
+
let collectionIdValue;
|
|
4535
|
+
if (isUsersCollection) {
|
|
4536
|
+
collectionIdValue = '"_pb_users_auth_"';
|
|
4537
|
+
} else if (collectionIdMap && collectionIdMap.has(String(change.newValue))) {
|
|
4538
|
+
collectionIdValue = `"${collectionIdMap.get(String(change.newValue))}"`;
|
|
4539
|
+
} else {
|
|
4540
|
+
collectionIdValue = `app.findCollectionByNameOrId("${change.newValue}").id`;
|
|
4541
|
+
}
|
|
4526
4542
|
lines.push(` ${fieldVar}.collectionId = ${collectionIdValue};`);
|
|
4527
4543
|
} else {
|
|
4528
4544
|
lines.push(` ${fieldVar}.${relationKey} = ${formatValue(change.newValue)};`);
|
|
@@ -4598,9 +4614,10 @@ function generateOperationUpMigration(operation, collectionIdMap) {
|
|
|
4598
4614
|
const collectionName = typeof operation.collection === "string" ? operation.collection : operation.collection?.name ?? modification.collection;
|
|
4599
4615
|
let operationCount = 0;
|
|
4600
4616
|
const totalOperations = modification.fieldsToAdd.length + modification.fieldsToModify.length + modification.fieldsToRemove.length + modification.indexesToAdd.length + modification.indexesToRemove.length + modification.rulesToUpdate.length + modification.permissionsToUpdate.length;
|
|
4601
|
-
for (
|
|
4617
|
+
for (let i = 0; i < modification.fieldsToAdd.length; i++) {
|
|
4618
|
+
const field = modification.fieldsToAdd[i];
|
|
4602
4619
|
operationCount++;
|
|
4603
|
-
const varName = `collection_${collectionName}_add_${field.name}`;
|
|
4620
|
+
const varName = `collection_${collectionName}_add_${field.name}_${i}`;
|
|
4604
4621
|
const isLast = operationCount === totalOperations;
|
|
4605
4622
|
lines.push(generateFieldAddition(collectionName, field, varName, isLast, collectionIdMap));
|
|
4606
4623
|
if (!isLast) lines.push("");
|
|
@@ -4609,7 +4626,7 @@ function generateOperationUpMigration(operation, collectionIdMap) {
|
|
|
4609
4626
|
operationCount++;
|
|
4610
4627
|
const varName = `collection_${collectionName}_modify_${fieldMod.fieldName}`;
|
|
4611
4628
|
const isLast = operationCount === totalOperations;
|
|
4612
|
-
lines.push(generateFieldModification(collectionName, fieldMod, varName, isLast));
|
|
4629
|
+
lines.push(generateFieldModification(collectionName, fieldMod, varName, isLast, collectionIdMap));
|
|
4613
4630
|
if (!isLast) lines.push("");
|
|
4614
4631
|
}
|
|
4615
4632
|
for (const field of modification.fieldsToRemove) {
|
|
@@ -4794,6 +4811,11 @@ function generateUpMigration(diff) {
|
|
|
4794
4811
|
collectionIdMap.set(collection.name, collection.id);
|
|
4795
4812
|
}
|
|
4796
4813
|
}
|
|
4814
|
+
if (diff.existingCollectionIds) {
|
|
4815
|
+
for (const [name, id] of diff.existingCollectionIds) {
|
|
4816
|
+
collectionIdMap.set(name, id);
|
|
4817
|
+
}
|
|
4818
|
+
}
|
|
4797
4819
|
if (diff.collectionsToCreate.length > 0) {
|
|
4798
4820
|
lines.push(` // Create new collections`);
|
|
4799
4821
|
for (let i = 0; i < diff.collectionsToCreate.length; i++) {
|
|
@@ -4809,8 +4831,9 @@ function generateUpMigration(diff) {
|
|
|
4809
4831
|
const collectionName = modification.collection;
|
|
4810
4832
|
if (modification.fieldsToAdd.length > 0) {
|
|
4811
4833
|
lines.push(` // Add fields to ${collectionName}`);
|
|
4812
|
-
for (
|
|
4813
|
-
const
|
|
4834
|
+
for (let i = 0; i < modification.fieldsToAdd.length; i++) {
|
|
4835
|
+
const field = modification.fieldsToAdd[i];
|
|
4836
|
+
const varName = `collection_${collectionName}_add_${field.name}_${i}`;
|
|
4814
4837
|
lines.push(generateFieldAddition(collectionName, field, varName, false, collectionIdMap));
|
|
4815
4838
|
lines.push(``);
|
|
4816
4839
|
}
|
|
@@ -4819,7 +4842,7 @@ function generateUpMigration(diff) {
|
|
|
4819
4842
|
lines.push(` // Modify fields in ${collectionName}`);
|
|
4820
4843
|
for (const fieldMod of modification.fieldsToModify) {
|
|
4821
4844
|
const varName = `collection_${collectionName}_modify_${fieldMod.fieldName}`;
|
|
4822
|
-
lines.push(generateFieldModification(collectionName, fieldMod, varName));
|
|
4845
|
+
lines.push(generateFieldModification(collectionName, fieldMod, varName, false, collectionIdMap));
|
|
4823
4846
|
lines.push(``);
|
|
4824
4847
|
}
|
|
4825
4848
|
}
|
|
@@ -4916,6 +4939,11 @@ function generateDownMigration(diff) {
|
|
|
4916
4939
|
collectionIdMap.set(collection.name, collection.id);
|
|
4917
4940
|
}
|
|
4918
4941
|
}
|
|
4942
|
+
if (diff.existingCollectionIds) {
|
|
4943
|
+
for (const [name, id] of diff.existingCollectionIds) {
|
|
4944
|
+
collectionIdMap.set(name, id);
|
|
4945
|
+
}
|
|
4946
|
+
}
|
|
4919
4947
|
if (diff.collectionsToDelete.length > 0) {
|
|
4920
4948
|
lines.push(` // Recreate deleted collections`);
|
|
4921
4949
|
for (let i = 0; i < diff.collectionsToDelete.length; i++) {
|
|
@@ -5053,6 +5081,11 @@ function generate(diff, config) {
|
|
|
5053
5081
|
collectionIdMap.set(collection.name, collection.id);
|
|
5054
5082
|
}
|
|
5055
5083
|
}
|
|
5084
|
+
if (diff.existingCollectionIds) {
|
|
5085
|
+
for (const [name, id] of diff.existingCollectionIds) {
|
|
5086
|
+
collectionIdMap.set(name, id);
|
|
5087
|
+
}
|
|
5088
|
+
}
|
|
5056
5089
|
const baseTimestamp = generateTimestamp(normalizedConfig);
|
|
5057
5090
|
const operations = splitDiffByCollection(diff, baseTimestamp);
|
|
5058
5091
|
const filePaths = [];
|