Skip to content

Commit

Permalink
Updated packages in webinar sample
Browse files Browse the repository at this point in the history
  • Loading branch information
oskardudycz committed Jan 3, 2024
1 parent 71b58c2 commit d476dc8
Show file tree
Hide file tree
Showing 15 changed files with 974 additions and 1,066 deletions.
3 changes: 1 addition & 2 deletions samples/webinar/.vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
"editor.formatOnSave": true,

"editor.codeActionsOnSave": {
// For ESLint
"source.fixAll.eslint": true
"source.fixAll.eslint": "explicit"
},

"editor.tabSize": 2,
Expand Down
6 changes: 3 additions & 3 deletions samples/webinar/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ services:
# EventStoreDB
#######################################################
eventstore.db:
image: eventstore/eventstore:21.10.8-buster-slim
image: eventstore/eventstore:23.10.0-bookworm-slim
# use this image if you're running ARM-based proc like Apple M1
# image: ghcr.io/eventstore/eventstore:21.10.0-alpha-arm64v8
# image: eventstore/eventstore:23.10.0-alpha-arm64v8
environment:
- EVENTSTORE_CLUSTER_SIZE=1
- EVENTSTORE_RUN_PROJECTIONS=All
Expand All @@ -31,7 +31,7 @@ services:
- esdb_network

mongodb:
image: mongo:5.0
image: mongo:6.0.12
# environment:
# MONGO_INITDB_ROOT_USERNAME: root
# MONGO_INITDB_ROOT_PASSWORD: rootpassword
Expand Down
1,863 changes: 885 additions & 978 deletions samples/webinar/package-lock.json

Large diffs are not rendered by default.

28 changes: 14 additions & 14 deletions samples/webinar/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,23 @@
},
"homepage": "https://github.com/oskardudycz/EventSourcing.NodeJS#readme",
"dependencies": {
"@eventstore/db-client": "4.0.0",
"@eventstore/db-client": "6.1.0",
"express": "4.18.2",
"mongodb": "4.8.1"
"mongodb": "6.3.0"
},
"devDependencies": {
"@types/express": "4.17.14",
"@types/node": "18.11.9",
"@types/uuid": "8.3.4",
"@typescript-eslint/eslint-plugin": "5.42.0",
"@typescript-eslint/parser": "5.42.0",
"eslint": "8.26.0",
"eslint-config-prettier": "8.5.0",
"eslint-plugin-prettier": "4.2.1",
"@types/express": "4.17.21",
"@types/node": "20.10.6",
"@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",
"npm-run-all": "4.1.5",
"prettier": "2.7.1",
"ts-node": "10.9.1",
"tsconfig-paths": "4.1.0",
"typescript": "4.8.4"
"prettier": "3.1.1",
"ts-node": "10.9.2",
"tsconfig-paths": "4.2.0",
"typescript": "5.3.3"
}
}
2 changes: 1 addition & 1 deletion samples/webinar/src/core/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const startAPI = (router: Router) => {
app.use(
express.urlencoded({
extended: true,
})
}),
);
app.use(router);

Expand Down
8 changes: 4 additions & 4 deletions samples/webinar/src/core/commandHandling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
export const create =
<Command, StreamEvent extends JSONEventType>(
eventStore: EventStoreDBClient,
handle: (command: Command) => StreamEvent
handle: (command: Command) => StreamEvent,
) =>
(streamName: string, command: Command): Promise<AppendResult> => {
const event = handle(command);
Expand All @@ -30,13 +30,13 @@ export const update =
eventStore: EventStoreDBClient,
handle: (
events: StreamingRead<ResolvedEvent<StreamEvent>>,
command: Command
) => Promise<StreamEvent>
command: Command,
) => Promise<StreamEvent>,
) =>
async (
streamName: string,
command: Command,
expectedRevision: bigint
expectedRevision: bigint,
): Promise<AppendResult> => {
const readStream = eventStore.readStream(streamName);

Expand Down
4 changes: 2 additions & 2 deletions samples/webinar/src/core/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ export const getExpectedRevisionFromETag = (request: Request): bigint =>
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 });
};
18 changes: 9 additions & 9 deletions samples/webinar/src/core/mongoDB.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ import {
let mongoClient: MongoClient;

export const getMongoDB = async (
connectionString?: string
connectionString?: string,
): Promise<MongoClient> => {
if (!mongoClient) {
mongoClient = new MongoClient(
connectionString ?? 'mongodb://localhost:27017/'
connectionString ?? 'mongodb://localhost:27017/',
);
await mongoClient.connect();
}
Expand All @@ -41,7 +41,7 @@ export type ExecuteOnMongoDBOptions =
| string;

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

Expand All @@ -62,7 +62,7 @@ export const enum MongoDBErrors {
}

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

Expand All @@ -74,7 +74,7 @@ export const assertUpdated = async (
};

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

Expand All @@ -91,14 +91,14 @@ export const assertFound = async <T>(

export const retryIfNotFound = <T>(
find: () => Promise<T | null>,
options: RetryOptions = DEFAULT_RETRY_OPTIONS
options: RetryOptions = DEFAULT_RETRY_OPTIONS,
): Promise<T> => {
return retryPromise(() => assertFound(find), options);
};

export const retryIfNotUpdated = (
update: () => Promise<UpdateResult>,
options: RetryOptions = DEFAULT_RETRY_OPTIONS
options: RetryOptions = DEFAULT_RETRY_OPTIONS,
): Promise<UpdateResult> => {
return retryPromise(() => assertUpdated(update), options);
};
Expand Down Expand Up @@ -136,11 +136,11 @@ export const storeCheckpointInCollection =
},
{
upsert: true,
}
},
);
};

export const SubscriptionToAllWithMongoCheckpoints = SubscriptionToAll(
getEventStore(),
loadCheckPointFromCollection
loadCheckPointFromCollection,
);
8 changes: 5 additions & 3 deletions samples/webinar/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 @@ -34,7 +34,9 @@ export const retryPromise = async <T = never>(
} catch (error) {
if (!shouldRetry(error) || retryCount == maxRetries) {
console.error(
`[retry] Exceeded max retry count, throwing: ${JSON.stringify(error)}`
`[retry] Exceeded max retry count, throwing: ${JSON.stringify(
error,
)}`,
);
throw error;
}
Expand All @@ -44,7 +46,7 @@ export const retryPromise = async <T = never>(
console.warn(
`[retry] Retrying (number: ${
retryCount + 1
}, delay: ${sleepTime}): ${JSON.stringify(error)}`
}, delay: ${sleepTime}): ${JSON.stringify(error)}`,
);

await sleep(sleepTime);
Expand Down
8 changes: 4 additions & 4 deletions samples/webinar/src/core/streams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ import {

export type ApplyEvent<Entity, E extends EventType> = (
currentState: Entity | undefined,
event: RecordedEvent<E>
event: RecordedEvent<E>,
) => Entity;

export const StreamAggregator =
<Entity, StreamEvents extends EventType>(
when: ApplyEvent<Entity, StreamEvents>
when: ApplyEvent<Entity, StreamEvents>,
) =>
async (
eventStream: StreamingRead<ResolvedEvent<StreamEvents>>
eventStream: StreamingRead<ResolvedEvent<StreamEvents>>,
): Promise<Entity> => {
let currentState: Entity | undefined = undefined;
for await (const { event } of eventStream) {
Expand All @@ -40,7 +40,7 @@ let eventStore: EventStoreDBClient;
export const getEventStore = (connectionString?: string) => {
if (!eventStore) {
eventStore = EventStoreDBClient.connectionString(
connectionString ?? 'esdb://localhost:2113?tls=false'
connectionString ?? 'esdb://localhost:2113?tls=false',
);
}

Expand Down
4 changes: 2 additions & 2 deletions samples/webinar/src/core/subscriptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export type EventHandler = (event: SubscriptionResolvedEvent) => Promise<void>;
export const SubscriptionToAll =
(
eventStore: EventStoreDBClient,
loadCheckpoint: (subscriptionId: string) => Promise<bigint | undefined>
loadCheckpoint: (subscriptionId: string) => Promise<bigint | undefined>,
) =>
async (subscriptionId: string, handlers: EventHandler[]) => {
const currentPosition = await loadCheckpoint(subscriptionId);
Expand All @@ -42,7 +42,7 @@ export const SubscriptionToAll =
return;
}
console.error(`Received error: ${JSON.stringify(error)}.`);
}
},
);
return subscription;
};
14 changes: 7 additions & 7 deletions samples/webinar/src/shoppingCarts/productItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export interface ProductItem {

export const addProductItem = (
productItems: ProductItem[],
newProductItem: ProductItem
newProductItem: ProductItem,
): ProductItem[] => {
const { productId, quantity } = newProductItem;

Expand All @@ -23,19 +23,19 @@ export const addProductItem = (
const mergedProductItem = { productId, quantity: newQuantity };

return productItems.map((pi) =>
pi.productId === productId ? mergedProductItem : pi
pi.productId === productId ? mergedProductItem : pi,
);
};

export const removeProductItem = (
productItems: ProductItem[],
newProductItem: ProductItem
newProductItem: ProductItem,
): ProductItem[] => {
const { productId, quantity } = newProductItem;

const currentProductItem = assertProductItemExists(
productItems,
newProductItem
newProductItem,
);

const newQuantity = currentProductItem.quantity - quantity;
Expand All @@ -46,20 +46,20 @@ export const removeProductItem = (
const mergedProductItem = { productId, quantity: newQuantity };

return productItems.map((pi) =>
pi.productId === productId ? mergedProductItem : pi
pi.productId === productId ? mergedProductItem : pi,
);
};

export const findProductItem = (
productItems: ProductItem[],
productId: string
productId: string,
): ProductItem | undefined => {
return productItems.find((pi) => pi.productId === productId);
};

export const assertProductItemExists = (
productItems: ProductItem[],
{ productId, quantity }: ProductItem
{ productId, quantity }: ProductItem,
): ProductItem => {
const current = findProductItem(productItems, productId);

Expand Down
Loading

0 comments on commit d476dc8

Please sign in to comment.