@event-driven-io/emmett 0.43.0-beta.20 → 0.43.0-beta.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1743,14 +1743,16 @@ const DATABASE_REQUIRED_ERROR_MESSAGE = "Database is required in context for InM
1743
1743
  */
1744
1744
  const handleInMemoryProjections = async (options) => {
1745
1745
  const { projections, events, database, eventStore, observability } = options;
1746
- const eventTypes = events.map((e) => e.type);
1747
- const relevantProjections = projections.filter((p) => p.canHandle.some((type) => eventTypes.includes(type)));
1748
1746
  const { startScope } = ObservabilityScope(observability);
1749
- for (const projection of relevantProjections) await startScope("eventStore.inlineProjection", async (observabilityScope) => projection.handle(events, {
1750
- eventStore,
1751
- database,
1752
- observabilityScope
1753
- }));
1747
+ for (const projection of projections) {
1748
+ const filteredEvents = events.filter(({ type }) => projection.canHandle.includes(type));
1749
+ if (filteredEvents.length === 0) continue;
1750
+ await startScope("eventStore.inlineProjection", async (observabilityScope) => projection.handle(filteredEvents, {
1751
+ eventStore,
1752
+ database,
1753
+ observabilityScope
1754
+ }));
1755
+ }
1754
1756
  };
1755
1757
  /**
1756
1758
  * Creates an InMemory projection