@serialized/serialized-client
Advanced tools
Comparing version 3.10.1 to 3.11.0
@@ -15,2 +15,7 @@ import { BaseClient, DomainEvent, EventEnvelope } from './'; | ||
} | ||
export interface StoreEventsOptions { | ||
expectedVersion?: number; | ||
} | ||
export interface CheckAggregateExistsRequest extends AggregateRequest { | ||
} | ||
export interface DeleteAggregateOptions { | ||
@@ -37,8 +42,8 @@ deleteToken?: boolean; | ||
constructor(aggregateTypeConstructor: any, config: any); | ||
checkExists(aggregateId: string): Promise<any>; | ||
update(aggregateId: string, handler: (s: A) => DomainEvent[]): Promise<void>; | ||
create(aggregateId: string, handler: (s: A) => DomainEvent[]): Promise<void>; | ||
commit(aggregateId: string, handler: (s: A) => Commit): Promise<void>; | ||
appendOne(aggregateId: string, event: DomainEvent): Promise<void>; | ||
append(aggregateId: string, events: DomainEvent[]): Promise<void>; | ||
checkExists(request: CheckAggregateExistsRequest): Promise<any>; | ||
update(aggregateId: string, commandHandler: (s: A) => DomainEvent[]): Promise<void>; | ||
create(aggregateId: string, commandHandler: (s: A) => DomainEvent[]): Promise<void>; | ||
commit(aggregateId: string, commandHandler: (s: A) => Commit): Promise<void>; | ||
recordEvent(aggregateId: string, event: DomainEvent): Promise<void>; | ||
recordEvents(aggregateId: string, events: DomainEvent[]): Promise<void>; | ||
load<T extends A>(aggregateId: string): Promise<T>; | ||
@@ -45,0 +50,0 @@ private loadInternal; |
@@ -67,3 +67,3 @@ "use strict"; | ||
} | ||
AggregatesClient.prototype.checkExists = function (aggregateId) { | ||
AggregatesClient.prototype.checkExists = function (request) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
@@ -74,3 +74,3 @@ var url; | ||
case 0: | ||
url = AggregatesClient.aggregateUrlPath(this.aggregateType, aggregateId); | ||
url = AggregatesClient.aggregateUrlPath(this.aggregateType, request.aggregateId); | ||
return [4 /*yield*/, this.axiosClient.head(url, this.axiosConfig())]; | ||
@@ -82,3 +82,3 @@ case 1: return [2 /*return*/, (_a.sent()).data]; | ||
}; | ||
AggregatesClient.prototype.update = function (aggregateId, handler) { | ||
AggregatesClient.prototype.update = function (aggregateId, commandHandler) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
@@ -92,3 +92,3 @@ var response, currentVersion, domainEvents, eventsToSave; | ||
currentVersion = response.metadata.version; | ||
domainEvents = handler(response.aggregate); | ||
domainEvents = commandHandler(response.aggregate); | ||
eventsToSave = domainEvents.map(function (e) { return (_1.EventEnvelope.fromDomainEvent(e)); }); | ||
@@ -103,3 +103,3 @@ return [4 /*yield*/, this.saveInternal(aggregateId, { events: eventsToSave, expectedVersion: currentVersion })]; | ||
}; | ||
AggregatesClient.prototype.create = function (aggregateId, handler) { | ||
AggregatesClient.prototype.create = function (aggregateId, commandHandler) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
@@ -111,3 +111,3 @@ var aggregate, domainEvents, eventsToSave; | ||
aggregate = new this.aggregateTypeConstructor.prototype.constructor(this.initialState); | ||
domainEvents = handler(aggregate); | ||
domainEvents = commandHandler(aggregate); | ||
eventsToSave = domainEvents.map(function (e) { return (_1.EventEnvelope.fromDomainEvent(e)); }); | ||
@@ -122,3 +122,3 @@ return [4 /*yield*/, this.saveInternal(aggregateId, { events: eventsToSave, expectedVersion: 0 })]; | ||
}; | ||
AggregatesClient.prototype.commit = function (aggregateId, handler) { | ||
AggregatesClient.prototype.commit = function (aggregateId, commandHandler) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
@@ -130,3 +130,3 @@ var aggregate, commit; | ||
aggregate = new this.aggregateTypeConstructor.prototype.constructor(this.initialState); | ||
commit = handler(aggregate); | ||
commit = commandHandler(aggregate); | ||
return [4 /*yield*/, this.saveInternal(aggregateId, commit)]; | ||
@@ -140,7 +140,7 @@ case 1: | ||
}; | ||
AggregatesClient.prototype.appendOne = function (aggregateId, event) { | ||
AggregatesClient.prototype.recordEvent = function (aggregateId, event) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, this.append(aggregateId, [event])]; | ||
case 0: return [4 /*yield*/, this.recordEvents(aggregateId, [event])]; | ||
case 1: return [2 /*return*/, _a.sent()]; | ||
@@ -151,3 +151,3 @@ } | ||
}; | ||
AggregatesClient.prototype.append = function (aggregateId, events) { | ||
AggregatesClient.prototype.recordEvents = function (aggregateId, events) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
@@ -154,0 +154,0 @@ return __generator(this, function (_a) { |
@@ -1,8 +0,2 @@ | ||
export declare function Aggregate(aggregateType: string, eventHandlersType: any): <T extends new (...args: any[]) => {}>(constructor: T) => { | ||
new (...args: any[]): { | ||
aggregateType: string; | ||
initialState: any; | ||
eventHandlers: any; | ||
}; | ||
} & T; | ||
export declare function Aggregate(aggregateType: string, eventHandlersType: any): <T extends new (...args: any[]) => {}>(constructor: T) => T; | ||
export declare function EventHandler(type: any): (target: any, propertyKey: string, descriptor: PropertyDescriptor) => void; |
@@ -18,13 +18,20 @@ "use strict"; | ||
return function handlesEventsFor(constructor) { | ||
return /** @class */ (function (_super) { | ||
__extends(class_1, _super); | ||
function class_1() { | ||
var _this = _super !== null && _super.apply(this, arguments) || this; | ||
_this.aggregateType = aggregateType; | ||
_this.initialState = eventHandlersType.prototype.initialState; | ||
_this.eventHandlers = eventHandlersType.eventHandlers; | ||
return _this; | ||
} | ||
return class_1; | ||
}(constructor)); | ||
var proxy; | ||
try { | ||
proxy = new Function('constructor', 'aggregateType', 'eventHandlersType', "\n 'use strict';\n return class extends constructor {\n aggregateType = aggregateType;\n initialState = eventHandlersType.prototype.initialState;\n eventHandlers = eventHandlersType.eventHandlers;\n };\n ")(constructor, aggregateType, eventHandlersType); | ||
} | ||
catch (_a) { | ||
proxy = /** @class */ (function (_super) { | ||
__extends(class_1, _super); | ||
function class_1() { | ||
var _this = _super !== null && _super.apply(this, arguments) || this; | ||
_this.aggregateType = aggregateType; | ||
_this.initialState = eventHandlersType.prototype.initialState; | ||
_this.eventHandlers = eventHandlersType.eventHandlers; | ||
return _this; | ||
} | ||
return class_1; | ||
}(constructor)); | ||
} | ||
return proxy; | ||
}; | ||
@@ -31,0 +38,0 @@ } |
@@ -6,3 +6,3 @@ { | ||
"author": "Mattias Holmqvist", | ||
"version": "3.10.1", | ||
"version": "3.11.0", | ||
"main": "dist/index.js", | ||
@@ -33,5 +33,5 @@ "types": "dist/index.d.ts", | ||
"dependencies": { | ||
"@types/uuid": "^8.3.0", | ||
"axios": "^0.21.1", | ||
"uuid": "^8.3.0", | ||
"@types/uuid": "^8.3.0" | ||
"uuid": "^8.3.0" | ||
}, | ||
@@ -41,6 +41,7 @@ "devDependencies": { | ||
"axios-mock-adapter": "^1.17.0", | ||
"jest": "^25.1.0", | ||
"jest": "^25.5.4", | ||
"ts-jest": "^25.5.1", | ||
"typescript": "^3.8.3" | ||
"typescript": "^3.8.3", | ||
"node-notifier": ">=8.0.1" | ||
} | ||
} |
@@ -83,3 +83,3 @@ # Serialized Javascript & Typescript client | ||
@EventHandler(GameCreated) | ||
handleGameCreated(event: GameCreated, state: GameState): GameState { | ||
handleGameCreated(state: GameState, event: GameCreated): GameState { | ||
return {gameId: state.gameId, status: GameStatus.CREATED}; | ||
@@ -89,3 +89,3 @@ } | ||
@EventHandler(GameStarted) | ||
handleGameStarted(event: GameStarted, state: GameState): GameState { | ||
handleGameStarted(state: GameState, event: GameStarted): GameState { | ||
return {...state, status: GameStatus.STARTED}; | ||
@@ -92,0 +92,0 @@ } |
62669
1273
6