eyre: convert facts to json manually

By doing a %watch instead of %watch-as %json for channel subscriptions,
we can hopefully make better use of noun deduplication, when storing
events in a channel's event queue until they get acked.
This commit is contained in:
fang 2020-10-18 16:31:35 +02:00
parent 8def1dbea8
commit 7e5f29cfd2
No known key found for this signature in database
GPG Key ID: EB035760C1BBA972

View File

@ -1214,10 +1214,9 @@
events events
=^ head queue ~(get to queue) =^ head queue ~(get to queue)
=, p.head =, p.head
=/ sign=(unit sign:agent:gall) ?~ sign=(channel-event-to-sign channel-event) $
(channel-event-to-sign channel-event) ?~ json=(sign-to-json request-id u.sign) $
?~ sign $ $(events [(event-json-to-wall id u.json) events])
$(events [(event-json-to-wall id (sign-to-json request-id u.sign)) events])
:: send the start event to the client :: send the start event to the client
:: ::
=^ http-moves state =^ http-moves state
@ -1363,7 +1362,7 @@
:^ duct %pass :^ duct %pass
(subscription-wire channel-id request-id ship app) (subscription-wire channel-id request-id ship app)
:* %g %deal [our ship] app :* %g %deal [our ship] app
`task:agent:gall`[%watch-as %json path] `task:agent:gall`[%watch path]
== ==
:: ::
=. session.channel-state.state =. session.channel-state.state
@ -1469,6 +1468,8 @@
:: ::
=? moves ?=([%| *] state.u.channel) =? moves ?=([%| *] state.u.channel)
^- (list move) ^- (list move)
?~ json=(sign-to-json request-id sign)
moves
:_ moves :_ moves
:+ p.state.u.channel %give :+ p.state.u.channel %give
^- gift:able ^- gift:able
@ -1476,7 +1477,7 @@
:: ::
^= data ^= data
%- wall-to-octs %- wall-to-octs
(event-json-to-wall event-id (sign-to-json request-id sign)) (event-json-to-wall event-id u.json)
:: ::
complete=%.n complete=%.n
== ==
@ -1513,29 +1514,37 @@
=/ res (mule |.((vale:dais noun.event))) =/ res (mule |.((vale:dais noun.event)))
?: ?=(%| -.res) ?: ?=(%| -.res)
((slog leaf+"eyre: stale fact of mark {(trip have)}" ~) ~) ((slog leaf+"eyre: stale fact of mark {(trip have)}" ~) ~)
=* vase p.res `[%fact have p.res]
:: find and use tube from fact mark to json
::TODO move into sign-to-json
::
=* desc=tape "from {(trip have)} to json"
=/ tube=(unit tube:clay)
?: =(have %json) `(bake same ^vase)
=/ tuc=(unit (unit cage))
(scry [%141 %noun] ~ %cc [our %home da+now] (flop /[have]/json))
?. ?=([~ ~ *] tuc) ~
`!<(tube:clay q.u.u.tuc)
?~ tube
((slog leaf+"eyre: no tube {desc}" ~) ~)
::
=/ res (mule |.((u.tube vase)))
?: ?=(%& -.res)
`[%fact %json p.res]
((slog leaf+"eyre: failed tube {desc}" ~) ~)
:: +sign-to-json: render sign from request-id as json channel event :: +sign-to-json: render sign from request-id as json channel event
:: ::
++ sign-to-json ++ sign-to-json
|= [request-id=@ud =sign:agent:gall] |= [request-id=@ud =sign:agent:gall]
^- json ^- (unit json)
:: for facts, we try to convert the result to json
::
=/ jsyn=(unit sign:agent:gall)
?. ?=(%fact -.sign) `sign
?: ?=(%json p.cage.sign) `sign
:: find and use tube from fact mark to json
::
=* have=mark p.cage.sign
=* desc=tape "from {(trip have)} to json"
=/ tube=(unit tube:clay)
=/ tuc=(unit (unit cage))
(scry [%141 %noun] ~ %cc [our %home da+now] (flop /[have]/json))
?. ?=([~ ~ *] tuc) ~
`!<(tube:clay q.u.u.tuc)
?~ tube
((slog leaf+"eyre: no tube {desc}" ~) ~)
::
=/ res (mule |.((u.tube q.cage.sign)))
?: ?=(%& -.res)
`[%fact %json p.res]
((slog leaf+"eyre: failed tube {desc}" ~) ~)
::
?~ jsyn ~
%- some
=* sign u.jsyn
=, enjs:format =, enjs:format
%- pairs %- pairs
^- (list [@t json]) ^- (list [@t json])
@ -1553,7 +1562,7 @@
:~ ['response' [%s 'diff']] :~ ['response' [%s 'diff']]
:: ::
:- 'json' :- 'json'
::TODO do mark conversion here ~| [%unexpected-fact-mark p.cage.sign]
?> =(%json p.cage.sign) ?> =(%json p.cage.sign)
;;(json q.q.cage.sign) ;;(json q.q.cage.sign)
== ==