Skip to content

Commit

Permalink
Updated packages in Unpeeling Onion sample
Browse files Browse the repository at this point in the history
  • Loading branch information
oskardudycz committed Jan 3, 2024
1 parent d476dc8 commit 6b8c9b7
Show file tree
Hide file tree
Showing 50 changed files with 5,640 additions and 5,741 deletions.
2 changes: 1 addition & 1 deletion samples/unpeelingOnion/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ services:
# EventStoreDB - Event Store
#######################################################
mongo:
image: mongo:5
image: mongo:6.0.12
ports:
- '27017:27017'
networks:
Expand Down
11,051 changes: 5,470 additions & 5,581 deletions samples/unpeelingOnion/package-lock.json

Large diffs are not rendered by default.

49 changes: 25 additions & 24 deletions samples/unpeelingOnion/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "1.0.0",
"description": "Samples of migrating from CRUD to Event Sourcing",
"scripts": {
"setup": "cat .nvmrc | nvm install; nvm use",
"build": "run-s lint build:ts",
"build:ts": "tsc",
"build:ts:watch": "tsc --watch",
Expand Down Expand Up @@ -44,39 +45,39 @@
},
"homepage": "https://github.com/oskardudycz/EventSourcing.NodeJS#readme",
"dependencies": {
"@databases/pg": "5.4.1",
"@eventstore/db-client": "5.0.1",
"@faker-js/faker": "7.6.0",
"@databases/pg": "5.5.0",
"@eventstore/db-client": "6.1.0",
"@faker-js/faker": "8.3.1",
"convict": "6.2.4",
"dotenv": "16.0.3",
"dotenv-cli": "7.2.1",
"dotenv": "16.3.1",
"dotenv-cli": "7.3.0",
"express": "4.18.2",
"mongodb": "5.2.0"
"mongodb": "6.3.0"
},
"devDependencies": {
"@databases/pg-migrations": "5.0.2",
"@databases/migrations-base": "3.0.1",
"@databases/pg-typed": "4.4.1",
"@types/convict": "6.1.1",
"@types/express": "4.17.17",
"@types/jest": "29.5.0",
"@types/node": "18.15.11",
"@types/supertest": "2.0.12",
"@types/uuid": "9.0.1",
"@typescript-eslint/eslint-plugin": "5.58.0",
"@typescript-eslint/parser": "5.58.0",
"eslint": "8.38.0",
"eslint-config-prettier": "8.8.0",
"eslint-plugin-prettier": "4.2.1",
"jest": "29.5.0",
"@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.7",
"prettier-plugin-sql": "0.14.0",
"prettier": "3.1.1",
"prettier-plugin-sql": "0.18.0",
"supertest": "6.3.3",
"testcontainers": "9.5.0",
"ts-jest": "29.1.0",
"ts-node": "10.9.1",
"testcontainers": "10.4.0",
"ts-jest": "29.1.1",
"ts-node": "10.9.2",
"tsconfig-paths": "4.2.0",
"typescript": "5.0.4"
"typescript": "5.3.3"
}
}
5 changes: 4 additions & 1 deletion samples/unpeelingOnion/src/core/aggregates/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ export abstract class Aggregate {
return this._revision;
}

constructor(protected _id: string, protected _revision: number) {}
constructor(
protected _id: string,
protected _revision: number,
) {}

public dequeueUncomittedEvents(): Event[] {
const events = this.uncomittedEvents;
Expand Down
2 changes: 1 addition & 1 deletion samples/unpeelingOnion/src/core/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const getApplication = (...routers: Router[]) => {
app.use(
express.urlencoded({
extended: true,
})
}),
);
app.use(...routers);

Expand Down
6 changes: 3 additions & 3 deletions samples/unpeelingOnion/src/core/commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ export const CommandBusFactory = (): CommandBus => {
if (handler === undefined || !handler.canHandle) {
return Promise.reject(
new Error(
`Command handler for ${JSON.stringify(command)} not found!`
)
`Command handler for ${JSON.stringify(command)} not found!`,
),
);
}
return handler.handle(command);
Expand All @@ -46,7 +46,7 @@ export const CommandBusFactory = (): CommandBus => {

export const registerCommandHandler = <C extends Command>(
commandType: Constructor<C>,
commandHandler: CommandHandler<C>
commandHandler: CommandHandler<C>,
) => {
return commandHandlers.push((command: Command) => {
if (!(command instanceof commandType)) {
Expand Down
2 changes: 1 addition & 1 deletion samples/unpeelingOnion/src/core/events/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export const EventBusFactory = (): EventBus => {

export const registerEventHandler = <C extends Event>(
eventType: Constructor<C>,
eventHandler: EventHandler<C>
eventHandler: EventHandler<C>,
) => {
return eventHandlers.push((event: Event) => {
if (!(event instanceof eventType)) {
Expand Down
14 changes: 7 additions & 7 deletions samples/unpeelingOnion/src/core/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export type ApiRequest = Request<
//////////////////////////////////////

type WeakETag = `W/${string}`;
type ETag = WeakETag | string;
type ETag = string;

const enum HeaderNames {
IF_MATCH = 'if-match',
Expand Down Expand Up @@ -45,7 +45,7 @@ export const toWeakETag = (value: number | bigint | string): WeakETag => {

export const getETagFromHeader = (
request: ApiRequest,
headerName: HeaderNames
headerName: HeaderNames,
): ETag | undefined => {
const etag = request.headers[headerName];

Expand All @@ -58,7 +58,7 @@ export const getETagFromHeader = (

export const getWeakETagValueFromHeader = (
request: ApiRequest,
headerName: HeaderNames
headerName: HeaderNames,
): WeakETag | undefined => {
const etag = getETagFromHeader(request, headerName);

Expand All @@ -75,7 +75,7 @@ export const getWeakETagValueFromHeader = (

export const getExpectedRevision = (
request: ApiRequest,
headerName: HeaderNames
headerName: HeaderNames,
): bigint | undefined => {
const eTag = getWeakETagValueFromHeader(request, headerName);

Expand All @@ -97,7 +97,7 @@ export const getExpectedRevisionFromIfMatch = (request: ApiRequest): bigint => {
};

export const getExpectedRevisionFromIfNotMatch = (
request: ApiRequest
request: ApiRequest,
): bigint | undefined => getExpectedRevision(request, HeaderNames.IF_NOT_MATCH);

//////////////////////////////////////
Expand All @@ -107,11 +107,11 @@ export const getExpectedRevisionFromIfNotMatch = (
export const sendCreated = (
response: Response,
createdId: string,
urlPrefix?: string
urlPrefix?: string,
): void => {
response.setHeader(
'Location',
`${urlPrefix ?? response.req.url}/${createdId}`
`${urlPrefix ?? response.req.url}/${createdId}`,
);
response.status(201).json({ id: createdId });
};
6 changes: 3 additions & 3 deletions samples/unpeelingOnion/src/core/mongo/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ import { Collection, Document, Filter, MongoClient, ObjectId } from 'mongodb';
export const getCollection = <T extends Document & { _id: ObjectId }>(
mongo: MongoClient,
collectionName: string,
databaseName?: string | undefined
databaseName?: string | undefined,
) => {
const db = mongo.db(databaseName);
return db.collection<T>(collectionName);
};

export const findById = async <T extends Document & { _id: ObjectId }>(
collection: Collection<T>,
id: string
id: string,
): Promise<T | null> => {
const result = await collection.findOne({
_id: new ObjectId(id),
Expand All @@ -24,7 +24,7 @@ export const findById = async <T extends Document & { _id: ObjectId }>(

export const getById = async <T extends Document & { _id: ObjectId }>(
collection: Collection<T>,
id: string
id: string,
): Promise<T> => {
const result = await findById(collection, id);

Expand Down
8 changes: 4 additions & 4 deletions samples/unpeelingOnion/src/core/mongo/repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export abstract class MongoDbRepository<T extends Document & { _id: ObjectId }>
constructor(
mongo: MongoClient,
collectionName: string,
databaseName?: string | undefined
databaseName?: string | undefined,
) {
this.collection = getCollection<T>(mongo, collectionName, databaseName);
}
Expand All @@ -24,23 +24,23 @@ export abstract class MongoDbRepository<T extends Document & { _id: ObjectId }>
await this.collection.updateOne(
{ _id: entity._id } as Filter<T>,
{ $set: entity },
{ upsert: true }
{ upsert: true },
);
}

async update(entity: T): Promise<void> {
await this.collection.updateOne(
{ _id: entity._id } as Filter<T>,
{ $set: entity },
{ upsert: false }
{ upsert: false },
);
}

async upsert(entity: T): Promise<void> {
await this.collection.updateOne(
{ _id: entity._id } as Filter<T>,
{ $set: entity },
{ upsert: true }
{ upsert: true },
);
}

Expand Down
10 changes: 5 additions & 5 deletions samples/unpeelingOnion/src/core/mongodb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ let mongoClient: MongoClient;
let isOpened = false;

export async function getMongoDB(
connectionString?: string
connectionString?: string,
): Promise<MongoClient> {
if (connectionString ?? !config.mongoDB.connectionString) {
throw 'MongoDB connection string not set. Please define "ESDB_CONNECTION_STRING" environment variable';
}

if (!mongoClient) {
mongoClient = new MongoClient(
connectionString ?? config.mongoDB.connectionString
connectionString ?? config.mongoDB.connectionString,
);
await mongoClient.connect();
isOpened = true;
Expand All @@ -42,7 +42,7 @@ export type ExecuteOnMongoDBOptions =
| string;

export async function getMongoCollection<Doc extends Document>(
options: ExecuteOnMongoDBOptions
options: ExecuteOnMongoDBOptions,
): Promise<Collection<Doc>> {
const mongo = await getMongoDB();

Expand All @@ -58,7 +58,7 @@ export async function getMongoCollection<Doc extends Document>(
export type FAILED_TO_UPDATE_DOCUMENT = 'FAILED_TO_UPDATE_DOCUMENT';

export async function assertUpdated(
update: () => Promise<UpdateResult>
update: () => Promise<UpdateResult>,
): Promise<UpdateResult> {
const result = await update();

Expand All @@ -79,7 +79,7 @@ export async function assertUpdated(
export type DOCUMENT_NOT_FOUND = 'DOCUMENT_NOT_FOUND';

export async function assertFound<T>(
find: () => Promise<T | null>
find: () => Promise<T | null>,
): Promise<T> {
const result = await find();

Expand Down
4 changes: 2 additions & 2 deletions samples/unpeelingOnion/src/core/queries/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const QueryBusFactory = (): QueryBus => {

if (handler === undefined || !handler.canHandle) {
return Promise.reject(
new Error(`Query handler for ${JSON.stringify(query)} not found!`)
new Error(`Query handler for ${JSON.stringify(query)} not found!`),
);
}
return (await handler.handle(query)) as Result;
Expand All @@ -44,7 +44,7 @@ export const QueryBusFactory = (): QueryBus => {

export const registerQueryHandler = <C extends Query, Result>(
queryType: Constructor<C>,
queryHandler: QueryHandler<C, Result>
queryHandler: QueryHandler<C, Result>,
) => {
return queryHandlers.push((query: Query) => {
if (!(query instanceof queryType)) {
Expand Down
4 changes: 2 additions & 2 deletions samples/unpeelingOnion/src/core/retries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const sleep = async (timeout: number): Promise<void> => {

export const retryPromise = async <T = never>(
callback: () => Promise<T>,
options: RetryOptions = DEFAULT_RETRY_OPTIONS
options: RetryOptions = DEFAULT_RETRY_OPTIONS,
): Promise<T> => {
let retryCount = 0;
const { maxRetries, delay, shouldRetry } = {
Expand All @@ -41,7 +41,7 @@ export const retryPromise = async <T = never>(

console.warn(
`[retry] Retrying (number: ${retryCount + 1}, delay: ${sleepTime}): %s`,
error
error,
);

await sleep(sleepTime);
Expand Down
4 changes: 2 additions & 2 deletions samples/unpeelingOnion/src/core/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const assertPositiveNumber = (value: unknown): number => {
};

export const assertPositiveNumberOrUndefined = (
value: unknown
value: unknown,
): number | undefined => {
return value != null ? assertPositiveNumber(value) : value ?? undefined;
};
Expand Down Expand Up @@ -71,7 +71,7 @@ export const assertArrayOrUndefined = (value: unknown): [] | undefined => {

export const greaterOrEqual = (
first: Date | null | undefined,
second: Date | null | undefined
second: Date | null | undefined,
): boolean => {
if (!first) return false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export class AddProductItemToShoppingCartHandler
constructor(
private repository: ShoppingCartRepository,
private mapper: ShoppingCartMapper,
private eventBus: EventBus
private eventBus: EventBus,
) {}

async handle(command: AddProductItemToShoppingCart): Promise<void> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export class ConfirmShoppingCartHandler
constructor(
private repository: ShoppingCartRepository,
private mapper: ShoppingCartMapper,
private eventBus: EventBus
private eventBus: EventBus,
) {}

async handle(command: ConfirmShoppingCart): Promise<void> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ export class OpenShoppingCartHandler
constructor(
private repository: ShoppingCartRepository,
private mapper: ShoppingCartMapper,
private eventBus: EventBus
private eventBus: EventBus,
) {}

async handle(command: OpenShoppingCart): Promise<void> {
const aggregate = ShoppingCart.open(
command.shoppingCartId,
command.customerId
command.customerId,
);

await this.repository.add(this.mapper.toModel(aggregate));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export class RemoveProductItemFromShoppingCartHandler
constructor(
private repository: ShoppingCartRepository,
private mapper: ShoppingCartMapper,
private eventBus: EventBus
private eventBus: EventBus,
) {}

async handle(command: RemoveProductItemFromShoppingCart): Promise<void> {
Expand Down
Loading

0 comments on commit 6b8c9b7

Please sign in to comment.