Skip to content

Commit

Permalink
🚨 fix linting issues
Browse files Browse the repository at this point in the history
  • Loading branch information
drieshooghe committed Jun 30, 2023
1 parent 951df47 commit bb37fa7
Show file tree
Hide file tree
Showing 12 changed files with 76 additions and 77 deletions.
4 changes: 2 additions & 2 deletions lib/constants.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
export const EVENT_SOURCING_OPTIONS = 'EventSourcingModuleOptions';

export enum StreamReadingDirection {
FORWARD,
BACKWARD,
FORWARD = 0,
BACKWARD = 1,
}

export const DEFAULT_BATCH_SIZE = 100;
2 changes: 0 additions & 2 deletions lib/event-sourcing.providers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ export const EventStoreProvider = {
const dynamoClient = new DynamoDBClient(options.eventStore.options);
return new DynamoDBEventStore(eventMap, dynamoClient);
}
case 'in-memory':
default:
return new InMemoryEventStore(eventMap);
}
Expand Down Expand Up @@ -74,7 +73,6 @@ export const SnapshotStoreProvider = {
const dynamoClient = new DynamoDBClient(options.snapshotStore.options);
return new DynamoDBSnapshotStore(dynamoClient);
}
case 'in-memory':
default:
return new InMemorySnapshotStore();
}
Expand Down
3 changes: 2 additions & 1 deletion lib/event-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,12 @@ export abstract class EventStore {
protected _publish: (envelope: EventEnvelope<IEvent>) => any;

constructor() {
// rome-ignore lint/correctness/noConstructorReturn:
return new Proxy(this, {
get(target, propKey) {
if (propKey === 'appendEvents') {
return async function (...args: unknown[]) {
let envelopes = await target[propKey].apply(this, args);
const envelopes = await target[propKey].apply(this, args);
for (const envelope of envelopes) {
await this._publish(envelope);
}
Expand Down
10 changes: 5 additions & 5 deletions lib/handlers.loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ import { EventSourcingModuleOptions } from './interfaces';
import { QueryBus } from './query-bus';

enum HandlerType {
COMMAND,
QUERY,
EVENT,
SERIALIZATION,
PUBLISHING,
COMMAND = 0,
QUERY = 1,
EVENT = 2,
SERIALIZATION = 3,
PUBLISHING = 4,
}

@Injectable()
Expand Down
16 changes: 8 additions & 8 deletions lib/integration/event-store/dynamodb.event-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ export class DynamoDBEventStore extends EventStore {
async *getEvents({ streamId }: EventStream, filter?: EventFilter): AsyncGenerator<IEvent[]> {
const collection = EventCollection.get(filter?.pool);

let fromVersion = filter?.fromVersion;
let direction = filter?.direction || StreamReadingDirection.FORWARD;
let limit = filter?.limit || Number.MAX_SAFE_INTEGER;
let batch = filter?.batch || DEFAULT_BATCH_SIZE;
const fromVersion = filter?.fromVersion;
const direction = filter?.direction || StreamReadingDirection.FORWARD;
const limit = filter?.limit || Number.MAX_SAFE_INTEGER;
const batch = filter?.batch || DEFAULT_BATCH_SIZE;

const KeyConditionExpression = ['streamId = :streamId'];
const ExpressionAttributeValues = {
Expand Down Expand Up @@ -181,10 +181,10 @@ export class DynamoDBEventStore extends EventStore {
async *getEnvelopes({ streamId }: EventStream, filter?: EventFilter): AsyncGenerator<EventEnvelope[]> {
const collection = EventCollection.get(filter?.pool);

let fromVersion = filter?.fromVersion;
let direction = filter?.direction || StreamReadingDirection.FORWARD;
let limit = filter?.limit || Number.MAX_SAFE_INTEGER;
let batch = filter?.batch || DEFAULT_BATCH_SIZE;
const fromVersion = filter?.fromVersion;
const direction = filter?.direction || StreamReadingDirection.FORWARD;
const limit = filter?.limit || Number.MAX_SAFE_INTEGER;
const batch = filter?.batch || DEFAULT_BATCH_SIZE;

const KeyConditionExpression = ['streamId = :streamId'];
const ExpressionAttributeValues = {
Expand Down
22 changes: 11 additions & 11 deletions lib/integration/event-store/in-memory.event-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ export class InMemoryEventStore extends EventStore {

async *getEvents({ streamId }: EventStream, filter?: EventFilter): AsyncGenerator<IEvent[]> {
let entities: InMemoryEventEntity[] = [];
let collection = EventCollection.get(filter?.pool);
const collection = EventCollection.get(filter?.pool);

let fromVersion = filter?.fromVersion;
let direction = filter?.direction || StreamReadingDirection.FORWARD;
let limit = filter?.limit || Number.MAX_SAFE_INTEGER;
let batch = filter?.batch || DEFAULT_BATCH_SIZE;
const fromVersion = filter?.fromVersion;
const direction = filter?.direction || StreamReadingDirection.FORWARD;
const limit = filter?.limit || Number.MAX_SAFE_INTEGER;
const batch = filter?.batch || DEFAULT_BATCH_SIZE;

entities = this.collections.get(collection).filter(({ streamId: entityStreamId }) => entityStreamId === streamId);

Expand All @@ -57,7 +57,7 @@ export class InMemoryEventStore extends EventStore {
const collection = EventCollection.get(pool);
const eventCollection = this.collections.get(collection) || [];

let entity = eventCollection.find(
const entity = eventCollection.find(
({ streamId: eventStreamId, version: aggregateVersion }) =>
eventStreamId === streamId && aggregateVersion === version,
);
Expand Down Expand Up @@ -97,10 +97,10 @@ export class InMemoryEventStore extends EventStore {
let entities: InMemoryEventEntity[] = [];
const collection = EventCollection.get(filter?.pool);

let fromVersion = filter?.fromVersion;
let direction = filter?.direction || StreamReadingDirection.FORWARD;
let limit = filter?.limit || Number.MAX_SAFE_INTEGER;
let batch = filter?.batch || DEFAULT_BATCH_SIZE;
const fromVersion = filter?.fromVersion;
const direction = filter?.direction || StreamReadingDirection.FORWARD;
const limit = filter?.limit || Number.MAX_SAFE_INTEGER;
const batch = filter?.batch || DEFAULT_BATCH_SIZE;

entities = this.collections.get(collection).filter(({ streamId: entityStreamId }) => entityStreamId === streamId);

Expand Down Expand Up @@ -135,7 +135,7 @@ export class InMemoryEventStore extends EventStore {
const collection = EventCollection.get(pool);
const eventCollection = this.collections.get(collection) || [];

let entity = eventCollection.find(
const entity = eventCollection.find(
({ streamId: eventStreamId, version: aggregateVersion }) =>
eventStreamId === streamId && aggregateVersion === version,
);
Expand Down
16 changes: 8 additions & 8 deletions lib/integration/event-store/mongodb.event-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ export class MongoDBEventStore extends EventStore {
async *getEvents({ streamId }: EventStream, filter?: EventFilter): AsyncGenerator<IEvent[]> {
const collection = EventCollection.get(filter?.pool);

let fromVersion = filter?.fromVersion;
let direction = filter?.direction || StreamReadingDirection.FORWARD;
let limit = filter?.limit || Number.MAX_SAFE_INTEGER;
let batch = filter?.batch || DEFAULT_BATCH_SIZE;
const fromVersion = filter?.fromVersion;
const direction = filter?.direction || StreamReadingDirection.FORWARD;
const limit = filter?.limit || Number.MAX_SAFE_INTEGER;
const batch = filter?.batch || DEFAULT_BATCH_SIZE;

const cursor = this.database
.collection<MongoEventEntity>(collection)
Expand Down Expand Up @@ -115,10 +115,10 @@ export class MongoDBEventStore extends EventStore {
async *getEnvelopes({ streamId }: EventStream, filter?: EventFilter): AsyncGenerator<EventEnvelope[]> {
const collection = EventCollection.get(filter?.pool);

let fromVersion = filter?.fromVersion;
let direction = filter?.direction || StreamReadingDirection.FORWARD;
let limit = filter?.limit || Number.MAX_SAFE_INTEGER;
let batch = filter?.batch || DEFAULT_BATCH_SIZE;
const fromVersion = filter?.fromVersion;
const direction = filter?.direction || StreamReadingDirection.FORWARD;
const limit = filter?.limit || Number.MAX_SAFE_INTEGER;
const batch = filter?.batch || DEFAULT_BATCH_SIZE;

const cursor = this.database
.collection<MongoEventEntity>(collection)
Expand Down
22 changes: 11 additions & 11 deletions lib/integration/snapshot-store/dynamodb.snapshot-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,10 @@ export class DynamoDBSnapshotStore extends SnapshotStore {
): AsyncGenerator<ISnapshot<A>[]> {
const collection = SnapshotCollection.get(filter?.pool);

let fromVersion = filter?.fromVersion;
let direction = filter?.direction || StreamReadingDirection.FORWARD;
let limit = filter?.limit || Number.MAX_SAFE_INTEGER;
let batch = filter?.batch || DEFAULT_BATCH_SIZE;
const fromVersion = filter?.fromVersion;
const direction = filter?.direction || StreamReadingDirection.FORWARD;
const limit = filter?.limit || Number.MAX_SAFE_INTEGER;
const batch = filter?.batch || DEFAULT_BATCH_SIZE;

const KeyConditionExpression = ['streamId = :streamId'];
const ExpressionAttributeValues = { ':streamId': { S: streamId } };
Expand Down Expand Up @@ -242,10 +242,10 @@ export class DynamoDBSnapshotStore extends SnapshotStore {
): AsyncGenerator<SnapshotEnvelope<A>[]> {
const collection = SnapshotCollection.get(filter?.pool);

let fromVersion = filter?.fromVersion;
let direction = filter?.direction || StreamReadingDirection.FORWARD;
let limit = filter?.limit || Number.MAX_SAFE_INTEGER;
let batch = filter?.batch || DEFAULT_BATCH_SIZE;
const fromVersion = filter?.fromVersion;
const direction = filter?.direction || StreamReadingDirection.FORWARD;
const limit = filter?.limit || Number.MAX_SAFE_INTEGER;
const batch = filter?.batch || DEFAULT_BATCH_SIZE;

const KeyConditionExpression = ['streamId = :streamId'];
const ExpressionAttributeValues = {
Expand Down Expand Up @@ -312,9 +312,9 @@ export class DynamoDBSnapshotStore extends SnapshotStore {
): AsyncGenerator<SnapshotEnvelope<A>[]> {
const collection = SnapshotCollection.get(pool);

let fromId = filter?.fromId;
let limit = filter?.limit || Number.MAX_SAFE_INTEGER;
let batch = filter?.batch || DEFAULT_BATCH_SIZE;
const fromId = filter?.fromId;
const limit = filter?.limit || Number.MAX_SAFE_INTEGER;
const batch = filter?.batch || DEFAULT_BATCH_SIZE;

const KeyConditionExpression = ['aggregateName = :aggregateName'];
const ExpressionAttributeValues = { ':aggregateName': { S: aggregateName } };
Expand Down
32 changes: 16 additions & 16 deletions lib/integration/snapshot-store/in-memory.snapshot-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ export class InMemorySnapshotStore extends SnapshotStore {
let entities: InMemorySnapshotEntity<any>[] = [];

const collection = SnapshotCollection.get(filter?.pool);
let fromVersion = filter?.fromVersion;
let direction = filter?.direction || StreamReadingDirection.FORWARD;
let limit = filter?.limit || Number.MAX_SAFE_INTEGER;
let batch = filter?.batch || DEFAULT_BATCH_SIZE;
const fromVersion = filter?.fromVersion;
const direction = filter?.direction || StreamReadingDirection.FORWARD;
const limit = filter?.limit || Number.MAX_SAFE_INTEGER;
const batch = filter?.batch || DEFAULT_BATCH_SIZE;

entities = this.collections.get(collection).filter(({ streamId: entityStreamId }) => entityStreamId === streamId);

Expand Down Expand Up @@ -102,7 +102,7 @@ export class InMemorySnapshotStore extends SnapshotStore {
const collection = SnapshotCollection.get(pool);
const snapshotCollection = this.collections.get(collection) || [];

let entity = this.getLastStreamEntity<A>(snapshotCollection, streamId);
const entity = this.getLastStreamEntity<A>(snapshotCollection, streamId);

if (entity) {
return entity.payload;
Expand All @@ -113,7 +113,7 @@ export class InMemorySnapshotStore extends SnapshotStore {
const collection = SnapshotCollection.get(pool);
const snapshotCollection = this.collections.get(collection) || [];

let entity = this.getLastStreamEntity<A>(snapshotCollection, streamId);
const entity = this.getLastStreamEntity<A>(snapshotCollection, streamId);

if (entity) {
return SnapshotEnvelope.from(entity.payload, {
Expand All @@ -132,10 +132,10 @@ export class InMemorySnapshotStore extends SnapshotStore {
let entities: InMemorySnapshotEntity<any>[] = [];

const collection = SnapshotCollection.get(filter?.pool);
let fromVersion = filter?.fromVersion;
let direction = filter?.direction || StreamReadingDirection.FORWARD;
let limit = filter?.limit || Number.MAX_SAFE_INTEGER;
let batch = filter?.batch || DEFAULT_BATCH_SIZE;
const fromVersion = filter?.fromVersion;
const direction = filter?.direction || StreamReadingDirection.FORWARD;
const limit = filter?.limit || Number.MAX_SAFE_INTEGER;
const batch = filter?.batch || DEFAULT_BATCH_SIZE;

entities = this.collections.get(collection).filter(({ streamId: entityStreamId }) => entityStreamId === streamId);

Expand Down Expand Up @@ -167,7 +167,7 @@ export class InMemorySnapshotStore extends SnapshotStore {
const collection = SnapshotCollection.get(pool);
const snapshotCollection = this.collections.get(collection) || [];

let entity = snapshotCollection.find(
const entity = snapshotCollection.find(
({ streamId: eventStreamId, version: aggregateVersion }) =>
eventStreamId === streamId && aggregateVersion === version,
);
Expand All @@ -192,16 +192,16 @@ export class InMemorySnapshotStore extends SnapshotStore {
let entities: InMemorySnapshotEntity<any>[] = [];

const collection = SnapshotCollection.get(pool);
let fromId = filter?.fromId;
let limit = filter?.limit || Number.MAX_SAFE_INTEGER;
let batch = filter?.batch || DEFAULT_BATCH_SIZE;
const fromId = filter?.fromId;
const limit = filter?.limit || Number.MAX_SAFE_INTEGER;
const batch = filter?.batch || DEFAULT_BATCH_SIZE;

entities = this.collections
.get(collection)
.filter(({ aggregateName: name, latest }) => name === aggregateName && latest)
.sort((envelopeA, envelopeB) => {
var textA = envelopeA.latest.toLowerCase();
var textB = envelopeB.latest.toLowerCase();
const textA = envelopeA.latest.toLowerCase();
const textB = envelopeB.latest.toLowerCase();
return textA < textB ? -1 : textA > textB ? 1 : 0;
})
.reverse();
Expand Down
22 changes: 11 additions & 11 deletions lib/integration/snapshot-store/mongodb.snapshot-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ export class MongoDBSnapshotStore extends SnapshotStore {
): AsyncGenerator<ISnapshot<A>[]> {
const collection = SnapshotCollection.get(filter?.pool);

let fromVersion = filter?.fromVersion;
let direction = filter?.direction || StreamReadingDirection.FORWARD;
let limit = filter?.limit || Number.MAX_SAFE_INTEGER;
let batch = filter?.batch || DEFAULT_BATCH_SIZE;
const fromVersion = filter?.fromVersion;
const direction = filter?.direction || StreamReadingDirection.FORWARD;
const limit = filter?.limit || Number.MAX_SAFE_INTEGER;
const batch = filter?.batch || DEFAULT_BATCH_SIZE;

const cursor = this.database
.collection<MongoSnapshotEntity<A>>(collection)
Expand Down Expand Up @@ -161,10 +161,10 @@ export class MongoDBSnapshotStore extends SnapshotStore {
): AsyncGenerator<SnapshotEnvelope<A>[]> {
const collection = SnapshotCollection.get(filter?.pool);

let fromVersion = filter?.fromVersion;
let direction = filter?.direction || StreamReadingDirection.FORWARD;
let limit = filter?.limit || Number.MAX_SAFE_INTEGER;
let batch = filter?.batch || DEFAULT_BATCH_SIZE;
const fromVersion = filter?.fromVersion;
const direction = filter?.direction || StreamReadingDirection.FORWARD;
const limit = filter?.limit || Number.MAX_SAFE_INTEGER;
const batch = filter?.batch || DEFAULT_BATCH_SIZE;

const cursor = this.database
.collection<MongoSnapshotEntity<A>>(collection)
Expand Down Expand Up @@ -228,9 +228,9 @@ export class MongoDBSnapshotStore extends SnapshotStore {
): AsyncGenerator<SnapshotEnvelope<A>[]> {
const collection = SnapshotCollection.get(pool);

let fromId = filter?.fromId;
let limit = filter?.limit || Number.MAX_SAFE_INTEGER;
let batch = filter?.batch || DEFAULT_BATCH_SIZE;
const fromId = filter?.fromId;
const limit = filter?.limit || Number.MAX_SAFE_INTEGER;
const batch = filter?.batch || DEFAULT_BATCH_SIZE;

const cursor = this.database
.collection<MongoSnapshotEntity<A>>(collection)
Expand Down
2 changes: 1 addition & 1 deletion lib/interfaces/events/event.interface.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export interface IEvent {}
export type IEvent = {};

export type IEventPayload<E extends IEvent> = Record<keyof E, any>;
2 changes: 1 addition & 1 deletion lib/models/aggregate-root.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const VERSION = Symbol();
const EVENTS = Symbol();

export abstract class AggregateRoot {
private [VERSION]: number = 0;
private [VERSION] = 0;
private readonly [EVENTS]: IEvent[] = [];

set version(version: number) {
Expand Down

0 comments on commit bb37fa7

Please sign in to comment.