Fix up hooked service

This commit is contained in:
Tobe O 2019-04-25 22:24:15 -04:00
parent 3202329490
commit 0420046d7e
3 changed files with 36 additions and 26 deletions

View file

@ -1,3 +1,7 @@
# 2.0.0-rc.9
* Fix some bugs in the `HookedService` implementation that skipped
the outputs of `before` events.
# 2.0.0-rc.8 # 2.0.0-rc.8
* Fix `MapService` flaw where clients could remove all records, even if `allowRemoveAll` were `false`. * Fix `MapService` flaw where clients could remove all records, even if `allowRemoveAll` were `false`.

View file

@ -276,7 +276,7 @@ class HookedService<Id, Data, T extends Service<Id, Data>>
params: params)) params: params))
.then((before) { .then((before) {
if (before._canceled) { if (before._canceled) {
return beforeIndexed return afterIndexed
._emit(new HookedServiceEvent(true, _getRequest(_params), ._emit(new HookedServiceEvent(true, _getRequest(_params),
_getResponse(_params), inner, HookedServiceEvent.indexed, _getResponse(_params), inner, HookedServiceEvent.indexed,
params: params, result: before.result)) params: params, result: before.result))
@ -302,7 +302,7 @@ class HookedService<Id, Data, T extends Service<Id, Data>>
id: id, params: params)) id: id, params: params))
.then((before) { .then((before) {
if (before._canceled) { if (before._canceled) {
return beforeRead return afterRead
._emit(new HookedServiceEvent(true, _getRequest(_params), ._emit(new HookedServiceEvent(true, _getRequest(_params),
_getResponse(_params), inner, HookedServiceEvent.read, _getResponse(_params), inner, HookedServiceEvent.read,
id: id, params: params, result: before.result)) id: id, params: params, result: before.result))
@ -328,18 +328,18 @@ class HookedService<Id, Data, T extends Service<Id, Data>>
data: data, params: params)) data: data, params: params))
.then((before) { .then((before) {
if (before._canceled) { if (before._canceled) {
return beforeCreated
._emit(new HookedServiceEvent(true, _getRequest(_params),
_getResponse(_params), inner, HookedServiceEvent.created,
data: data, params: params, result: before.result))
.then((after) => after.result as Data);
}
return inner.create(data, params).then((result) {
return afterCreated return afterCreated
._emit(new HookedServiceEvent(true, _getRequest(_params), ._emit(new HookedServiceEvent(true, _getRequest(_params),
_getResponse(_params), inner, HookedServiceEvent.created, _getResponse(_params), inner, HookedServiceEvent.created,
data: data, params: params, result: result)) data: before.data, params: params, result: before.result))
.then((after) => after.result as Data);
}
return inner.create(before.data, params).then((result) {
return afterCreated
._emit(new HookedServiceEvent(true, _getRequest(_params),
_getResponse(_params), inner, HookedServiceEvent.created,
data: before.data, params: params, result: result))
.then((after) => after.result as Data); .then((after) => after.result as Data);
}); });
}); });
@ -354,18 +354,21 @@ class HookedService<Id, Data, T extends Service<Id, Data>>
id: id, data: data, params: params)) id: id, data: data, params: params))
.then((before) { .then((before) {
if (before._canceled) { if (before._canceled) {
return beforeModified return afterModified
._emit(new HookedServiceEvent(true, _getRequest(_params), ._emit(new HookedServiceEvent(true, _getRequest(_params),
_getResponse(_params), inner, HookedServiceEvent.modified, _getResponse(_params), inner, HookedServiceEvent.modified,
id: id, data: data, params: params, result: before.result)) id: id,
data: before.data,
params: params,
result: before.result))
.then((after) => after.result as Data); .then((after) => after.result as Data);
} }
return inner.modify(id, data, params).then((result) { return inner.modify(id, before.data, params).then((result) {
return afterModified return afterModified
._emit(new HookedServiceEvent(true, _getRequest(_params), ._emit(new HookedServiceEvent(true, _getRequest(_params),
_getResponse(_params), inner, HookedServiceEvent.created, _getResponse(_params), inner, HookedServiceEvent.created,
id: id, data: data, params: params, result: result)) id: id, data: before.data, params: params, result: result))
.then((after) => after.result as Data); .then((after) => after.result as Data);
}); });
}); });
@ -380,18 +383,21 @@ class HookedService<Id, Data, T extends Service<Id, Data>>
id: id, data: data, params: params)) id: id, data: data, params: params))
.then((before) { .then((before) {
if (before._canceled) { if (before._canceled) {
return beforeUpdated
._emit(new HookedServiceEvent(true, _getRequest(_params),
_getResponse(_params), inner, HookedServiceEvent.updated,
id: id, data: data, params: params, result: before.result))
.then((after) => after.result as Data);
}
return inner.update(id, data, params).then((result) {
return afterUpdated return afterUpdated
._emit(new HookedServiceEvent(true, _getRequest(_params), ._emit(new HookedServiceEvent(true, _getRequest(_params),
_getResponse(_params), inner, HookedServiceEvent.updated, _getResponse(_params), inner, HookedServiceEvent.updated,
id: id, data: data, params: params, result: result)) id: id,
data: before.data,
params: params,
result: before.result))
.then((after) => after.result as Data);
}
return inner.update(id, before.data, params).then((result) {
return afterUpdated
._emit(new HookedServiceEvent(true, _getRequest(_params),
_getResponse(_params), inner, HookedServiceEvent.updated,
id: id, data: before.data, params: params, result: result))
.then((after) => after.result as Data); .then((after) => after.result as Data);
}); });
}); });
@ -406,7 +412,7 @@ class HookedService<Id, Data, T extends Service<Id, Data>>
id: id, params: params)) id: id, params: params))
.then((before) { .then((before) {
if (before._canceled) { if (before._canceled) {
return beforeRemoved return afterRemoved
._emit(new HookedServiceEvent(true, _getRequest(_params), ._emit(new HookedServiceEvent(true, _getRequest(_params),
_getResponse(_params), inner, HookedServiceEvent.removed, _getResponse(_params), inner, HookedServiceEvent.removed,
id: id, params: params, result: before.result)) id: id, params: params, result: before.result))

View file

@ -1,5 +1,5 @@
name: angel_framework name: angel_framework
version: 2.0.0-rc.8 version: 2.0.0-rc.9
description: A high-powered HTTP server with dependency injection, routing and much more. description: A high-powered HTTP server with dependency injection, routing and much more.
author: Tobe O <thosakwe@gmail.com> author: Tobe O <thosakwe@gmail.com>
homepage: https://github.com/angel-dart/angel_framework homepage: https://github.com/angel-dart/angel_framework