Add extra type check in apply-diff (#18783)

This commit is contained in:
Brainslug
2023-06-05 15:05:00 +02:00
committed by GitHub
parent 1b8f179bad
commit 9d8f29b792
2 changed files with 10 additions and 3 deletions

View File

@@ -0,0 +1,5 @@
---
"@directus/api": patch
---
Added extra type check in apply-diff

View File

@@ -181,9 +181,11 @@ export async function applyDiff(
// delete top level collections (no group) first, then continue with nested collections recursively
await deleteCollections(
snapshotDiff.collections.filter(
({ diff }) => diff[0]?.kind === DiffKind.DELETE && (diff[0] as DiffDeleted<Collection>).lhs.meta?.group === null
)
snapshotDiff.collections.filter(({ diff }) => {
if (diff.length === 0 || diff[0] === undefined) return false;
const collectionDiff = diff[0] as DiffDeleted<Collection>;
return collectionDiff.kind === DiffKind.DELETE && collectionDiff.lhs?.meta?.group === null;
})
);
for (const { collection, diff } of snapshotDiff.collections) {