Skip to content

Commit

Permalink
Removed stream events method from the API to be able to merge changes…
Browse files Browse the repository at this point in the history
…, it'll be added later on

Also applied other post merge fixed to wrongly resolved conflicts
  • Loading branch information
oskardudycz committed Oct 6, 2024
1 parent e4aa099 commit 2255e21
Show file tree
Hide file tree
Showing 20 changed files with 170 additions and 173 deletions.
2 changes: 2 additions & 0 deletions samples/webApi/expressjs-with-esdb/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ export default defineConfig({
minify: true, //env === 'production',
bundle: true, //env === 'production',
skipNodeModulesBundle: true,
entryPoints: ['src/index.ts'],
watch: env === 'development',
target: 'esnext',
outDir: 'dist', //env === 'production' ? 'dist' : 'lib',
entry: ['src/index.ts'],
Expand Down
16 changes: 0 additions & 16 deletions samples/webApi/expressjs-with-postgresql/src/shoppingCarts/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,22 +189,6 @@ export const shoppingCartApi =
});
}),
);

// Get Shopping Cart
router.get(
'/clients/:clientId/shopping-carts/summary',
on(async (request: GetShoppingCartRequest) => {
const clientId = assertNotEmptyString(request.params.clientId);

const result = await getClientShoppingSummary(readStore, clientId);

if (result === null) return NotFound();

return OK({
body: result,
});
}),
);
};

// Add Product Item
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,6 @@ export type CancelledSummary = ShoppingSummary & {
cartsCount: number;
};

const initialSummary = {
cartsCount: 0,
productItemsCount: 0,
totalAmount: 0,
};

const evolve = (
document: ClientShoppingSummary | null,
{ type, data: event, metadata }: ShoppingCartEvent,
Expand Down Expand Up @@ -99,6 +93,12 @@ const evolve = (
}
};

const initialSummary = {
cartsCount: 0,
productItemsCount: 0,
totalAmount: 0,
};

const withAdjustedTotals = (options: {
summary: ShoppingSummary | undefined;
with: PricedProductItem | ShoppingSummary;
Expand All @@ -125,18 +125,18 @@ const withAdjustedTotals = (options: {
};
};

const ClientShoppingSummaryCollectionName = 'ClientShoppingSummary';
const clientShoppingSummaryCollectionName = 'ClientShoppingSummary';

export const getClientShoppingSummary = (
db: PongoDb,
clientId: string,
): Promise<ClientShoppingSummary | null> =>
db
.collection<ClientShoppingSummary>(ClientShoppingSummaryCollectionName)
.collection<ClientShoppingSummary>(clientShoppingSummaryCollectionName)
.findOne({ _id: clientId });

export const clientShoppingSummaryProjection = pongoMultiStreamProjection({
collectionName: ClientShoppingSummaryCollectionName,
collectionName: clientShoppingSummaryCollectionName,
getDocumentId: (event) => event.metadata.clientId,
evolve,
canHandle: [
Expand Down
91 changes: 59 additions & 32 deletions src/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion src/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"type": "module",
"version": "0.19.1",
"description": "Emmett - Event Sourcing development made simple",
"type": "module",
"engines": {
"node": ">=20.11.1"
},
Expand Down
1 change: 0 additions & 1 deletion src/packages/emmett-esdb/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"type": "module",
"version": "0.19.1",
"description": "Emmett - EventStoreDB - Event Sourcing development made simple",
"type": "module",
"scripts": {
"build": "tsup",
"build:ts": "tsc",
Expand Down
46 changes: 21 additions & 25 deletions src/packages/emmett-esdb/src/eventStore/eventstoreDBEventStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
STREAM_DOES_NOT_EXIST,
STREAM_EXISTS,
globalStreamCaughtUp,
restream,
streamTransformations,
type AggregateStreamOptions,
type AggregateStreamResult,
Expand All @@ -15,7 +14,6 @@ import {
type EventStore,
type ExpectedStreamVersion,
type GlobalStreamCaughtUp,
type GlobalSubscriptionEvent,
type ReadEvent,
type ReadEventMetadataWithGlobalPosition,
type ReadStreamOptions,
Expand All @@ -26,10 +24,8 @@ import {
STREAM_EXISTS as ESDB_STREAM_EXISTS,
EventStoreDBClient,
NO_STREAM,
START,
StreamNotFoundError,
WrongExpectedVersionError,
excludeSystemEvents,
jsonEvent,
type AllStreamResolvedEvent,
type AllStreamSubscription,
Expand Down Expand Up @@ -179,7 +175,7 @@ export const getEventStoreDBEventStore = (
}
},

streamEvents: streamEvents(eventStore),
//streamEvents: streamEvents(eventStore),
};
};

Expand Down Expand Up @@ -251,6 +247,7 @@ const assertExpectedVersionMatchesCurrent = (
throw new ExpectedVersionConflictError(current, expected);
};

// eslint-disable-next-line @typescript-eslint/no-unused-vars
const convertToWebReadableStream = (
allStreamSubscription: AllStreamSubscription,
): ReadableStream<AllStreamResolvedEvent | GlobalStreamCaughtUp> => {
Expand Down Expand Up @@ -289,23 +286,22 @@ const convertToWebReadableStream = (
);
};

const streamEvents = (eventStore: EventStoreDBClient) => () => {
return restream<
AllStreamResolvedEvent | GlobalSubscriptionEvent,
| ReadEvent<Event, ReadEventMetadataWithGlobalPosition>
// eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents
| GlobalSubscriptionEvent
>(
(): ReadableStream<AllStreamResolvedEvent | GlobalSubscriptionEvent> =>
convertToWebReadableStream(
eventStore.subscribeToAll({
fromPosition: START,
filter: excludeSystemEvents(),
}),
),
(
resolvedEvent: AllStreamResolvedEvent | GlobalSubscriptionEvent,
): ReadEvent<Event, ReadEventMetadataWithGlobalPosition> =>
mapFromESDBEvent(resolvedEvent.event as JSONRecordedEvent<Event>),
);
};
// const streamEvents = (eventStore: EventStoreDBClient) => () => {
// return restream<
// AllStreamResolvedEvent | GlobalSubscriptionEvent,
// | ReadEvent<Event, ReadEventMetadataWithGlobalPosition>
// | GlobalSubscriptionEvent
// >(
// (): ReadableStream<AllStreamResolvedEvent | GlobalSubscriptionEvent> =>
// convertToWebReadableStream(
// eventStore.subscribeToAll({
// fromPosition: START,
// filter: excludeSystemEvents(),
// }),
// ),
// (
// resolvedEvent: AllStreamResolvedEvent | GlobalSubscriptionEvent,
// ): ReadEvent<Event, ReadEventMetadataWithGlobalPosition> =>
// mapFromESDBEvent(resolvedEvent.event as JSONRecordedEvent<Event>),
// );
// };
1 change: 0 additions & 1 deletion src/packages/emmett-fastify/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"version": "0.19.1",
"type": "module",
"description": "Emmett - Event Sourcing development made simple",
"type": "module",
"scripts": {
"build": "tsup",
"build:ts": "tsc",
Expand Down
Loading

0 comments on commit 2255e21

Please sign in to comment.