Extracted domain event interceptor to separate init

closes https://github.com/TryGhost/Arch/issues/13

- Model to Domain event interceptor is a class that does not strictly belong to Collections. It's supposed to be used in any new code that depends on legacy bookshelf model events. Extracted it's initialization to it's own service for clarity and visibility.
This commit is contained in:
Naz 2023-08-29 14:43:32 +08:00 committed by naz
parent 5989ea0ffa
commit dc7b20d50b
3 changed files with 11 additions and 2 deletions

View File

@ -326,6 +326,7 @@ async function initServices({config}) {
const slackNotifications = require('./server/services/slack-notifications'); const slackNotifications = require('./server/services/slack-notifications');
const mediaInliner = require('./server/services/media-inliner'); const mediaInliner = require('./server/services/media-inliner');
const collections = require('./server/services/collections'); const collections = require('./server/services/collections');
const modelToDomainEventInterceptor = require('./server/services/model-to-domain-event-interceptor');
const mailEvents = require('./server/services/mail-events'); const mailEvents = require('./server/services/mail-events');
const donationService = require('./server/services/donations'); const donationService = require('./server/services/donations');
@ -365,6 +366,7 @@ async function initServices({config}) {
emailSuppressionList.init(), emailSuppressionList.init(),
slackNotifications.init(), slackNotifications.init(),
collections.init(), collections.init(),
modelToDomainEventInterceptor.init(),
mediaInliner.init(), mediaInliner.init(),
mailEvents.init(), mailEvents.init(),
donationService.init() donationService.init()

View File

@ -36,7 +36,6 @@ class CollectionsServiceWrapper {
} }
inited = true; inited = true;
this.api.subscribeToEvents(); this.api.subscribeToEvents();
require('./intercept-events')();
} }
} }

View File

@ -1,4 +1,11 @@
module.exports = () => { let inited = false;
module.exports.init = async () => {
if (inited) {
return;
}
inited = true;
const DomainEvents = require('@tryghost/domain-events/lib/DomainEvents'); const DomainEvents = require('@tryghost/domain-events/lib/DomainEvents');
const {ModelToDomainEventInterceptor} = require('@tryghost/model-to-domain-event-interceptor'); const {ModelToDomainEventInterceptor} = require('@tryghost/model-to-domain-event-interceptor');
const events = require('../../lib/common/events'); const events = require('../../lib/common/events');
@ -6,5 +13,6 @@ module.exports = () => {
ModelEvents: events, ModelEvents: events,
DomainEvents: DomainEvents DomainEvents: DomainEvents
}); });
eventInterceptor.init(); eventInterceptor.init();
}; };