• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

snatalenko / node-cqrs / 10223224402

02 Aug 2024 11:19PM UTC coverage: 96.856%. First build
10223224402

Pull #21

github

snatalenko
Delete travis config
Pull Request #21: Migrate to TypeScript

570 of 859 branches covered (66.36%)

2282 of 2360 new or added lines in 28 files covered. (96.69%)

2403 of 2481 relevant lines covered (96.86%)

21.84 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

65.12
/src/Event.ts
1
import { IEvent } from "./interfaces";
4✔
2
import * as crypto from 'crypto';
4✔
3

4✔
4
const md5 = (data: object): string => crypto
4✔
NEW
5
        .createHash('md5')
×
NEW
6
        .update(JSON.stringify(data))
×
NEW
7
        .digest('hex')
×
8
        .replace(/==$/, '');
4✔
9

4✔
10
/**
4✔
11
 * Get text description of an event for logging purposes
4✔
12
 */
4✔
NEW
13
export function describe(event: IEvent): string {
×
NEW
14
        return `'${event.type}' of ${event.aggregateId} (v${event.aggregateVersion})`;
×
NEW
15
}
×
16

4✔
17
/**
4✔
18
 * Get text description of a set of events for logging purposes
4✔
19
 */
4✔
NEW
20
export function describeMultiple(events: ReadonlyArray<IEvent>): string {
×
NEW
21
        if (events.length === 1)
×
NEW
22
                return describe(events[0]);
×
NEW
23

×
NEW
24
        return `${events.length} events`;
×
NEW
25
}
×
26

4✔
27
/**
4✔
28
 * Validate event structure
4✔
29
 */
4✔
30
export function validate(event: IEvent) {
68✔
31
        if (typeof event !== 'object' || !event)
68✔
32
                throw new TypeError('event must be an Object');
68!
33
        if (typeof event.type !== 'string' || !event.type.length)
68✔
34
                throw new TypeError('event.type must be a non-empty String');
68!
35
        if (!event.aggregateId && !event.sagaId)
68✔
36
                throw new TypeError('either event.aggregateId or event.sagaId is required');
68✔
37
        if (event.sagaId && typeof event.sagaVersion === 'undefined')
68✔
38
                throw new TypeError('event.sagaVersion is required, when event.sagaId is defined');
68!
39
}
68✔
40

4✔
NEW
41
export function getId(event: IEvent): string {
×
NEW
42
        return event.id ?? md5(event);
×
NEW
43
}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc