Skip to content

Commit

Permalink
Bumped packages for introduction to event sourcing. Run new prettier …
Browse files Browse the repository at this point in the history
…and lint
  • Loading branch information
oskardudycz committed Jan 3, 2024
1 parent 7b88bc7 commit 71b58c2
Show file tree
Hide file tree
Showing 89 changed files with 8,690 additions and 8,683 deletions.
15,643 changes: 7,797 additions & 7,846 deletions workshops/introduction_to_event_sourcing/package-lock.json

Large diffs are not rendered by default.

48 changes: 23 additions & 25 deletions workshops/introduction_to_event_sourcing/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,36 +36,34 @@
},
"homepage": "https://github.com/oskardudycz/EventSourcing.NodeJS#readme",
"dependencies": {
"@eventstore/db-client": "5.0.0",
"@faker-js/faker": "7.6.0",
"@eventstore/db-client": "6.1.0",
"@faker-js/faker": "8.3.1",
"convict": "6.2.4",
"dotenv": "16.0.3",
"dotenv-cli": "7.0.0",
"dotenv": "16.3.1",
"dotenv-cli": "7.3.0",
"express": "4.18.2",
"immutable": "4.2.2",
"mongodb": "4.13.0"
"immutable": "5.0.0-beta.4"
},
"devDependencies": {
"@types/convict": "6.1.1",
"@types/express": "4.17.16",
"@types/jest": "29.4.0",
"@types/node": "18.11.18",
"@types/supertest": "2.0.12",
"@types/uuid": "9.0.0",
"@typescript-eslint/eslint-plugin": "5.49.0",
"@typescript-eslint/parser": "5.49.0",
"docker-compose": "0.23.19",
"eslint": "8.33.0",
"eslint-config-prettier": "8.6.0",
"eslint-plugin-prettier": "4.2.1",
"jest": "29.4.1",
"@types/convict": "6.1.6",
"@types/express": "4.17.21",
"@types/jest": "29.5.11",
"@types/node": "20.10.6",
"@types/supertest": "6.0.2",
"@types/uuid": "9.0.7",
"@typescript-eslint/eslint-plugin": "6.17.0",
"@typescript-eslint/parser": "6.17.0",
"eslint": "8.56.0",
"eslint-config-prettier": "9.1.0",
"eslint-plugin-prettier": "5.1.2",
"jest": "29.7.0",
"npm-run-all": "4.1.5",
"prettier": "2.8.3",
"prettier": "3.1.1",
"supertest": "6.3.3",
"testcontainers": "9.1.1",
"ts-jest": "29.0.5",
"ts-node": "10.9.1",
"tsconfig-paths": "4.1.2",
"typescript": "4.9.4"
"testcontainers": "10.4.0",
"ts-jest": "29.1.1",
"ts-node": "10.9.2",
"tsconfig-paths": "4.2.0",
"typescript": "5.3.3"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export class ShoppingCart {
private _openedAt: Date,
private _productItems: PricedProductItem[] = [],
private _confirmedAt?: Date,
private _canceledAt?: Date
private _canceledAt?: Date,
) {}

get id() {
Expand Down Expand Up @@ -183,9 +183,9 @@ describe('Events definition', () => {
openedAt,
[pairOfShoes, tShirt],
confirmedAt,
canceledAt
)
)
canceledAt,
),
),
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export type ShoppingCartEvent =
const appendToStream = async (
_eventStore: EventStoreDBClient,
_streamName: string,
_events: ShoppingCartEvent[]
_events: ShoppingCartEvent[],
): Promise<bigint> => {
// TODO: Fill append events logic here.
return Promise.reject('Not implemented!');
Expand Down Expand Up @@ -116,7 +116,7 @@ describe('Appending events', () => {
const appendedEventsCount = await appendToStream(
eventStore,
streamName,
events
events,
);

expect(appendedEventsCount).toBe(BigInt(events.length - 1));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export type ShoppingCart = Readonly<{
const appendToStream = async (
eventStore: EventStoreDBClient,
streamName: string,
events: ShoppingCartEvent[]
events: ShoppingCartEvent[],
): Promise<AppendResult> => {
const serializedEvents = events.map(jsonEvent);

Expand All @@ -84,7 +84,7 @@ const appendToStream = async (

export const getShoppingCart = (
_eventStore: EventStoreDBClient,
_streamName: string
_streamName: string,
): Promise<ShoppingCart> => {
// 1. Add logic here
return Promise.reject('Not implemented!');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export class ShoppingCart {
private _openedAt: Date,
private _productItems: PricedProductItem[] = [],
private _confirmedAt?: Date,
private _canceledAt?: Date
private _canceledAt?: Date,
) {}

get id() {
Expand Down Expand Up @@ -115,7 +115,7 @@ export class ShoppingCart {
} = event;

const currentProductItem = this._productItems.find(
(pi) => pi.productId === productId && pi.unitPrice === unitPrice
(pi) => pi.productId === productId && pi.unitPrice === unitPrice,
);

if (currentProductItem) {
Expand All @@ -131,7 +131,7 @@ export class ShoppingCart {
} = event;

const currentProductItem = this._productItems.find(
(pi) => pi.productId === productId && pi.unitPrice === unitPrice
(pi) => pi.productId === productId && pi.unitPrice === unitPrice,
);

if (!currentProductItem) {
Expand All @@ -143,7 +143,7 @@ export class ShoppingCart {
if (currentProductItem.quantity <= 0) {
this._productItems.splice(
this._productItems.indexOf(currentProductItem),
1
1,
);
}
return;
Expand All @@ -165,7 +165,7 @@ export class ShoppingCart {
const appendToStream = async (
eventStore: EventStoreDBClient,
streamName: string,
events: ShoppingCartEvent[]
events: ShoppingCartEvent[],
): Promise<AppendResult> => {
const serializedEvents = events.map(jsonEvent);

Expand All @@ -176,7 +176,7 @@ const appendToStream = async (

export const getShoppingCart = (
_eventStore: EventStoreDBClient,
_streamName: string
_streamName: string,
): Promise<ShoppingCart> => {
// 1. Add logic here
return Promise.reject('Not implemented!');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export const merge = <T>(
item: T,
where: (current: T) => boolean,
onExisting: (current: T) => T,
onNotFound: () => T | undefined = () => undefined
onNotFound: () => T | undefined = () => undefined,
) => {
let wasFound = false;

Expand Down Expand Up @@ -103,7 +103,7 @@ export type ShoppingCart = Readonly<{

export const evolve = (
state: ShoppingCart,
{ type, data: event }: ShoppingCartEvent
{ type, data: event }: ShoppingCartEvent,
): ShoppingCart => {
switch (type) {
case 'ShoppingCartOpened':
Expand Down Expand Up @@ -132,7 +132,7 @@ export const evolve = (
quantity: p.quantity + productItem.quantity,
};
},
() => productItem
() => productItem,
),
};
}
Expand All @@ -152,7 +152,7 @@ export const evolve = (
...p,
quantity: p.quantity - productItem.quantity,
};
}
},
),
};
}
Expand All @@ -178,7 +178,7 @@ export const getShoppingCart = (events: ShoppingCartEvent[]): ShoppingCart => {

export type Event<
EventType extends string = string,
EventData extends Record<string, unknown> = Record<string, unknown>
EventData extends Record<string, unknown> = Record<string, unknown>,
> = Readonly<{
type: Readonly<EventType>;
data: Readonly<EventData>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export type PricedProductItem = ProductItem & {

export type Event<
EventType extends string = string,
EventData extends Record<string, unknown> = Record<string, unknown>
EventData extends Record<string, unknown> = Record<string, unknown>,
> = Readonly<{
type: Readonly<EventType>;
data: Readonly<EventData>;
Expand Down Expand Up @@ -79,7 +79,7 @@ export class ShoppingCart {
private _openedAt: Date,
private _productItems: PricedProductItem[] = [],
private _confirmedAt?: Date,
private _canceledAt?: Date
private _canceledAt?: Date,
) {}

get id() {
Expand Down Expand Up @@ -126,7 +126,7 @@ export class ShoppingCart {
} = event;

const currentProductItem = this._productItems.find(
(pi) => pi.productId === productId && pi.unitPrice === unitPrice
(pi) => pi.productId === productId && pi.unitPrice === unitPrice,
);

if (currentProductItem) {
Expand All @@ -142,7 +142,7 @@ export class ShoppingCart {
} = event;

const currentProductItem = this._productItems.find(
(pi) => pi.productId === productId && pi.unitPrice === unitPrice
(pi) => pi.productId === productId && pi.unitPrice === unitPrice,
);

if (!currentProductItem) {
Expand All @@ -154,7 +154,7 @@ export class ShoppingCart {
if (currentProductItem.quantity <= 0) {
this._productItems.splice(
this._productItems.indexOf(currentProductItem),
1
1,
);
}
return;
Expand All @@ -174,10 +174,21 @@ export class ShoppingCart {
}

export const getShoppingCart = (events: ShoppingCartEvent[]): ShoppingCart => {
return events.reduce<ShoppingCart>((state, event) => {
state.evolve(event);
return state;
}, new ShoppingCart(undefined!, undefined!, undefined!, undefined!, undefined, undefined, undefined));
return events.reduce<ShoppingCart>(
(state, event) => {
state.evolve(event);
return state;
},
new ShoppingCart(
undefined!,
undefined!,
undefined!,
undefined!,
undefined,
undefined,
undefined,
),
);
};

export interface EventStore {
Expand Down Expand Up @@ -290,9 +301,9 @@ describe('Getting state from events', () => {
ShoppingCartStatus.Confirmed,
openedAt,
[pairOfShoes, tShirt],
confirmedAt
)
)
confirmedAt,
),
),
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export const merge = <T>(
item: T,
where: (current: T) => boolean,
onExisting: (current: T) => T,
onNotFound: () => T | undefined = () => undefined
onNotFound: () => T | undefined = () => undefined,
) => {
let wasFound = false;

Expand Down Expand Up @@ -105,7 +105,7 @@ export type ShoppingCart = Readonly<{

export const evolve = (
state: ShoppingCart,
{ type, data: event }: ShoppingCartEvent
{ type, data: event }: ShoppingCartEvent,
): ShoppingCart => {
switch (type) {
case 'ShoppingCartOpened':
Expand Down Expand Up @@ -134,7 +134,7 @@ export const evolve = (
quantity: p.quantity + productItem.quantity,
};
},
() => productItem
() => productItem,
),
};
}
Expand All @@ -154,7 +154,7 @@ export const evolve = (
...p,
quantity: p.quantity - productItem.quantity,
};
}
},
),
};
}
Expand All @@ -180,7 +180,7 @@ export const getShoppingCart = (events: ShoppingCartEvent[]): ShoppingCart => {

export type Event<
EventType extends string = string,
EventData extends Record<string, unknown> = Record<string, unknown>
EventData extends Record<string, unknown> = Record<string, unknown>,
> = Readonly<{
type: Readonly<EventType>;
data: Readonly<EventData>;
Expand All @@ -190,10 +190,10 @@ export const mapShoppingCartStreamId = (id: string) => `shopping_cart-${id}`;

export const readStream = async (
eventStore: EventStoreDBClient,
shoppingCartId: string
shoppingCartId: string,
) => {
const readResult = eventStore.readStream<ShoppingCartEvent>(
mapShoppingCartStreamId(shoppingCartId)
mapShoppingCartStreamId(shoppingCartId),
);

const events: ShoppingCartEvent[] = [];
Expand Down
Loading

0 comments on commit 71b58c2

Please sign in to comment.