Fork me on GitHub
#untangled
<
2016-11-08
>
mitchelkuijpers08:11:27

That would fix it πŸ™‚ @tony.kay I also found some bugs with regard to ident loading with load, Ill try to reproduce them this week

tony.kay18:11:29

@mitchelkuijpers interesting. Let me know. Thanks

wilkerlucio19:11:05

in untangled-server, how can I add ring session or any kind of handler wrappers?

adambrosio19:11:29

I and tony added untangled-system to the latest snapshot, but I dont think it has any/good documentation Otherwise: make-untangled-server takes :components that can depend on :handler and inject into handler stack at two locations pre-hook and fallback-hook using get-pre-hook and set-pre-hook

adambrosio19:11:20

let me find you a cookbook or something

wilkerlucio19:11:48

@adambros thanks, I just figured out, found an example using the wrap-cookie, all good πŸ™‚

adambrosio19:11:11

is that yours?

wilkerlucio19:11:22

no, it came on the template from Tony

wilkerlucio19:11:29

I just added the wrap-session bit

adambrosio19:11:56

in the future untangled-system is the way forwards it simply lets you have complete control over the handler stack

adambrosio19:11:41

and you can create a webserver, or grab the pieces you need and put them in some other servlet

adambrosio19:11:00

for now the best documentation is the specs for it

wilkerlucio19:11:11

cool, thanks for letting me know

wilkerlucio19:11:57

one other question, how do you set the session values? I see at the docs that I should return the ring request with the session modified from a handler, but how can we do that from a parser mutation?

adambrosio19:11:32

iirc we have an open issue about that

adambrosio19:11:19

you should add that you might want to change the :session

wilkerlucio19:11:15

yeah, I guess @tony.kay is thinking on the request in general, but I'll add a note just in case

wilkerlucio19:11:29

@tony.kay on the issue you suggest using metadata to get the response modifications, why not just a key in the response map (like untangled.server/response)?

wilkerlucio19:11:48

oh, I see, it all get's returned to the om parser, gotcha

tony.kay21:11:56

@wilkerlucio At the moment you can return a response to the client and use cljs to set a cookie, but we do need a general purpose solution from a mutation

tony.kay21:11:16

but with ring-session you can access the session store

wilkerlucio21:11:33

@tony.kay I sent a PR with a possible solution to the response problem

wilkerlucio21:11:01

I first tried using the idea of meta-data returning, but since the parser can return on multiple nodes the merging could become an issue

tony.kay21:11:27

yep, that was partly why I hadn't done it yet πŸ™‚

wilkerlucio21:11:37

so I had another idea (a simpler one I think) that is to have a shared atom called response, that the parser can mutate, then it get's merged into the response

wilkerlucio21:11:46

this way, the merging is user responsability

tony.kay21:11:56

oooo..state, I dislike that more, to be honest

tony.kay21:11:21

I'd rather have idempotent metadata...e.g. "add cookie", "add header"...things that compose well

tony.kay21:11:52

it is /api; there isn't much you should ever need to do

tony.kay21:11:12

and mutations are non-recursive, so it is a simple merge

wilkerlucio21:11:35

I'm just thinking that multiple mutations can ask for example to change the session

wilkerlucio21:11:54

in this case, if we implement the merging in untangled we are taking this decision upfront on how to manage it

tony.kay21:11:55

changing the session should be done IN the mutation, with direct access to the session store

tony.kay21:11:01

the only thing the client cares about is the cookie

tony.kay21:11:07

which should be identical in both

tony.kay21:11:13

again, idempotent

tony.kay21:11:20

set it 5x, who cares?

tony.kay21:11:57

Now, this IS server-side, so we don't have the app-state serialization concern

tony.kay21:11:12

we could put a lamba on the metadata of type resp->resp

tony.kay21:11:20

now it chains

tony.kay21:11:00

(f (g (h response))) -> new response

tony.kay21:11:30

or rather, response

tony.kay21:11:32

not session

wilkerlucio21:11:34

let me update the PR, I'll revert to the metadata, and change from merging to lambds

wilkerlucio21:11:37

yeah, response

adambrosio21:11:15

now are we still limiting what you can do to the response?

tony.kay21:11:29

no, but if you break it, it's your problem πŸ˜‰

adambrosio21:11:56

is this for reads and mutates?

tony.kay21:11:14

any reason on reads?

tony.kay21:11:38

you have to change server state, so I'd say it only makes sense abstractly on mutations

adambrosio21:11:12

makes enough sense

adambrosio21:11:47

@wilkerlucio you are doing this in just reads though

wilkerlucio21:11:02

the current way just doens't care if it's a read or a write

wilkerlucio21:11:07

should we limit to writes?

adambrosio21:11:15

read above tony’s last message

wilkerlucio21:11:59

what if a user wants to change the response status from a read?

tony.kay21:11:56

recursive parsing...how do you find them all? Throw an exception and get a 500, or return a response that you can deal with on the client. Don't care about HTTP status codes because this isn't REST

tony.kay21:11:22

in other words, treat it more like RMI, not HTTP

wilkerlucio21:11:41

ok, so, in this case, instead of walk the response, we can scan just the first level and apply the with-response in the ones that are symbols (and so, mutations), is that correct?

tony.kay21:11:48

That was my take, yes. On reads, what are the use-cases where you'd need it. If there are many valid ones, then maybe we support it only on top-level values?

tony.kay21:11:15

Headers for caching might end up being interesting when we get to http caching of responses...but I'm not sure we won't have another way of dealing with that

tony.kay21:11:34

since you have to hook into a specific alternate URL and remote def for that

wilkerlucio21:11:55

I don't see any case right now in favor of giving the readings, except that I also don't see a reason to don't allow it, I prefer to leave the decision of using or not to the user on those cases

tony.kay21:11:21

So, if we only look at the shallow case, I'm ok with it handling reads and writes

wilkerlucio21:11:23

I think allowing on the top level is a good approach until we have more input on this

tony.kay21:11:46

can always add a filter to symbols

wilkerlucio21:11:45

@tony.kay PR updated, scanning only root

tony.kay21:11:00

sweet. Behavioral tests?

wilkerlucio21:11:35

I added tests on the API method directly, there is any other place I should be checking on it?

wilkerlucio21:11:25

also, I added a method with-response at the core, but I'm not sure if this is the best place and name for it

tony.kay21:11:40

I'll take a look, thanks!

tony.kay21:11:51

Hm. So, should the reduction get to see the status/body of the response? If not, then the merge order is probably wrong.

tony.kay22:11:53

the behavioral (test) should say something like "prefers original response body and status over any appearing in the modified response"

tony.kay22:11:28

I like the helper function. Core is a fine place for it. Naming.....suggestions anyone?

tony.kay22:11:36

augment-response?

tony.kay22:11:00

arg names are off, too

tony.kay22:11:23

(defn augment-response [core-response ring-response-fn] ...)?

tony.kay22:11:33

doc string would be extra good there

wilkerlucio22:11:28

I though you wanted the ability to change the status, (because your example (response-with-status { :tempids {n m} } 202)), so, no body and status change, right?

tony.kay22:11:53

ah. I'm easily swayed on that

tony.kay22:11:05

just want a spec that says which way it is intended to behave

tony.kay22:11:14

and proves it behaves that way

adambrosio22:11:45

(augment-response {…}
   (comp
      (with-status 202)
      (with-header …)))

wilkerlucio22:11:57

ok, I'm writing the spec for that, so I'll leave the status open and block the :body

adambrosio22:11:15

it then just becomes middleware?

wilkerlucio22:11:17

@adambros you think untangled should provide those helpers?

adambrosio22:11:25

ring should have some

tony.kay22:11:29

I'm ok being able to mess with the body, just as long as we say it is what you can do

tony.kay22:11:47

oh right, @adambros there are already Ring response helpers like that

tony.kay22:11:52

set-content-type etc

tony.kay22:11:14

so yeah, just leverage the middleware helpers that are in Ring already

wilkerlucio22:11:15

yeah, the lambda approach should enable the usage of those, nice πŸ™‚

tony.kay22:11:58

resp -> resp

tony.kay22:11:00

it's all good

tony.kay22:11:23

good effort team πŸ™‚

wilkerlucio22:11:01

@tony.kay added new specs and docs

tony.kay23:11:17

thx. I'll look very soon.