Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Oct 12 2021 21:36
    fcallejon edited #60
  • Oct 12 2021 21:34
    fcallejon edited #60
  • Oct 12 2021 21:33
    fcallejon opened #60
  • Oct 12 2021 21:05
  • Aug 10 2021 21:30
  • Jun 24 2021 03:00
  • Apr 06 2021 08:21
    cmeeren commented #59
  • Apr 06 2021 08:20
    cmeeren commented #59
  • Apr 06 2021 08:01
    varon commented #59
  • Apr 06 2021 06:02
    cmeeren commented #59
  • Apr 06 2021 06:01
    cmeeren commented #59
  • Apr 06 2021 02:06
    et1975 commented #59
  • Apr 05 2021 19:04
    cmeeren commented #59
  • Apr 05 2021 12:36
    varon commented #59
  • Mar 30 2021 17:23
    cmeeren opened #59
  • Jan 27 2021 14:37
    LAJW commented #58
  • Jan 27 2021 11:06
    varon commented #58
  • Jan 27 2021 09:22
    LAJW commented #58
  • Jan 26 2021 20:45
    varon commented #58
  • Jan 26 2021 20:44
    varon commented #58
Alojzy Leszcz
@bratfizyk
    type ToJsonDefaults = ToJsonDefaults with

        static member inline ToJson (x: unit) =
            Json.Optic.set Json.Null_ x
Background: I've been working on my own OWIN extension like this:
app.UseStaticFiles(staticConfig)
                   .UseChironProcessor(Post "/api/myEndpoint", api.myEndpointHandler)
app is of type IAppBuilder
in general the handler function is of type: 'a -> 'b, but all the in params are sent as strings and then parsed to 'a using Chiron
however, sometimes 'a is just unit - there are functions in my api that don't require any parameter (e.g. return all the records in an associated db)
and that's the problem
Andrew Cherry
@kolektiv
oh, yes i see what you mean there. hmmm. i'll have a quick look and see if there's a neat way to stick that in (and for FromJson too).
i don't see why not.
Andrew Cherry
@kolektiv
@bratfizyk so, i just pushed out a pre-release of Chiron with a change to support that, if you want to try it. take a dependency on Chiron 6.3.0-rc1 and see whether that works for you :)
Alojzy Leszcz
@bratfizyk
@kolektiv Cool - let me take a look.
Alojzy Leszcz
@bratfizyk
ok - so here's what I found out
My "UseChironProcessor" endpoint now compiles for functions like: unit -> 'a, but the problem is that for "kick" this endpoint, I need to put "null" in GET/POST body.
Ideally I'd like it to work with an empty body, but that would require Chiron to interpret an empty string as a unit value.
Not sure if it's potentially dangerous - what do you think about it ?
Andrew Cherry
@kolektiv
mmmm. have you considered having an optional body type? So Option<Json> or similar? that might make things easier, as any empty body would simply become None - and that maps closer to the semantics of HTTP i think...
(happy to take a look at the source of the ChironProcessor if you like as well, might be able to offer a suggestion!)
it'll be later today though as I have to head for some meetings now, but i'm happy to take a look when i can!
Alojzy Leszcz
@bratfizyk
sure - I'll give a go to your suggestion with the optional body
now that unit values compile, life is a bit simpler
I'll keep you updated
Alojzy Leszcz
@bratfizyk
                  requestBody :=  
                        (let body = (Env.getRequestBody environment) in if String.isNullOrEmpty body then "null" else body)
works for now - hopefully won't bite me too painfully
Andrew Cherry
@kolektiv
that sounds pretty good :) i'd love to see the complete thing and how it works if you can share any of it
Alojzy Leszcz
@bratfizyk
Yeah - that's the problem. It's not my personal project, but a corporate one, so unfortunately I can't share it - sorry for that.
The fix for unit - however - has been working well so far. I'll keep on testing it next week.
Andrew Cherry
@kolektiv
that's no problem - i'm always happy when code is being used, open or not! glad the unit fix is useful, if you don't find issues i might make that final next week
Alojzy Leszcz
@bratfizyk
OK - for sure I'll let you know about my testing experience ;).
Andrew Cherry
@kolektiv
thanks! :)
Alojzy Leszcz
@bratfizyk
Now it's marked as "rc", so no rush - let's make sure it truly deserves becoming an official release ;)
all right - home time; have a good weekend !
Andrew Cherry
@kolektiv
you too!
Alojzy Leszcz
@bratfizyk
Heya - interesting stuff found today:
        let inline serialise (x : 'a) = 
            (Chiron.Mapping.Json.serialize >> Chiron.Formatting.Json.format) x
and now:
> serialise [| 1; 2 |];;
val it : string = "[1,2]"
but:
> serialise [| "1"; "2" |];;
System.TypeInitializationException: The type initializer for 'Escaping' threw an exception. ---> System.TypeInitializationException: The type initializer for '<StartupCode$Chiron>.$Chiron' threw an exception. ---> System.IO.FileNotFoundException: Could not load file or assembly 'FParsec, Version=1.0.0.0, Culture=neutral, PublicKeyToken=40ccfc0a09edbb5d' or one of its dependencies. The system cannot find the file specified.
   at <StartupCode$Chiron>.$Chiron..cctor()
   --- End of inner exception stack trace ---
   at Chiron.Escaping..cctor() in C:\projects\chiron\src\Chiron\Chiron.fs:line 0
>    --- End of inner exception stack trace ---
   at Chiron.Escaping.escape(String s)
   at Chiron.Formatting.formatJson(Int32 level, JsonFormattingOptions options, Json _arg1) in C:\projects\chiron\src\Chiron\Chiron.fs:line 704
   at Chiron.Formatting.formatArray@710-1.Invoke(Json _arg1) in C:\projects\chiron\src\Chiron\Chiron.fs:line 710
   at Chiron.Formatting.join@667-2.Invoke(StringBuilder b) in C:\projects\chiron\src\Chiron\Chiron.fs:line 670
   at Chiron.Formatting.formatArray@708-4.Invoke(StringBuilder x) in C:\projects\chiron\src\Chiron\Chiron.fs:line 708
   at Chiron.Formatting.formatArray@708-5.Invoke(StringBuilder x) in C:\projects\chiron\src\Chiron\Chiron.fs:line 708
   at Chiron.Formatting.Json.format(Json json) in C:\projects\chiron\src\Chiron\Chiron.fs:line 743
   at <StartupCode$FSI_0005>.$FSI_0005.main@()
Stopped due to error
So serialising an array of ints works fine, but doesn't work with an array of strings.
Can you try it as well ?
Andrew Cherry
@kolektiv
i'll have a look when i get a chance a little later! i'd start by seeing if i can work out why there's a file not found error for fparsec - that might well be related, but it's odd that it would be intermittent.
Alojzy Leszcz
@bratfizyk
ok - feel free to ignore this
I've just checked that after some paket-magic I had done, my project lost a reference to FParsec
After fixing that all fine
sorry for the false alarm
Andrew Cherry
@kolektiv
no problem :)
Alojzy Leszcz
@bratfizyk
Heya - about the unit feature testing: so far so good
Andrew Cherry
@kolektiv
:) sounds good!
Stefan Reichel
@stefan-akelius
This message was deleted
btrepp
@btrepp

With lenses and prisms, is there a guide in which it is appropriate to use either?. are prisms mainly for nested datastructures?. In freya the IfMatch_ header is returned as an IfMatch option Lens, rather than an IfMatch prism.

Say i wanted to deal with some nested values, it would make sense to use an epimorphism eg ifmatchweaktag_: Epimorphism<IfMatch,EntityTag.Weak>
But then with IfMatch itself being a Lens<IfMatch option> this doesn't compose.

I have written a composing epimorphism

      let private toPrism_ : Epimorphism<'T option, 'T> = (fun x -> x),
                                                            (fun v -> Some v)

but I'm not sure if this is idiomatic. I ask because I have my own lens in freya for the ClaimsPrincipal Lens<State,ClaimsPrincipal option>, which I can see the advantage for (eg my middeware could remove the claims principal if it wants to), but then most uses I can think of would want Prism<State,ClaimsPrincipal>.