refactor(integration): replaced #createEvent with #event
MODIFY
packages/@integration/src/cqrs/domain/Offer.command.ts
packages/@integration/src/cqrs/domain/Offer.command.ts
-import { createEvent, EventsUnion } from '@marblejs/core';
+import * as t from 'io-ts';
+import { event } from '@marblejs/core';
export enum OfferCommandType {
GENERATE_OFFER_DOCUMENT = 'GENERATE_OFFER_DOCUMENT',
}
-export const OfferCommand = {
- generateOffer: createEvent(
- OfferCommandType.GENERATE_OFFER_DOCUMENT,
- (offerId: string) => ({ offerId }),
- ),
-};
-
-export type OfferCommand = EventsUnion<typeof OfferCommand>;
+export const GenerateOfferDocumentCommand =
+ event(OfferCommandType.GENERATE_OFFER_DOCUMENT)(t.type({ offerId: t.string }));

MODIFY
packages/@integration/src/cqrs/domain/Offer.event.ts
packages/@integration/src/cqrs/domain/Offer.event.ts
-import { createEvent, EventsUnion } from '@marblejs/core';
+import * as t from 'io-ts';
+import { event } from '@marblejs/core';
-export enum OfferEventType {
- OFFER_CREATED = 'OFFER_CREATED',
- OFFER_UPDATED = 'OFFER_UPDATED',
+export const enum OfferEventType {
OFFER_DOCUMENT_SAVED = 'OFFER_DOCUMENT_SAVED',
OFFER_DOCUMENT_CREATED = 'OFFER_DOCUMENT_CREATED',
}
-export const OfferEvent = {
- offerCreated: createEvent(
- OfferEventType.OFFER_CREATED,
- (offerId: string) => ({ offerId }),
- ),
- offerUpdated: createEvent(
- OfferEventType.OFFER_UPDATED,
- (offerId: string) => ({ offerId }),
- ),
- offerDocumentCreated: createEvent(
- OfferEventType.OFFER_DOCUMENT_CREATED,
- (offerId: string) => ({ offerId }),
- ),
- offerDocumentSaved: createEvent(
- OfferEventType.OFFER_DOCUMENT_SAVED,
- ),
-};
+export const OfferDocumentCreatedEvent =
+ event(OfferEventType.OFFER_DOCUMENT_CREATED)(t.type({ offerId: t.string }));
-export type OfferEvent = EventsUnion<typeof OfferEvent>;
+export const OfferDocumentSavedEvent =
+ event(OfferEventType.OFFER_DOCUMENT_SAVED)();

MODIFY
packages/@integration/src/cqrs/effects/eventbus.effects.ts
packages/@integration/src/cqrs/effects/eventbus.effects.ts
import { of } from 'rxjs';
import { map, tap, delay } from 'rxjs/operators';
+import { pipe } from 'fp-ts/lib/pipeable';
import { act, matchEvent, useContext, LoggerToken, LoggerTag } from '@marblejs/core';
import { MsgEffect } from '@marblejs/messaging';
-import { OfferCommand } from '../domain/Offer.command';
-import { OfferEvent } from '../domain/Offer.event';
+import { GenerateOfferDocumentCommand } from '../domain/Offer.command';
+import { OfferDocumentSavedEvent, OfferDocumentCreatedEvent } from '../domain/Offer.event';
const tag = LoggerTag.EVENT_BUS;
@@ -11,26 +12,26 @@ export const generateOfferDocument$: MsgEffect = (event$, ctx) => {
const logger = useContext(LoggerToken)(ctx.ask);
return event$.pipe(
- matchEvent(OfferCommand.generateOffer),
- act(event => of(event).pipe(
- map(event => event.payload.offerId),
+ matchEvent(GenerateOfferDocumentCommand),
+ act(event => pipe(
+ of(event.payload.offerId),
tap(logger({ tag, type: 'generateOfferDocument$', message: 'Generating offer document...'})),
delay(5 * 1000),
- map(offerId => OfferEvent.offerDocumentCreated(offerId)),
+ map(offerId => OfferDocumentCreatedEvent.create({ offerId })),
)),
);
}
-export const saveOfferDocument$: MsgEffect = (event$, ctx) => {
+export const offerDocumentCreated$: MsgEffect = (event$, ctx) => {
const logger = useContext(LoggerToken)(ctx.ask);
return event$.pipe(
- matchEvent(OfferEvent.offerDocumentCreated),
- act(event => of(event).pipe(
- map(event => event.payload.offerId),
+ matchEvent(OfferDocumentCreatedEvent),
+ act(event => pipe(
+ of(event.payload.offerId),
tap(logger({ tag, type: 'saveOfferDocument$', message: 'Saving offer document...'})),
delay(5 * 1000),
- map(OfferEvent.offerDocumentSaved),
+ map(OfferDocumentSavedEvent.create),
)),
);
}

MODIFY
packages/@integration/src/cqrs/effects/http.effects.ts
packages/@integration/src/cqrs/effects/http.effects.ts
@@ -2,7 +2,7 @@ import { r, HttpStatus, useContext, use } from '@marblejs/core';
import { tap, mapTo, map } from 'rxjs/operators';
import { EventBusClientToken } from '@marblejs/messaging';
import { requestValidator$, t } from '@marblejs/middleware-io';
-import { OfferCommand } from '../domain/Offer.command';
+import { GenerateOfferDocumentCommand } from '../domain/Offer.command';
const generateDocumentValidator$ = requestValidator$({
params: t.type({
@@ -18,7 +18,7 @@ export const postDocumentsGenerate$ = r.pipe(
return req$.pipe(
use(generateDocumentValidator$),
- map(req => OfferCommand.generateOffer(req.params.id)),
+ map(req => GenerateOfferDocumentCommand.create({ offerId: req.params.id })),
tap(eventBusClient.emit),
mapTo({ status: HttpStatus.ACCEPTED }),
);

MODIFY
packages/@integration/src/cqrs/index.ts
packages/@integration/src/cqrs/index.ts
@@ -6,12 +6,12 @@ import { messagingListener, EventBusClientToken, eventBusClient, EventBusToken,
import { bodyParser$ } from '@marblejs/middleware-body';
import { logger$ } from '@marblejs/middleware-logger';
import { postDocumentsGenerate$ } from './effects/http.effects';
-import { generateOfferDocument$, saveOfferDocument$ } from './effects/eventbus.effects';
+import { generateOfferDocument$, offerDocumentCreated$ } from './effects/eventbus.effects';
const eventBusListener = messagingListener({
effects: [
generateOfferDocument$,
- saveOfferDocument$,
+ offerDocumentCreated$,
],
});

MODIFY
packages/@integration/tsconfig.json
packages/@integration/tsconfig.json
"../node_modules/@types"
],
"lib": [
- "dom",
"es2018"
]
},

refactor(integration): replaced #createEvent with #event