Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(fix): don't import optional dependencies #49

Merged
merged 1 commit into from
Nov 8, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions lib/event-sourcing.providers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { DynamoDBClient } from '@aws-sdk/client-dynamodb';
import { Provider } from '@nestjs/common';
import { MongoClient } from 'mongodb';
import { EVENT_SOURCING_OPTIONS } from './constants';
import { EventMap } from './event-map';
import { EventStore } from './event-store';
Expand All @@ -23,13 +21,15 @@ export const EventStoreProvider = {
throw new MissingStoreConnectionOptionsException('eventStore', 'mongodb');
}
const { url, ...clientOptions } = options.eventStore.options;
const { MongoClient } = await import('mongodb');
const mongoClient = await new MongoClient(url, clientOptions).connect();
return new MongoDBEventStore(eventMap, mongoClient.db());
}
case 'dynamodb': {
if (!options.eventStore.options) {
throw new MissingStoreConnectionOptionsException('eventStore', ' dynamodb');
}
const { DynamoDBClient } = await import('@aws-sdk/client-dynamodb');
const dynamoClient = new DynamoDBClient(options.eventStore.options);
return new DynamoDBEventStore(eventMap, dynamoClient);
}
Expand All @@ -50,13 +50,15 @@ export const SnapshotStoreProvider = {
throw new MissingStoreConnectionOptionsException('snapshotStore', 'mongodb');
}
const { url, ...clientOptions } = options.snapshotStore.options;
const { MongoClient } = await import('mongodb');
const mongoClient = await new MongoClient(url, clientOptions).connect();
return new MongoDBSnapshotStore(mongoClient.db());
}
case 'dynamodb': {
if (!options.snapshotStore.options) {
throw new MissingStoreConnectionOptionsException('snapshotStore', 'dynamodb');
}
const { DynamoDBClient } = await import('@aws-sdk/client-dynamodb');
const dynamoClient = new DynamoDBClient(options.snapshotStore.options);
return new DynamoDBSnapshotStore(dynamoClient);
}
Expand Down