From 637724ba66f2747a78381bbe50322b709e2948db Mon Sep 17 00:00:00 2001 From: "Fabien \"egg\" O'Carroll" Date: Fri, 22 Sep 2023 15:04:48 +0700 Subject: [PATCH] Added CollectionPost events refs https://github.com/TryGhost/Arch/issues/95 These events can be used to know when an automatic collections posts have been updated, as well as by the repository to optimise the storage of CollectionPosts --- .../src/events/CollectionPostAdded.ts | 19 +++++++++++++++++++ .../src/events/CollectionPostRemoved.ts | 19 +++++++++++++++++++ ghost/collections/src/index.ts | 2 ++ 3 files changed, 40 insertions(+) create mode 100644 ghost/collections/src/events/CollectionPostAdded.ts create mode 100644 ghost/collections/src/events/CollectionPostRemoved.ts diff --git a/ghost/collections/src/events/CollectionPostAdded.ts b/ghost/collections/src/events/CollectionPostAdded.ts new file mode 100644 index 0000000000..00cb8d5dec --- /dev/null +++ b/ghost/collections/src/events/CollectionPostAdded.ts @@ -0,0 +1,19 @@ +type CollectionPostAddedData = { + collection_id: string; + post_id: string; +}; + +export class CollectionPostAdded { + data: CollectionPostAddedData; + timestamp: Date; + type = 'CollectionPostAdded' as const; + + constructor(data: CollectionPostAddedData, timestamp: Date) { + this.data = data; + this.timestamp = timestamp; + } + + static create(data: CollectionPostAddedData, timestamp = new Date()) { + return new CollectionPostAdded(data, timestamp); + } +} diff --git a/ghost/collections/src/events/CollectionPostRemoved.ts b/ghost/collections/src/events/CollectionPostRemoved.ts new file mode 100644 index 0000000000..305f6b8eec --- /dev/null +++ b/ghost/collections/src/events/CollectionPostRemoved.ts @@ -0,0 +1,19 @@ +type CollectionPostRemovedData = { + collection_id: string; + post_id: string; +}; + +export class CollectionPostRemoved { + data: CollectionPostRemovedData; + timestamp: Date; + type = 'CollectionPostRemoved' as const; + + constructor(data: CollectionPostRemovedData, timestamp: Date) { + this.data = data; + this.timestamp = timestamp; + } + + static create(data: CollectionPostRemovedData, timestamp = new Date()) { + return new CollectionPostRemoved(data, timestamp); + } +} diff --git a/ghost/collections/src/index.ts b/ghost/collections/src/index.ts index 8423909fdf..af417d2388 100644 --- a/ghost/collections/src/index.ts +++ b/ghost/collections/src/index.ts @@ -4,3 +4,5 @@ export * from './Collection'; export * from './events/PostAddedEvent'; export * from './events/PostEditedEvent'; export * from './events/TagDeletedEvent'; +export * from './events/CollectionPostAdded'; +export * from './events/CollectionPostRemoved';