@arque/core
Advanced tools
Comparing version 0.1.0-alpha.11 to 0.1.0-alpha.13
@@ -23,3 +23,2 @@ /// <reference types="node" /> | ||
private eventHandlers; | ||
private lastReloadTimestamp; | ||
constructor(eventStore: EventStore, commandHandlers: CommandHandler<TCommand, TEvent, TState>[], eventHandlers: EventHandler<TEvent, TState>[], _id: Buffer, _version: number, _state: TState, opts?: { | ||
@@ -26,0 +25,0 @@ readonly snapshotOpts?: SnapshotOpts<TState>; |
@@ -16,3 +16,2 @@ "use strict"; | ||
this.opts = opts; | ||
this.lastReloadTimestamp = null; | ||
this.mutex = new async_mutex_1.Mutex(); | ||
@@ -98,3 +97,2 @@ this.commandHandlers = new Map(commandHandlers.map((item) => [item.type, item])); | ||
async _reload(opts) { | ||
const timestamp = new Date(); | ||
if (!(opts === null || opts === void 0 ? void 0 : opts.ignoreSnapshot)) { | ||
@@ -120,3 +118,2 @@ const snapshot = await this.eventStore.getLatestSnapshot({ | ||
}); | ||
this.lastReloadTimestamp = timestamp; | ||
} | ||
@@ -148,6 +145,9 @@ async reload(opts) { | ||
}, command, ...command.args); | ||
const events = (_events instanceof Array ? _events : [_events]).map((item, index) => (Object.assign(Object.assign({}, item), { id: new event_id_1.EventId(), timestamp, aggregate: { | ||
id: this.id, | ||
version: this.version + index + 1, | ||
} }))); | ||
const events = (_events instanceof Array ? _events : [_events]).map((item, index) => { | ||
var _a; | ||
return (Object.assign(Object.assign({}, item), { id: new event_id_1.EventId(), timestamp, aggregate: { | ||
id: this.id, | ||
version: this.version + index + 1, | ||
}, meta: (_a = item.meta) !== null && _a !== void 0 ? _a : {} })); | ||
}); | ||
await this.eventStore.saveEvents({ | ||
@@ -162,2 +162,3 @@ aggregate: { | ||
body: item.body, | ||
meta: item.meta, | ||
})), | ||
@@ -164,0 +165,0 @@ timestamp, |
@@ -76,5 +76,5 @@ /// <reference types="node" /> | ||
timestamp: Date; | ||
events: Pick<Event, 'id' | 'type' | 'body'>[]; | ||
events: Pick<Event, 'id' | 'type' | 'body' | 'meta'>[]; | ||
}): Promise<void>; | ||
} | ||
export {}; |
@@ -39,8 +39,12 @@ "use strict"; | ||
streamAdapterSendEventsTransaction = await this.streamAdapter.sendEvents(streamAdapterSendEventsData); | ||
await storageAdapterSaveEventsTransaction.commit(); | ||
await streamAdapterSendEventsTransaction.commit(); | ||
await Promise.all([ | ||
storageAdapterSaveEventsTransaction.commit(), | ||
streamAdapterSendEventsTransaction.commit(), | ||
]); | ||
} | ||
catch (err) { | ||
await (storageAdapterSaveEventsTransaction === null || storageAdapterSaveEventsTransaction === void 0 ? void 0 : storageAdapterSaveEventsTransaction.abort()); | ||
await (streamAdapterSendEventsTransaction === null || streamAdapterSendEventsTransaction === void 0 ? void 0 : streamAdapterSendEventsTransaction.abort()); | ||
await Promise.all([ | ||
storageAdapterSaveEventsTransaction === null || storageAdapterSaveEventsTransaction === void 0 ? void 0 : storageAdapterSaveEventsTransaction.abort(), | ||
streamAdapterSendEventsTransaction === null || streamAdapterSendEventsTransaction === void 0 ? void 0 : streamAdapterSendEventsTransaction.abort(), | ||
]); | ||
throw err; | ||
@@ -47,0 +51,0 @@ } |
/// <reference types="node" /> | ||
import { EventId } from './event-id'; | ||
export type Event<TType extends number = number, TBody extends Record<string, unknown> = Record<string, unknown>> = { | ||
export type Event<TType extends number = number, TBody extends Record<string, unknown> = Record<string, unknown>, TMeta extends Record<string, unknown> = Record<string, unknown>> = { | ||
id: EventId; | ||
@@ -11,2 +11,3 @@ type: TType; | ||
body: TBody; | ||
meta: TMeta; | ||
timestamp: Date; | ||
@@ -28,3 +29,3 @@ }; | ||
}; | ||
export type GeneratedEvent<TEvent extends Event> = Pick<TEvent, 'type' | 'body'>; | ||
export type GeneratedEvent<TEvent extends Event> = Pick<TEvent, 'type' | 'body'> & Partial<Pick<TEvent, 'meta'>>; | ||
export type CommandHandler<TCommand extends Command, TEvent extends Event, TState> = { | ||
@@ -31,0 +32,0 @@ type: TCommand['type']; |
{ | ||
"name": "@arque/core", | ||
"version": "0.1.0-alpha.11", | ||
"version": "0.1.0-alpha.13", | ||
"description": "The Event Sourcing library.", | ||
"author": "Scale Technologies", | ||
"author": "ScaleForge", | ||
"homepage": "https://github.com/ScaleTechnologies/arque#README.md", | ||
@@ -33,3 +33,3 @@ "license": "MIT", | ||
}, | ||
"gitHead": "d1d3bf6dd528d86b4378e145361211befdcd5eb1" | ||
"gitHead": "a8dbb1dbd25b495e64c8dd65d52ae2a0229962ce" | ||
} |
@@ -1,11 +0,3 @@ | ||
# `core` | ||
# `@arque/core` | ||
> TODO: description | ||
## Usage | ||
``` | ||
const core = require('core'); | ||
// TODO: DEMONSTRATE API | ||
``` | ||
> `arque` code module. |
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
33328
546
4