@arque/core
Advanced tools
Comparing version 1.0.0-alpha.37 to 1.0.0-alpha.38
@@ -25,2 +25,3 @@ /// <reference types="node" /> | ||
restoreFromLatestSnapshot(): Promise<void>; | ||
private _fold; | ||
fold(): Promise<void>; | ||
@@ -27,0 +28,0 @@ createEvent<T extends Event = Event>(params: { |
@@ -32,3 +32,4 @@ "use strict"; | ||
} | ||
let promise = cache.get(id.toString('hex')); | ||
const key = id.toString('hex'); | ||
let promise = cache.get(key); | ||
if (!promise) { | ||
@@ -40,3 +41,3 @@ promise = (async () => { | ||
})(); | ||
cache.set(id.toString('hex'), promise); | ||
cache.set(key, promise); | ||
} | ||
@@ -103,25 +104,26 @@ const aggregate = await promise; | ||
} | ||
async _fold() { | ||
let state = ramda_1.default.clone(this.state); | ||
let { version } = this; | ||
let events; | ||
do { | ||
events = (await this.eventStore.retrieveAggregateEvents({ | ||
aggregate: this.id, | ||
first: this.options.batchSize, | ||
after: version, | ||
})); | ||
for (const event of events) { | ||
state = this.apply(state, event); | ||
version = event.aggregate.version; | ||
} | ||
} while (events.length === this.options.batchSize); | ||
this._version = version; | ||
this._state = Object.freeze(state); | ||
} | ||
async fold() { | ||
await this.queue.add(async () => { | ||
let state = ramda_1.default.clone(this.state); | ||
let { version } = this; | ||
let events; | ||
do { | ||
events = (await this.eventStore.retrieveAggregateEvents({ | ||
aggregate: this.id, | ||
first: this.options.batchSize, | ||
after: version, | ||
})); | ||
for (const event of events) { | ||
state = this.apply(state, event); | ||
version = event.aggregate.version; | ||
} | ||
} while (events.length === this.options.batchSize); | ||
this._version = version; | ||
this._state = Object.freeze(state); | ||
}); | ||
await this.queue.add(async () => this._fold()); | ||
} | ||
async createEvent(params) { | ||
await this.fold(); | ||
await this.queue.add(async () => { | ||
await this._fold(); | ||
const event = await this.eventStore.createEvent(Object.assign(Object.assign({}, params), { version: params.version || 1, aggregate: { | ||
@@ -132,3 +134,3 @@ id: this.id, | ||
} })); | ||
const state = this.apply(ramda_1.default.clone(this.state), event); | ||
const state = this.apply(this.state, event); | ||
await event.save(); | ||
@@ -135,0 +137,0 @@ this._version = event.aggregate.version; |
{ | ||
"name": "@arque/core", | ||
"version": "1.0.0-alpha.37", | ||
"version": "1.0.0-alpha.38", | ||
"description": "Core for `arque`", | ||
@@ -84,3 +84,3 @@ "keywords": [ | ||
}, | ||
"gitHead": "71107bf680f9b3fc0fe3c1728afcfd6de6c63e01" | ||
"gitHead": "64e7266284879425f2d59ac93750e33ddc8c4c24" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
157626
2182