flexiblepersistence
Version:
A CQRS and Event Sourcing platform
82 lines • 2.27 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.DirectedEvent = void 0;
const __1 = require("..");
/* eslint-disable @typescript-eslint/no-explicit-any */
class DirectedEvent {
constructor(event) {
this.timestamp = event.timestamp || this.currentTimestamp();
this.content = event.content;
this.selection = event.selection;
this.single = event.single === undefined ? true : event.single;
this.id = event.id;
this.options = event.options;
this.correct =
event.operation !== __1.Operation.read ? event.correct || false : false;
this.replace =
event.operation === __1.Operation.create ||
event.operation === __1.Operation.update ||
event.operation === __1.Operation.other
? event.replace || false
: undefined;
}
// deepcode ignore no-any: any needed
setContent(content) {
this.content = content;
}
getTimestamp() {
return this.timestamp;
}
// deepcode ignore no-any: any needed
getContent() {
return this.content;
}
getSelection() {
return this.selection;
}
getOptions() {
return this.options;
}
isSingle() {
return this.single;
}
isCorrect() {
return this.correct;
}
isReplace() {
return this.replace;
}
getId() {
return this.id;
}
setId(id) {
this.id = id;
}
setOptions(options) {
this.options = options;
}
currentTimestamp() {
const date = new Date();
const dash = '-';
const colon = ':';
const dot = '.';
return (date.getFullYear() +
dash +
this.pad(date.getMonth() + 1) +
dash +
this.pad(date.getDate()) +
' ' +
this.pad(date.getHours()) +
colon +
this.pad(date.getMinutes()) +
colon +
this.pad(date.getSeconds()) +
dot +
this.pad(date.getMilliseconds()));
}
pad(n) {
return n < 10 ? '0' + n : n;
}
}
exports.DirectedEvent = DirectedEvent;
//# sourceMappingURL=directedEvent.js.map