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 e172275 commit 62081f2
Show file tree
Hide file tree
Showing 21 changed files with 142 additions and 150 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
31 changes: 28 additions & 3 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
4 changes: 1 addition & 3 deletions 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 Expand Up @@ -53,7 +52,6 @@
},
"peerDependencies": {
"@event-driven-io/emmett": "0.19.1",
"@eventstore/db-client": "^6.2.1",
"web-streams-polyfill": "^4.0.0"
"@eventstore/db-client": "^6.2.1"
}
}
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>),
// );
// };
3 changes: 1 addition & 2 deletions src/packages/emmett-expressjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
"express": "^4.19.2",
"express-async-errors": "^3.1.1",
"http-problem-details": "^0.1.5",
"supertest": "^7.0.0",
"web-streams-polyfill": "^4.0.0"
"supertest": "^7.0.0"
}
}
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
2 changes: 1 addition & 1 deletion src/packages/emmett-shims/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@event-driven-io/emmett-shims",
"version": "0.11.2",
"version": "0.19.1",
"type": "module",
"description": "Emmett - Event Sourcing development made simple",
"scripts": {
Expand Down
13 changes: 7 additions & 6 deletions src/packages/emmett-shims/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import streamsPolyfill from 'web-streams-polyfill';
import {
ReadableStream,
TransformStream,
WritableStream,
} from 'web-streams-polyfill';

const streamsPolyfill = { ReadableStream, WritableStream, TransformStream };

// https://github.com/jsdom/jsdom/issues/1537#issuecomment-229405327

Expand Down Expand Up @@ -40,18 +46,13 @@ let streams: typeof streamsPolyfill;

if (
globalThis &&
// @ts-expect-error global object check
globalThis.WritableStream &&
// @ts-expect-error global object check
globalThis.ReadableStream &&
// @ts-expect-error global object check
globalThis.TransformStream
) {
// @ts-expect-error global object check
streams = globalThis as typeof streamsPolyfill;
} else {
try {
// @ts-expect-error global object check
streams = (await import('node:stream/web')) as typeof streamsPolyfill;
} catch {
// Just falling back to the default polyfill
Expand Down
1 change: 0 additions & 1 deletion src/packages/emmett-testcontainers/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 - TestContainers - Event Sourcing development made simple",
"type": "module",
"scripts": {
"build": "tsup",
"build:ts": "tsc",
Expand Down
Loading

0 comments on commit 62081f2

Please sign in to comment.