cqrs-eventstore
Advanced tools
Comparing version 1.0.1 to 1.0.2
@@ -18,25 +18,26 @@ "use strict" | ||
const repository = new EventStore.Repository(UserInfoAggregate) | ||
let userInfoAggregate = UserInfoAggregate.create(1) | ||
let userInfoAggregate = new UserInfoAggregate(1); | ||
userInfoAggregate.initialize("Gennaro", "Del Sorbo", "Main Street", "09762847") | ||
repository.save(userInfoAggregate).then(() => { | ||
userInfoAggregate.updateMobile("333"); | ||
userInfoAggregate.updateMobile("334"); | ||
userInfoAggregate.updateMobile("335"); | ||
userInfoAggregate.updateAddress("12, Main St.") | ||
userInfoAggregate.updateAddress("15, Main St.") | ||
repository.save(userInfoAggregate).then(() => { | ||
console.log("all saved") | ||
userInfoAggregate.updateMobile("333"); | ||
userInfoAggregate.updateMobile("334"); | ||
userInfoAggregate.updateMobile("335"); | ||
userInfoAggregate.updateAddress("12, Main St.") | ||
userInfoAggregate.updateAddress("15, Main St.") | ||
repository.save(userInfoAggregate).then(() => { | ||
console.log("all saved") | ||
console.log("try a read") | ||
console.log("try a read") | ||
repository.read(1).then(userInfo => { | ||
console.log(userInfo.Mobile) | ||
console.log(userInfo.Address) | ||
}).catch(e => { | ||
console.log(e) | ||
}); | ||
}) | ||
}).catch(err => { | ||
console.log(err) | ||
repository.read(1).then(userInfo => { | ||
console.log(userInfo.Mobile) | ||
console.log(userInfo.Address) | ||
}).catch(e => { | ||
console.log(e) | ||
}); | ||
}) | ||
}).catch(err => { | ||
console.log(err) | ||
}) |
@@ -9,71 +9,70 @@ "use strict" | ||
function UserInfoObj() { | ||
this.name | ||
this.surname | ||
this.address | ||
this.mobile | ||
} | ||
function UserInfo(id) { | ||
let _userInfo | ||
class UserInfo extends NodeEventStore.Aggregate { | ||
constructor(id) { | ||
super(id) | ||
_userInfo = new UserInfoObj() | ||
function UserInfoObj() { | ||
this.name | ||
this.surname | ||
this.address | ||
this.mobile | ||
} | ||
static create(id) { | ||
return new UserInfo(id) | ||
} | ||
snapshot() { | ||
return clone(_userInfo) | ||
} | ||
applySnapshot(payload) { | ||
_userInfo = payload | ||
} | ||
//Queries | ||
get Mobile() { | ||
return _userInfo.mobile | ||
} | ||
get Address() { | ||
return _userInfo.address | ||
} | ||
let _userInfo | ||
//Mutators | ||
initialize(name, surname, address, mobile) { | ||
super.raiseEvent(new UserInfoCreated(name, surname, address, mobile)) | ||
class UserInfo extends NodeEventStore.Aggregate { | ||
constructor(id) { | ||
super(id) | ||
_userInfo = new UserInfoObj() | ||
} | ||
snapshot() { | ||
return clone(_userInfo) | ||
} | ||
applySnapshot(payload) { | ||
_userInfo = payload | ||
} | ||
//Queries | ||
get Mobile() { | ||
return _userInfo.mobile | ||
} | ||
get Address() { | ||
return _userInfo.address | ||
} | ||
//Mutators | ||
initialize(name, surname, address, mobile) { | ||
super.raiseEvent(new UserInfoCreated(name, surname, address, mobile)) | ||
} | ||
updateAddress(address) { | ||
super.raiseEvent(new AddressUpdated(address)) | ||
} | ||
updateMobile(mobile, hookFn) { | ||
super.raiseEvent(new MobileUpdated(mobile), hookFn) | ||
} | ||
//Apply | ||
UserInfoCreated(payload) { | ||
_userInfo.name = payload.name | ||
_userInfo.surname = payload.surname | ||
_userInfo.address = payload.address | ||
_userInfo.mobile = payload.mobile | ||
} | ||
AddressUpdated(payload) { | ||
_userInfo.address = payload.address | ||
} | ||
MobileUpdated(payload) { | ||
_userInfo.mobile = payload.mobile | ||
} | ||
} | ||
updateAddress(address) { | ||
super.raiseEvent(new AddressUpdated(address)) | ||
} | ||
updateMobile(mobile, hookFn) { | ||
super.raiseEvent(new MobileUpdated(mobile), hookFn) | ||
} | ||
//Apply | ||
UserInfoCreated(payload) { | ||
_userInfo.name = payload.name | ||
_userInfo.surname = payload.surname | ||
_userInfo.address = payload.address | ||
_userInfo.mobile = payload.mobile | ||
} | ||
AddressUpdated(payload) { | ||
_userInfo.address = payload.address | ||
} | ||
MobileUpdated(payload) { | ||
_userInfo.mobile = payload.mobile | ||
} | ||
return new UserInfo(id); | ||
} | ||
module.exports = { | ||
create: UserInfo.create | ||
} | ||
module.exports = UserInfo |
{ | ||
"name": "cqrs-eventstore", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "CQRS and Event Sourcing for Node.js 4+, supporting snapshots, built-in cache, hooks and payload compression", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
127
README.md
@@ -93,73 +93,72 @@ CQRS-EventStore | ||
//We are not exposing the UserInfo to the outside world, but we access to it through query. | ||
function UserInfoObj() { | ||
this.name | ||
this.surname | ||
this.address | ||
this.mobile | ||
} | ||
function UserInfo(id) { | ||
let _userInfo | ||
class UserInfo extends NodeEventStore.Aggregate { | ||
constructor(id) { | ||
super(id) | ||
_userInfo = new UserInfoObj() | ||
//We are not exposing the UserInfo to the outside world, but we access to it through query. | ||
function UserInfoObj() { | ||
this.name | ||
this.surname | ||
this.address | ||
this.mobile | ||
} | ||
static create(id) { | ||
return new UserInfo(id) | ||
} | ||
snapshot() { | ||
return clone(_userInfo) | ||
} | ||
applySnapshot(payload) { | ||
_userInfo = payload | ||
} | ||
//Queries | ||
get Mobile() { | ||
return _userInfo.mobile | ||
} | ||
get Address() { | ||
return _userInfo.address | ||
} | ||
let _userInfo | ||
//Commands | ||
initialize(name, surname, address, mobile) { | ||
super.raiseEvent(new UserInfoCreated(name, surname, address, mobile)) | ||
class UserInfo extends NodeEventStore.Aggregate { | ||
constructor(id) { | ||
super(id) | ||
_userInfo = new UserInfoObj() | ||
} | ||
snapshot() { | ||
return clone(_userInfo) | ||
} | ||
applySnapshot(payload) { | ||
_userInfo = payload | ||
} | ||
//Queries | ||
get Mobile() { | ||
return _userInfo.mobile | ||
} | ||
get Address() { | ||
return _userInfo.address | ||
} | ||
//Mutators | ||
initialize(name, surname, address, mobile) { | ||
super.raiseEvent(new UserInfoCreated(name, surname, address, mobile)) | ||
} | ||
updateAddress(address) { | ||
super.raiseEvent(new AddressUpdated(address)) | ||
} | ||
updateMobile(mobile, hookFn) { | ||
super.raiseEvent(new MobileUpdated(mobile), hookFn) | ||
} | ||
//Apply | ||
UserInfoCreated(payload) { | ||
_userInfo.name = payload.name | ||
_userInfo.surname = payload.surname | ||
_userInfo.address = payload.address | ||
_userInfo.mobile = payload.mobile | ||
} | ||
AddressUpdated(payload) { | ||
_userInfo.address = payload.address | ||
} | ||
MobileUpdated(payload) { | ||
_userInfo.mobile = payload.mobile | ||
} | ||
} | ||
updateAddress(address) { | ||
super.raiseEvent(new AddressUpdated(address)) | ||
} | ||
updateMobile(mobile, hookFn) { | ||
super.raiseEvent(new MobileUpdated(mobile), hookFn) | ||
} | ||
//Applies | ||
UserInfoCreated(payload) { | ||
_userInfo.name = payload.name | ||
_userInfo.surname = payload.surname | ||
_userInfo.address = payload.address | ||
_userInfo.mobile = payload.mobile | ||
} | ||
AddressUpdated(payload) { | ||
_userInfo.address = payload.address | ||
} | ||
MobileUpdated(payload) { | ||
_userInfo.mobile = payload.mobile | ||
} | ||
return new UserInfo(id) | ||
} | ||
module.exports = { | ||
create: UserInfo.create | ||
} | ||
module.exports = UserInfo | ||
``` | ||
@@ -302,3 +301,3 @@ | ||
const repository = new EventStore.Repository(UserInfoAggregate) | ||
let userInfoAggregate = UserInfoAggregate.create(1) | ||
let userInfoAggregate = new UserInfoAggregate(1) | ||
userInfoAggregate.initialize("Gennaro", "Del Sorbo", "Main Street", "09762847") | ||
@@ -305,0 +304,0 @@ |
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
26575
503
324