Skip to content
Snippets Groups Projects
Commit 723712bb authored by Berend Sliedrecht's avatar Berend Sliedrecht
Browse files

feat(shared): base event setup


Signed-off-by: default avatarBerend Sliedrecht <berend@animo.id>
parent 69de826c
No related branches found
No related tags found
1 merge request!5feat(shared): base event setup
import { BaseEvent, EventDidcommConnectionsGetAll } from './events.js';
describe('check logger', () => {
it('should return module', () => {
jest.requireActual('./events');
});
it('should create a new base event', () => {
const baseEvent = new BaseEvent({ some: 'data' });
expect(typeof baseEvent.id).toStrictEqual('string');
expect(baseEvent.type).toStrictEqual('BaseEvent');
expect(baseEvent.timestamp).toBeInstanceOf(Date);
expect(baseEvent.data).toMatchObject({ some: 'data' });
});
it('should create a new connections get all event', () => {
const getAllConnectionsEvent = new EventDidcommConnectionsGetAll({
connections: [],
});
expect(typeof getAllConnectionsEvent.id).toStrictEqual('string');
expect(getAllConnectionsEvent.type).toStrictEqual(
'EventDidcommConnectionsGetAll',
);
expect(getAllConnectionsEvent.timestamp).toBeInstanceOf(Date);
expect(getAllConnectionsEvent.data).toMatchObject({ connections: [] });
});
});
import { utils, type ConnectionRecord } from '@aries-framework/core';
export class BaseEvent<
T extends Record<string, unknown> = Record<string, unknown>,
> {
public id: string;
public type: string;
public timestamp: Date;
public data: T;
public constructor(data: T) {
this.id = utils.uuid();
this.type = this.constructor.name;
this.timestamp = new Date();
this.data = data;
}
}
export class EventDidcommConnectionsGetAll extends BaseEvent<{
connections: Array<ConnectionRecord>;
}> {}
......@@ -3,3 +3,5 @@ export * from './health/health.controller.js';
export * from './logging/logger.js';
export * from './logging/logAxiosError.js';
export * from './events/events.js';
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment