Added generic to Routable.use

This commit is contained in:
Tobe O 2018-09-11 16:25:07 -04:00
parent 20c6aedaa3
commit 7e2afed853
9 changed files with 198 additions and 187 deletions

View file

@ -2,7 +2,12 @@
<project version="4">
<component name="ChangeListManager">
<list default="true" id="7b89ff1e-1260-4dcf-9c3d-345de0471ea1" name="Default" comment="">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/CHANGELOG.md" beforeDir="false" afterPath="$PROJECT_DIR$/CHANGELOG.md" afterDir="false" />
<change beforePath="$PROJECT_DIR$/lib/src/core/anonymous_service.dart" beforeDir="false" afterPath="$PROJECT_DIR$/lib/src/core/anonymous_service.dart" afterDir="false" />
<change beforePath="$PROJECT_DIR$/lib/src/core/hooked_service.dart" beforeDir="false" afterPath="$PROJECT_DIR$/lib/src/core/hooked_service.dart" afterDir="false" />
<change beforePath="$PROJECT_DIR$/lib/src/core/map_service.dart" beforeDir="false" afterPath="$PROJECT_DIR$/lib/src/core/map_service.dart" afterDir="false" />
<change beforePath="$PROJECT_DIR$/lib/src/core/request_context.dart" beforeDir="false" afterPath="$PROJECT_DIR$/lib/src/core/request_context.dart" afterDir="false" />
<change beforePath="$PROJECT_DIR$/lib/src/core/service.dart" beforeDir="false" afterPath="$PROJECT_DIR$/lib/src/core/service.dart" afterDir="false" />
</list>
<ignored path="$PROJECT_DIR$/.tmp/" />
<ignored path="$PROJECT_DIR$/temp/" />
@ -25,27 +30,57 @@
</component>
<component name="FileEditorManager">
<leaf SIDE_TABS_SIZE_LIMIT_KEY="300">
<file leaf-file-name="README.md" pinned="false" current-in-tab="true">
<file leaf-file-name="README.md" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/README.md">
<provider selected="true" editor-type-id="split-provider[text-editor;markdown-preview-editor]">
<state split_layout="SPLIT">
<first_editor relative-caret-position="187">
<first_editor relative-caret-position="124">
<caret line="20" column="49" selection-start-line="20" selection-start-column="49" selection-end-line="20" selection-end-column="49" />
<folding>
<element signature="e#0#54#0" expanded="true" />
</folding>
</first_editor>
<second_editor />
</state>
</provider>
</entry>
</file>
<file leaf-file-name="CHANGELOG.md" pinned="false" current-in-tab="false">
<file leaf-file-name="hooked_service.dart" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/lib/src/core/hooked_service.dart">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="181">
<caret line="60" column="20" lean-forward="true" selection-start-line="60" selection-start-column="20" selection-end-line="60" selection-end-column="20" />
</state>
</provider>
</entry>
</file>
<file leaf-file-name="service.dart" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/lib/src/core/service.dart">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="85">
<caret line="79" column="33" selection-start-line="79" selection-start-column="33" selection-end-line="79" selection-end-column="33" />
<folding>
<element signature="e#39#59#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
</file>
<file leaf-file-name="request_context.dart" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/lib/src/core/request_context.dart">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="149">
<caret line="29" column="28" selection-start-line="29" selection-start-column="28" selection-end-line="29" selection-end-column="28" />
<folding>
<element signature="e#47#67#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
</file>
<file leaf-file-name="CHANGELOG.md" pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/CHANGELOG.md">
<provider selected="true" editor-type-id="split-provider[text-editor;markdown-preview-editor]">
<state split_layout="SPLIT">
<first_editor relative-caret-position="96">
<caret line="6" column="69" selection-start-line="6" selection-start-column="69" selection-end-line="6" selection-end-column="69" />
<first_editor relative-caret-position="32">
<caret line="2" column="95" selection-start-line="2" selection-start-column="95" selection-end-line="2" selection-end-column="95" />
</first_editor>
<second_editor />
</state>
@ -64,7 +99,6 @@
</component>
<component name="FindInProjectRecents">
<findStrings>
<find>sto</find>
<find>sopw</find>
<find>stopw</find>
<find>release</find>
@ -94,6 +128,7 @@
<find>Middleware</find>
<find>/meta</find>
<find>complet</find>
<find>parseI</find>
</findStrings>
<replaceStrings>
<replace>FutureOr</replace>
@ -150,9 +185,7 @@
<option name="CHANGED_PATHS">
<list>
<option value="$PROJECT_DIR$/test/hm.dart" />
<option value="$PROJECT_DIR$/lib/src/core/anonymous_service.dart" />
<option value="$PROJECT_DIR$/test/find_one_test.dart" />
<option value="$PROJECT_DIR$/lib/src/core/map_service.dart" />
<option value="$PROJECT_DIR$/test/extension_test.dart" />
<option value="$PROJECT_DIR$/test/accepts_test.dart" />
<option value="$PROJECT_DIR$/example/templating.dart" />
@ -174,18 +207,15 @@
<option value="$PROJECT_DIR$/lib/src/http/http_request_context.dart" />
<option value="$PROJECT_DIR$/example/handle_error.dart" />
<option value="$PROJECT_DIR$/example/json.dart" />
<option value="$PROJECT_DIR$/lib/src/core/hooked_service.dart" />
<option value="$PROJECT_DIR$/test/hooked_test.dart" />
<option value="$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/angel_container-1.0.0-alpha.3/lib/src/mirrors/reflector.dart" />
<option value="$PROJECT_DIR$/lib/src/http/controller.dart" />
<option value="$PROJECT_DIR$/lib/src/core/request_context.dart" />
<option value="$PROJECT_DIR$/lib/src/core/injection.dart" />
<option value="$PROJECT_DIR$/example/main.dart" />
<option value="$PROJECT_DIR$/test/view_generator_test.dart" />
<option value="$PROJECT_DIR$/test/common.dart" />
<option value="$PROJECT_DIR$/test/server_test.dart" />
<option value="$PROJECT_DIR$/test/parameter_meta_test.dart" />
<option value="$PROJECT_DIR$/lib/src/core/service.dart" />
<option value="$PROJECT_DIR$/test/serialize_test.dart" />
<option value="$PROJECT_DIR$/lib/src/core/routable.dart" />
<option value="$PROJECT_DIR$/test/precontained_test.dart" />
@ -199,6 +229,11 @@
<option value="$PROJECT_DIR$/test/streaming_test.dart" />
<option value="$PROJECT_DIR$/README.md" />
<option value="$PROJECT_DIR$/pubspec.yaml" />
<option value="$PROJECT_DIR$/lib/src/core/request_context.dart" />
<option value="$PROJECT_DIR$/lib/src/core/anonymous_service.dart" />
<option value="$PROJECT_DIR$/lib/src/core/hooked_service.dart" />
<option value="$PROJECT_DIR$/lib/src/core/service.dart" />
<option value="$PROJECT_DIR$/lib/src/core/map_service.dart" />
<option value="$PROJECT_DIR$/CHANGELOG.md" />
</list>
</option>
@ -232,7 +267,6 @@
<foldersAlwaysOnTop value="true" />
</navigator>
<panes>
<pane id="PackagesPane" />
<pane id="Scope">
<subPane subId="Project Files">
<expand>
@ -256,6 +290,13 @@
<item name="lib" type="cbb8eebc:String" user="lib" />
<item name="src" type="cbb8eebc:String" user="src" />
</path>
<path>
<item name="Root" type="cbb8eebc:String" user="Root" />
<item name="framework" type="cbb8eebc:String" user="framework" />
<item name="lib" type="cbb8eebc:String" user="lib" />
<item name="src" type="cbb8eebc:String" user="src" />
<item name="core" type="cbb8eebc:String" user="core" />
</path>
<path>
<item name="Root" type="cbb8eebc:String" user="Root" />
<item name="framework" type="cbb8eebc:String" user="framework" />
@ -272,6 +313,7 @@
<select />
</subPane>
</pane>
<pane id="PackagesPane" />
<pane id="ProjectPane" />
<pane id="AndroidView" />
</panes>
@ -465,6 +507,7 @@
<envs />
</configuration>
<list>
<item itemvalue="Dart Command Line App.All Tests (PRODUCTION)" />
<item itemvalue="Dart Command Line App.performance::hello (DEV)" />
<item itemvalue="Dart Command Line App.performance::hello (PRODUCTION)" />
<item itemvalue="Dart Command Line App.All Tests (for coverage)" />
@ -619,13 +662,7 @@
<workItem from="1534793956753" duration="15012000" />
<workItem from="1534863259966" duration="198000" />
<workItem from="1534873119036" duration="4624000" />
</task>
<task id="LOCAL-00114" summary="Remove traces of json_god">
<created>1534732268467</created>
<option name="number" value="00114" />
<option name="presentableId" value="LOCAL-00114" />
<option name="project" value="LOCAL" />
<updated>1534732268467</updated>
<workItem from="1536696642254" duration="760000" />
</task>
<task id="LOCAL-00115" summary="Remove lib/hooks.dart">
<created>1534732365272</created>
@ -963,7 +1000,14 @@
<option name="project" value="LOCAL" />
<updated>1534877529522</updated>
</task>
<option name="localTasksCounter" value="163" />
<task id="LOCAL-00163" summary="Add &lt;Id, Data&gt;">
<created>1536696871863</created>
<option name="number" value="00163" />
<option name="presentableId" value="LOCAL-00163" />
<option name="project" value="LOCAL" />
<updated>1536696871864</updated>
</task>
<option name="localTasksCounter" value="164" />
<servers />
</component>
<component name="TestHistory">
@ -999,7 +1043,7 @@
</history-entry>
</component>
<component name="TimeTrackingManager">
<option name="totallyTimeSpent" value="192041000" />
<option name="totallyTimeSpent" value="192801000" />
</component>
<component name="TodoView">
<todo-panel id="selected-file">
@ -1030,15 +1074,13 @@
<window_info id="UI Designer" order="2" />
<window_info anchor="bottom" id="Debug" order="3" weight="0.39857143" />
<window_info anchor="bottom" id="TODO" order="6" weight="0.32714286" />
<window_info anchor="bottom" id="Messages" order="7" weight="0.33478895" />
<window_info anchor="right" id="Palette&#9;" order="3" />
<window_info id="Image Layers" order="2" />
<window_info anchor="right" id="Capture Analysis" order="3" />
<window_info anchor="bottom" id="Version Control" order="7" weight="0.32905984" />
<window_info anchor="bottom" id="Run" order="2" sideWeight="0.4964476" weight="0.3973799" />
<window_info anchor="bottom" id="Version Control" order="7" weight="0.32905984" />
<window_info anchor="bottom" id="Terminal" order="7" weight="0.44978166" />
<window_info content_ui="combo" id="Project" order="0" weight="0.28615385" />
<window_info anchor="bottom" id="Find" order="1" weight="0.32905984" />
<window_info anchor="right" id="SciView" order="4" />
<window_info anchor="right" id="Theme Preview" order="3" />
<window_info id="Favorites" order="3" side_tool="true" />
@ -1049,7 +1091,9 @@
<window_info anchor="bottom" id="Cvs" order="4" weight="0.25" />
<window_info anchor="right" content_ui="combo" id="Hierarchy" order="2" weight="0.25" />
<window_info id="DB Browser" order="2" weight="0.32998413" />
<window_info anchor="bottom" id="Find" order="1" weight="0.32905984" />
<window_info anchor="right" id="Commander" internal_type="SLIDING" order="0" type="SLIDING" weight="0.4" />
<window_info anchor="bottom" id="Messages" order="7" weight="0.33478895" />
<window_info anchor="bottom" id="Message" order="0" />
<window_info anchor="right" id="Data View" order="4" />
</layout>
@ -1062,7 +1106,6 @@
</component>
<component name="VcsManagerConfiguration">
<option name="CHECK_CODE_SMELLS_BEFORE_PROJECT_COMMIT" value="false" />
<MESSAGE value="Update query parsing" />
<MESSAGE value="Update CHANGELOG" />
<MESSAGE value="Remove req.injections" />
<MESSAGE value="Remove Angel.inject" />
@ -1087,7 +1130,8 @@
<MESSAGE value="dart:mirrors is completely gone from Angel" />
<MESSAGE value="All tests pass" />
<MESSAGE value="CHANGELOG + bump to 2.0.0-alpha.1" />
<option name="LAST_COMMIT_MESSAGE" value="CHANGELOG + bump to 2.0.0-alpha.1" />
<MESSAGE value="Add &lt;Id, Data&gt;" />
<option name="LAST_COMMIT_MESSAGE" value="Add &lt;Id, Data&gt;" />
</component>
<component name="XDebuggerManager">
<breakpoint-manager>
@ -1095,20 +1139,6 @@
</breakpoint-manager>
</component>
<component name="editorHistoryManager">
<entry file="file://$PROJECT_DIR$/example/handle_error.dart">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="144">
<caret line="13" column="21" lean-forward="true" selection-start-line="13" selection-start-column="21" selection-end-line="13" selection-end-column="21" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/example/view.dart">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="48">
<caret line="3" column="14" lean-forward="true" selection-start-line="3" selection-start-column="14" selection-end-line="3" selection-end-column="14" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/performance/hello/angel.md">
<provider selected="true" editor-type-id="split-provider[text-editor;markdown-preview-editor]">
<state split_layout="SPLIT">
@ -1215,23 +1245,10 @@
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/lib/src/core/request_context.dart">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="1152">
<caret line="72" column="30" selection-start-line="72" selection-start-column="30" selection-end-line="72" selection-end-column="30" />
<folding>
<element signature="e#47#67#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/test/accepts_test.dart">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="150">
<caret line="41" column="67" lean-forward="true" selection-start-line="41" selection-start-column="67" selection-end-line="41" selection-end-column="67" />
<folding>
<element signature="e#0#20#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
@ -1239,28 +1256,18 @@
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="256">
<caret line="16" column="33" lean-forward="true" selection-start-line="16" selection-start-column="33" selection-end-line="16" selection-end-column="33" />
<folding>
<element signature="e#0#20#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/test/exception_test.dart">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="-602">
<folding>
<element signature="e#0#54#0" expanded="true" />
</folding>
</state>
<state relative-caret-position="-602" />
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/test/find_one_test.dart">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="192">
<caret line="12" lean-forward="true" selection-start-line="12" selection-end-line="12" />
<folding>
<element signature="e#0#54#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
@ -1268,20 +1275,11 @@
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="239">
<caret line="15" column="62" lean-forward="true" selection-start-line="15" selection-start-column="62" selection-end-line="15" selection-end-column="62" />
<folding>
<element signature="e#0#17#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/test/view_generator_test.dart">
<provider selected="true" editor-type-id="text-editor">
<state>
<folding>
<element signature="e#1#55#0" expanded="true" />
</folding>
</state>
</provider>
<provider selected="true" editor-type-id="text-editor" />
</entry>
<entry file="file:///usr/local/Cellar/dart/2.0.0/libexec/lib/_http/http.dart">
<provider selected="true" editor-type-id="text-editor">
@ -1321,16 +1319,6 @@
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/lib/src/core/service.dart">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="114">
<caret line="35" column="53" selection-start-line="35" selection-start-column="53" selection-end-line="35" selection-end-column="53" />
<folding>
<element signature="e#39#59#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/test/serialize_test.dart">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="134">
@ -1380,20 +1368,10 @@
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/lib/src/core/hooked_service.dart">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="30">
<caret line="89" column="23" selection-start-line="89" selection-start-column="23" selection-end-line="89" selection-end-column="23" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/lib/src/core/response_context.dart">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="186">
<caret line="309" column="12" selection-start-line="309" selection-start-column="12" selection-end-line="309" selection-end-column="12" />
<folding>
<element signature="e#48#68#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
@ -1415,9 +1393,6 @@
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="129">
<caret line="249" column="26" selection-start-line="249" selection-start-column="26" selection-end-line="249" selection-end-column="26" />
<folding>
<element signature="e#38#58#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
@ -1439,9 +1414,6 @@
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="368">
<caret line="23" column="19" lean-forward="true" selection-start-line="23" selection-start-column="19" selection-end-line="23" selection-end-column="19" />
<folding>
<element signature="e#0#46#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
@ -1449,9 +1421,6 @@
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="126">
<caret line="328" column="36" lean-forward="true" selection-start-line="328" selection-start-column="36" selection-end-line="328" selection-end-column="36" />
<folding>
<element signature="e#0#20#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
@ -1466,9 +1435,6 @@
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="172">
<caret line="35" column="13" selection-start-line="35" selection-start-column="13" selection-end-line="35" selection-end-column="13" />
<folding>
<element signature="e#0#20#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
@ -1476,30 +1442,68 @@
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="129">
<caret line="154" column="49" selection-start-line="154" selection-start-column="49" selection-end-line="154" selection-end-column="49" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/README.md">
<provider selected="true" editor-type-id="split-provider[text-editor;markdown-preview-editor]">
<state split_layout="SPLIT">
<first_editor relative-caret-position="124">
<caret line="20" column="49" selection-start-line="20" selection-start-column="49" selection-end-line="20" selection-end-column="49" />
</first_editor>
<second_editor />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/lib/src/core/anonymous_service.dart">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="112">
<caret line="9" column="63" lean-forward="true" selection-start-line="9" selection-start-column="63" selection-end-line="9" selection-end-column="63" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/lib/src/core/request_context.dart">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="149">
<caret line="29" column="28" selection-start-line="29" selection-start-column="28" selection-end-line="29" selection-end-column="28" />
<folding>
<element signature="e#47#67#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/lib/src/core/hooked_service.dart">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="181">
<caret line="60" column="20" lean-forward="true" selection-start-line="60" selection-start-column="20" selection-end-line="60" selection-end-column="20" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/lib/src/core/map_service.dart">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="64">
<caret line="4" column="22" lean-forward="true" selection-start-line="4" selection-start-column="22" selection-end-line="4" selection-end-column="22" />
<folding>
<element signature="e#0#20#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/lib/src/core/service.dart">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="85">
<caret line="79" column="33" selection-start-line="79" selection-start-column="33" selection-end-line="79" selection-end-column="33" />
<folding>
<element signature="e#39#59#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/CHANGELOG.md">
<provider selected="true" editor-type-id="split-provider[text-editor;markdown-preview-editor]">
<state split_layout="SPLIT">
<first_editor relative-caret-position="96">
<caret line="6" column="69" selection-start-line="6" selection-start-column="69" selection-end-line="6" selection-end-column="69" />
</first_editor>
<second_editor />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/README.md">
<provider selected="true" editor-type-id="split-provider[text-editor;markdown-preview-editor]">
<state split_layout="SPLIT">
<first_editor relative-caret-position="187">
<caret line="20" column="49" selection-start-line="20" selection-start-column="49" selection-end-line="20" selection-end-column="49" />
<folding>
<element signature="e#0#54#0" expanded="true" />
</folding>
<first_editor relative-caret-position="32">
<caret line="2" column="95" selection-start-line="2" selection-start-column="95" selection-end-line="2" selection-end-column="95" />
</first_editor>
<second_editor />
</state>

View file

@ -1,3 +1,7 @@
# 2.0.0-alpha.3
* Added `<Id, Data>` type parameters to `Service`.
* `HookedService` now follows suit, and takes a third parameter, pointing to the inner service.
# 2.0.0-alpha.2
* Added `ResponseContext.detach`.

View file

@ -1,21 +1,23 @@
import 'dart:async';
import 'service.dart';
/// An easy helper class to create one-off services without having to create an entire class.
///
/// Well-suited for testing.
class AnonymousService extends Service {
FutureOr Function([Map]) _index;
FutureOr Function(Object, [Map]) _read, _create, _remove;
FutureOr Function(Object, Object, [Map]) _modify, _update;
class AnonymousService<Id, Data> extends Service<Id, Data> {
FutureOr Function([Map<String, dynamic>]) _index;
FutureOr Function(Id, [Map<String, dynamic>]) _read, _remove;
FutureOr Function(Data, [Map<String, dynamic>]) _create;
Function(Id, Data, [Map<String, dynamic>]) _modify, _update;
AnonymousService(
{FutureOr index([Map params]),
FutureOr read(id, [Map params]),
FutureOr create(data, [Map params]),
FutureOr modify(id, data, [Map params]),
FutureOr update(id, data, [Map params]),
FutureOr remove(id, [Map params])})
FutureOr read(Id id, [Map params]),
FutureOr create(Data data, [Map params]),
FutureOr modify(Id id, Data data, [Map params]),
FutureOr update(Id id, Data data, [Map params]),
FutureOr remove(Id id, [Map params])})
: super() {
_index = index;
_read = read;
@ -26,28 +28,30 @@ class AnonymousService extends Service {
}
@override
index([Map params]) => new Future.sync(
index([Map<String, dynamic> params]) => new Future.sync(
() => _index != null ? _index(params) : super.index(params));
@override
read(id, [Map params]) => new Future.sync(
read(Id id, [Map<String, dynamic> params]) => new Future.sync(
() => _read != null ? _read(id, params) : super.read(id, params));
@override
create(data, [Map params]) => new Future.sync(() =>
create(Data data, [Map<String, dynamic> params]) => new Future.sync(() =>
_create != null ? _create(data, params) : super.create(data, params));
@override
modify(id, data, [Map params]) => new Future.sync(() => _modify != null
modify(Id id, Data data, [Map<String, dynamic> params]) =>
new Future.sync(() => _modify != null
? _modify(id, data, params)
: super.modify(id, data, params));
@override
update(id, data, [Map params]) => new Future.sync(() => _update != null
update(Id id, Data data, [Map<String, dynamic> params]) =>
new Future.sync(() => _update != null
? _update(id, data, params)
: super.update(id, data, params));
@override
remove(id, [Map params]) => new Future.sync(
remove(Id id, [Map<String, dynamic> params]) => new Future.sync(
() => _remove != null ? _remove(id, params) : super.remove(id, params));
}

View file

@ -10,11 +10,12 @@ import 'server.dart';
import 'service.dart';
/// Wraps another service in a service that broadcasts events on actions.
class HookedService extends Service {
class HookedService<Id, Data, T extends Service<Id, Data>>
extends Service<Id, Data> {
final List<StreamController<HookedServiceEvent>> _ctrl = [];
/// Tbe service that is proxied by this hooked one.
final Service inner;
final T inner;
final HookedServiceEventDispatcher beforeIndexed =
new HookedServiceEventDispatcher();
@ -41,7 +42,7 @@ class HookedService extends Service {
final HookedServiceEventDispatcher afterRemoved =
new HookedServiceEventDispatcher();
HookedService(Service this.inner) {
HookedService(this.inner) {
// Clone app instance
if (inner.app != null) this.app = inner.app;
}
@ -56,13 +57,14 @@ class HookedService extends Service {
return params['__responsectx'] as ResponseContext;
}
Map _stripReq(Map params) {
Map<String, dynamic> _stripReq(Map<String, dynamic> params) {
if (params == null)
return params;
else
return params.keys
.where((key) => key != '__requestctx' && key != '__responsectx')
.fold({}, (map, key) => map..[key] = params[key]);
.fold<Map<String, dynamic>>(
{}, (map, key) => map..[key] = params[key]);
}
/// Closes any open [StreamController]s on this instance. **Internal use only**.
@ -257,7 +259,7 @@ class HookedService extends Service {
}
@override
Future index([Map _params]) {
Future index([Map<String, dynamic> _params]) {
var params = _stripReq(_params);
return beforeIndexed
._emit(new HookedServiceEvent(false, _getRequest(_params),
@ -283,7 +285,7 @@ class HookedService extends Service {
}
@override
Future read(id, [Map _params]) {
Future read(id, [Map<String, dynamic> _params]) {
var params = _stripReq(_params);
return beforeRead
._emit(new HookedServiceEvent(false, _getRequest(_params),
@ -309,7 +311,7 @@ class HookedService extends Service {
}
@override
Future create(data, [Map _params]) {
Future create(data, [Map<String, dynamic> _params]) {
var params = _stripReq(_params);
return beforeCreated
._emit(new HookedServiceEvent(false, _getRequest(_params),
@ -335,7 +337,7 @@ class HookedService extends Service {
}
@override
Future modify(id, data, [Map _params]) {
Future modify(id, data, [Map<String, dynamic> _params]) {
var params = _stripReq(_params);
return beforeModified
._emit(new HookedServiceEvent(false, _getRequest(_params),
@ -361,7 +363,7 @@ class HookedService extends Service {
}
@override
Future update(id, data, [Map _params]) {
Future update(id, data, [Map<String, dynamic> _params]) {
var params = _stripReq(_params);
return beforeUpdated
._emit(new HookedServiceEvent(false, _getRequest(_params),
@ -387,7 +389,7 @@ class HookedService extends Service {
}
@override
Future remove(id, [Map _params]) {
Future remove(id, [Map<String, dynamic> _params]) {
var params = _stripReq(_params);
return beforeRemoved
._emit(new HookedServiceEvent(false, _getRequest(_params),

View file

@ -5,7 +5,7 @@ import 'package:angel_http_exception/angel_http_exception.dart';
import 'service.dart';
/// A basic service that manages an in-memory list of maps.
class MapService extends Service {
class MapService extends Service<String, Map<String, dynamic>> {
/// If set to `true`, clients can remove all items by passing a `null` `id` to `remove`.
///
/// `false` by default.
@ -35,8 +35,8 @@ class MapService extends Service {
String get updatedAtKey =>
autoSnakeCaseNames == false ? 'updatedAt' : 'updated_at';
bool Function(Map) _matchesId(id) {
return (Map item) {
bool Function(Map<String, dynamic>) _matchesId(id) {
return (Map<String, dynamic> item) {
if (item['id'] == null)
return false;
else if (autoIdAndDateFields != false)
@ -47,7 +47,7 @@ class MapService extends Service {
}
@override
Future<List> index([Map params]) {
Future<List> index([Map<String, dynamic> params]) {
if (allowQuery == false || params == null || params['query'] is! Map)
return new Future.value(items);
else {
@ -66,20 +66,20 @@ class MapService extends Service {
}
@override
Future<Map> read(id, [Map params]) {
Future<Map> read(String id, [Map<String, dynamic> params]) {
return new Future.value(items.firstWhere(_matchesId(id),
orElse: () => throw new AngelHttpException.notFound(
message: 'No record found for ID $id')));
}
@override
Future<Map> create(data, [Map params]) {
Future<Map> create(Map<String, dynamic> data, [Map<String, dynamic> params]) {
if (data is! Map)
throw new AngelHttpException.badRequest(
message:
'MapService does not support `create` with ${data.runtimeType}.');
var now = new DateTime.now().toIso8601String();
var result = data as Map;
var result = new Map<String, dynamic>.from(data);
if (autoIdAndDateFields == true) {
result
@ -87,19 +87,13 @@ class MapService extends Service {
..[autoSnakeCaseNames == false ? 'createdAt' : 'created_at'] = now
..[autoSnakeCaseNames == false ? 'updatedAt' : 'updated_at'] = now;
}
items.add(_foldStringDynamic(result));
items.add(result);
return new Future.value(result);
}
Map<String, dynamic> _foldStringDynamic(Map map) {
return map == null
? null
: map.keys.fold<Map<String, dynamic>>(
<String, dynamic>{}, (out, k) => out..[k.toString()] = map[k]);
}
@override
Future<Map> modify(id, data, [Map params]) {
Future<Map> modify(String id, Map<String, dynamic> data,
[Map<String, dynamic> params]) {
if (data is! Map)
throw new AngelHttpException.badRequest(
message:
@ -107,7 +101,7 @@ class MapService extends Service {
if (!items.any(_matchesId(id))) return create(data, params);
return read(id).then((item) {
var result = item..addAll(data as Map);
var result = new Map<String, dynamic>.from(item)..addAll(data);
if (autoIdAndDateFields == true)
result
@ -118,7 +112,8 @@ class MapService extends Service {
}
@override
Future<Map> update(id, data, [Map params]) {
Future<Map> update(String id, Map<String, dynamic> data,
[Map<String, dynamic> params]) {
if (data is! Map)
throw new AngelHttpException.badRequest(
message:
@ -130,7 +125,7 @@ class MapService extends Service {
throw new AngelHttpException.notFound(
message: 'No record found for ID $id');
var result = data as Map;
var result = new Map<String, dynamic>.from(data);
if (autoIdAndDateFields == true) {
result
..['id'] = id?.toString()
@ -139,13 +134,13 @@ class MapService extends Service {
..[autoSnakeCaseNames == false ? 'updatedAt' : 'updated_at'] =
new DateTime.now().toIso8601String();
}
items.add(_foldStringDynamic(result));
items.add(result);
return new Future.value(result);
});
}
@override
Future<Map> remove(id, [Map params]) {
Future<Map> remove(String id, [Map<String, dynamic> params]) {
if (id == null ||
id == 'null' &&
(allowRemoveAll == true ||

View file

@ -27,7 +27,7 @@ abstract class RequestContext<RawRequest> {
RawRequest get rawRequest;
/// Additional params to be passed to services.
final Map serviceParams = {};
final Map<String, dynamic> serviceParams = {};
/// The [Angel] instance that is responding to this request.
Angel app;

View file

@ -101,8 +101,9 @@ class Routable extends Router<RequestHandler> {
///
/// Returns a [HookedService] that can be used to hook into
/// events dispatched by this service.
HookedService use(String path, Service service) {
var hooked = new HookedService(service);
HookedService<Id, Data, T> use<Id, Data, T extends Service<Id, Data>>(
String path, T service) {
var hooked = new HookedService<Id, Data, T>(service);
_services[path
.toString()
.trim()

View file

@ -339,7 +339,8 @@ class Angel extends Routable {
}
@override
HookedService use(String path, Service service) {
HookedService<Id, Data, T> use<Id, Data, T extends Service<Id, Data>>(
String path, T service) {
service.app = this;
return super.use(path, service)..app = this;
}

View file

@ -79,7 +79,7 @@ class Service<Id, Data> extends Routable {
///
/// A custom [errorMessage] may be provided.
Future findOne(
[Map params,
[Map<String, dynamic> params,
String errorMessage = 'No record was found matching the given query.']) {
return index(params).then((result) {
if (result == null) {
@ -97,32 +97,32 @@ class Service<Id, Data> extends Routable {
}
/// Retrieves all resources.
Future index([Map params]) {
Future index([Map<String, dynamic> params]) {
throw new AngelHttpException.methodNotAllowed();
}
/// Retrieves the desired resource.
Future read(Id id, [Map params]) {
Future read(Id id, [Map<String, dynamic> params]) {
throw new AngelHttpException.methodNotAllowed();
}
/// Creates a resource.
Future create(Data data, [Map params]) {
Future create(Data data, [Map<String, dynamic> params]) {
throw new AngelHttpException.methodNotAllowed();
}
/// Modifies a resource.
Future modify(Id id, Data data, [Map params]) {
Future modify(Id id, Data data, [Map<String, dynamic> params]) {
throw new AngelHttpException.methodNotAllowed();
}
/// Overwrites a resource.
Future update(Id id, Data data, [Map params]) {
Future update(Id id, Data data, [Map<String, dynamic> params]) {
throw new AngelHttpException.methodNotAllowed();
}
/// Removes the given resource.
Future remove(Id id, [Map params]) {
Future remove(Id id, [Map<String, dynamic> params]) {
throw new AngelHttpException.methodNotAllowed();
}