This repository was archived by the owner on Apr 17, 2018. It is now read-only.
File tree Expand file tree Collapse file tree 8 files changed +61
-3
lines changed Expand file tree Collapse file tree 8 files changed +61
-3
lines changed Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ exports.split = db_out.app.core.split;
99exports . retrieve = db_out . app . core . retrieve ;
1010exports . save = db_out . app . core . save ;
1111exports . index = db_out . app . core . index ;
12+ exports . augment = db_out . app . core . augment ;
1213exports . debug = db_out . app . core . debug ;
1314exports . dump = db_out . app . core . dump ;
1415exports . combine = db_out . app . core . combine ;
Original file line number Diff line number Diff line change 1+ (ns app.augment.index
2+ (:require [app.augment.mappings :refer [mappings]]
3+ [app.augment.specs :refer [specs]]
4+ [backend-shared.service.index :as service]
5+ [shared.protocols.convertible :as cv]
6+ [shared.protocols.queryable :as qa]
7+ [cljs.core.async :as async])
8+ (:require-macros [cljs.core.async.macros :refer [go]]))
9+
10+ (def adapters {:db {:table-names {:bookmarks (.. js/process -env -bookmarksTable)}}})
11+
12+ (defn augment [& args]
13+ (go
14+ (let [{:keys [event] :as service} (apply service/create specs mappings adapters args)
15+ {:keys [added] :as payload} (cv/to-db-events event)
16+ res (async/<! (qa/fetch service added))]
17+ (service/done service res))))
Original file line number Diff line number Diff line change 1+ (ns app.augment.mappings
2+ (:require [backend-shared.service.index :refer [perform fetch]]
3+ [shared.protocols.actionable :as ac]
4+ [shared.protocols.queryable :as qa]
5+ [shared.protocols.loggable :as log])
6+ (:require-macros [cljs.core.async.macros :refer [go]]))
7+
8+ (defn mappings []
9+
10+ (defmethod fetch :bookmarks [{:keys [db]} payload]
11+ (let [query (map (fn [{:keys [bookmark-url]}] {:resource-url bookmark-url}) payload)]
12+ (qa/fetch db query)))
13+
14+ (defmethod perform [:put :nothing ] [_ _]
15+ (go {:error :no-payload }))
16+
17+ (defmethod perform [:put :errors ] [_ [_ errors]]
18+ (go errors))
19+
20+ (defmethod perform :default [{:keys [bucket]} action]
21+ (ac/perform bucket action)))
Original file line number Diff line number Diff line change 1+ (ns app.augment.specs
2+ (:require [cljs.spec :as spec]
3+ [shared.specs.action :as action :refer [action-spec]]))
4+
5+ (spec/def ::resource-url :base/url )
6+ (spec/def :query/bookmark (spec/keys :req-un [::resource-url ]))
7+
8+ (defn specs []
9+ (spec/def :offcourse/query (spec/or :bookmarks (spec/coll-of :query/resource )
10+ :errors (spec/coll-of :offcourse/error ))))
Original file line number Diff line number Diff line change 33 [shared.protocols.actionable :as ac]
44 [shared.protocols.convertible :as cv]
55 [shared.protocols.queryable :as qa]
6- [shared.protocols.loggable :as log])
6+ [shared.protocols.loggable :as log]
7+ [cljs.core.async :as async])
78 (:require-macros [cljs.core.async.macros :refer [go]]))
89
910(defn mappings []
1011
11- (defmethod fetch :identity [{:keys [db]} query]
12+ (defmethod fetch :identity [{:keys [db table-names ]} query]
1213 (qa/fetch db query))
1314
1415 (defmethod fetch :error [{:keys [db]} error]
Original file line number Diff line number Diff line change 44 [backend-shared.index]
55 [app.query.index :as query]
66 [app.transform.index :as transform]
7+ [app.augment.index :as augment]
78 [app.command.index :as command]
89 [app.retrieve.index :as retrieve]
910 [app.index.index :as index]
2122(def ^:export download download /download )
2223(def ^:export save save /save )
2324(def ^:export index index /index )
25+ (def ^:export augment augment /augment )
2426(def ^:export debug debug /debug )
2527(def ^:export retrieve retrieve /retrieve )
2628
Original file line number Diff line number Diff line change 2323 (handle-request index query true ))
2424
2525 (defmethod fetch :resource [{:keys [db stage]} query]
26- (go ( async/<! ( qa/fetch db query)) )))
26+ (qa/fetch db query)))
Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ provider:
1111 - dynamodb:GetItem
1212 - dynamodb:BatchGetItem
1313 - dynamodb:PutItem
14+ - dynamodb:query
1415 - dynamodb:Scan
1516 - s3:PutObject
1617 - s3:GetObject
@@ -43,6 +44,11 @@ functions:
4344 integration : lambda
4445 authorizer : authorize
4546
47+ augment :
48+ handler : functions/index.augment
49+ environment :
50+ bookmarksTable : " bookmarks-${opt:stage}"
51+
4652 query :
4753 handler : functions/index.query
4854 environment :
You can’t perform that action at this time.
0 commit comments