@lovelace_lol/polymer 0.0.4 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -204,26 +204,40 @@
204
204
  (defn match-event? [match event]
205
205
  (every? (fn [[key expected]] (= expected (get event key))) match))
206
206
 
207
+ (defn accepted-edge-context
208
+ [edge]
209
+ {:edgeId (:id edge)
210
+ :from (:from edge)
211
+ :to (:to edge)
212
+ :credit (:credit edge)})
213
+
214
+ (defn route-contexts
215
+ "Return all accepted edge metadata for one outgoing domain event.
216
+
217
+ An empty result means the topology, agency enablement, match predicate, or edge
218
+ credit rejected all candidate routes before they reached receiving agencies."
219
+ [society from event]
220
+ (if-not (agency-enabled? society from)
221
+ []
222
+ (into []
223
+ (keep (fn [edge]
224
+ (when (and (= from (:from edge))
225
+ (= (:type event) (:type edge))
226
+ (agency-enabled? society (:to edge))
227
+ (:enabled edge)
228
+ (pos? (:credit edge))
229
+ (match-event? (:match edge) event))
230
+ (accepted-edge-context edge))))
231
+ (:edges society))))
232
+
207
233
  (defn route-context
208
- "Return the accepted edge metadata for one outgoing domain event.
234
+ "Return one accepted edge metadata entry for an outgoing event and target.
209
235
 
210
- A nil result means the topology, agency enablement, match predicate, or edge
211
- credit rejected the route before it reached the receiving agency."
236
+ A nil result means the route was rejected before it reached the receiving
237
+ agency."
212
238
  [society from event to]
213
- (when (and (agency-enabled? society from)
214
- (agency-enabled? society to))
215
- (some (fn [edge]
216
- (when (and (= from (:from edge))
217
- (= to (:to edge))
218
- (= (:type event) (:type edge))
219
- (:enabled edge)
220
- (pos? (:credit edge))
221
- (match-event? (:match edge) event))
222
- {:edgeId (:id edge)
223
- :from from
224
- :to to
225
- :credit (:credit edge)}))
226
- (:edges society))))
239
+ (some #(when (= to (:to %)) %)
240
+ (route-contexts society from event)))
227
241
 
228
242
  (defn agency-config
229
243
  "Create one JS agency config without converting runtime/provider handles.
@@ -52,12 +52,23 @@
52
52
  :snapshot (js->clj (.snapshot ^js system) :keywordize-keys true)})
53
53
  (post-error! id "Unknown Polymer agency system id")))
54
54
 
55
+ (defn- update-society-routing! [id agency-society]
56
+ (if-let [system (get @systems id)]
57
+ (post! {:id id
58
+ :stream "society"
59
+ :agencySociety (js->clj
60
+ (.updateSocietyRouting ^js system
61
+ (clj->js agency-society))
62
+ :keywordize-keys true)})
63
+ (post-error! id "Unknown Polymer agency system id")))
64
+
55
65
  (defn- handle-message [message]
56
66
  (let [payload (js->clj (.-data message) :keywordize-keys true)
57
67
  id (or (:id payload) "character")]
58
68
  (case (:type payload)
59
69
  "createCharacterAgencies" (create-system! id (:config payload))
60
70
  "dispatch" (dispatch! id (:message payload))
71
+ "updateSocietyRouting" (update-society-routing! id (:agencySociety payload))
61
72
  "snapshot" (snapshot! id)
62
73
  "dispose" (do
63
74
  (dispose-system! id)