From 9d8f29b7926547bcee401b26dc592ffca5de5dae Mon Sep 17 00:00:00 2001 From: Brainslug Date: Mon, 5 Jun 2023 15:05:00 +0200 Subject: [PATCH] Add extra type check in apply-diff (#18783) --- .changeset/nine-masks-explode.md | 5 +++++ api/src/utils/apply-diff.ts | 8 +++++--- 2 files changed, 10 insertions(+), 3 deletions(-) create mode 100644 .changeset/nine-masks-explode.md diff --git a/.changeset/nine-masks-explode.md b/.changeset/nine-masks-explode.md new file mode 100644 index 0000000000..f6d1e27e75 --- /dev/null +++ b/.changeset/nine-masks-explode.md @@ -0,0 +1,5 @@ +--- +"@directus/api": patch +--- + +Added extra type check in apply-diff diff --git a/api/src/utils/apply-diff.ts b/api/src/utils/apply-diff.ts index 404d29ba3c..f448300461 100644 --- a/api/src/utils/apply-diff.ts +++ b/api/src/utils/apply-diff.ts @@ -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).lhs.meta?.group === null - ) + snapshotDiff.collections.filter(({ diff }) => { + if (diff.length === 0 || diff[0] === undefined) return false; + const collectionDiff = diff[0] as DiffDeleted; + return collectionDiff.kind === DiffKind.DELETE && collectionDiff.lhs?.meta?.group === null; + }) ); for (const { collection, diff } of snapshotDiff.collections) {