@nestjs-cqrs-eventsourcing/core
Version:
Event sourcing for nestjs CQRS
43 lines (42 loc) • 1.43 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Snapshot = void 0;
const debug_1 = __importDefault(require("debug"));
const debug = (0, debug_1.default)('eventstore:snapshot');
class Snapshot {
constructor(id, obj) {
if (!id) {
const errIdMsg = 'id not injected!';
debug(errIdMsg);
throw new Error(errIdMsg);
}
if (!obj) {
const errObjMsg = 'object not injected!';
debug(errObjMsg);
throw new Error(errObjMsg);
}
if (!obj.aggregateId) {
const errAggIdMsg = 'object.aggregateId not injected!';
debug(errAggIdMsg);
throw new Error(errAggIdMsg);
}
if (!obj.data) {
const errDataMsg = 'object.data not injected!';
debug(errDataMsg);
throw new Error(errDataMsg);
}
this.id = id;
this.streamId = obj.aggregateId;
this.aggregateId = obj.aggregateId;
this.aggregate = obj.aggregate || undefined;
this.context = obj.context || undefined;
this.timestamp = undefined;
this.revision = obj.revision;
this.version = obj.version;
this.data = obj.data;
}
}
exports.Snapshot = Snapshot;