This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-04-05
Channels
- # architecture (2)
- # aws (1)
- # bangalore-clj (4)
- # beginners (97)
- # boot (35)
- # cider (8)
- # cljsjs (3)
- # cljsrn (35)
- # clojure (190)
- # clojure-dusseldorf (4)
- # clojure-italy (7)
- # clojure-poland (1)
- # clojure-russia (17)
- # clojure-spec (74)
- # clojure-uk (30)
- # clojureremote (2)
- # clojurescript (298)
- # code-reviews (18)
- # component (18)
- # cursive (18)
- # datascript (3)
- # datavis (2)
- # datomic (24)
- # dirac (17)
- # emacs (3)
- # garden (7)
- # hoplon (51)
- # jobs (2)
- # jobs-rus (2)
- # leiningen (4)
- # luminus (11)
- # mount (24)
- # off-topic (1)
- # om (32)
- # onyx (25)
- # pedestal (1)
- # powderkeg (9)
- # protorepl (6)
- # re-frame (11)
- # reagent (15)
- # spacemacs (6)
- # sql (35)
- # uncomplicate (1)
- # unrepl (74)
- # untangled (130)
- # yada (6)
user=> (s/def ::foo (s/map-of any? map?))
:user/foo
user=> (s/valid? ::foo {:a {:b 1}})
true
here I could also do (s/map-of any? (s/map-of any? any?))
but the inner (s/map-of any? any?)
is equiv to map?
right?
Is there a way to send clojure spec over the wire? Iām looking to dynamically fetch specs from a clojure service via a HTTP request, into my clojurescript app that needs to use these specs for validation, etc.
Unfortunately, I canāt share these specs via cljc, because the server, and the client apps should be decoupled. So itās a runtime dependency.
@shafeeq you can put your specs into a .cljc
file so they can be shared, but serializing a spec will not work
@thheller: I (perhaps incorrectly) thought specs are just data and can be passed around like data.
the s/form
is the serialization format for specs. You need to recursively fetch all the related specs too.
spiked that with a custom rmi-style āspec-loaderā that is used to negotiate the specs over the wire.
@thheller: ah; besides functions, are there other things that need to be serailized? (and it seems like functions can be serialized if you have a giant hashmap of keyword to functions)
user=> (let [x :foo ] (s/form (s/spec #(= % x))))
(clojure.core/fn [%] (clojure.core/= % x))
there was discussion about dynamic scope somewhere in channel history but slack eats it š
Well in my case, I only use clojure.core predicates, since I also need the spec to be representable via swagger as well.
Hereās what I have so far: https://gist.github.com/shafeeq/c2ded8e71579a26e44c2191536e01c0d
On the clojurescript side, now I have to walk through this list of specs and make definitions.
Would something like this work? Am I missing some other perspectives or edge cases (apart from custom functions)?
nice. did similar spike before the s/form
bugs were fixed, now might work on most/specs already.
that opens up a security concernā¦ running eval on something that has come over the wire.
you can, you shoudnāt? (https://github.com/metosin/spec-tools/blob/master/src/spec_tools/core.cljc#L57-L62)
as @qqq suggested you could make this work if turn everything into keywords and then define those keywords on both ends
but really ... use .cljc
(just turn the specs into a library the client/server can share)
@thheller from a higher level perspective: the specs on the server side will evolve with time, and we shouldnāt really have to compile, and build the client. The client should ideally be oblivious to changes in the specs. It should pull it down (via http), and use it.
well, the specs are my API specification at the moment. Apart from getting a catalog of requests, Iām building and coercing requests on the clojurescript side based on the spec.
I already have this functionality implemented for swagger.json. Iām moving to spec now.
@thheller: I'm impressed by how flexible spec is. I can't imagine even asking this question in Haskell. š
Is it possible to get full spec instrumentation during ClojureScript development in your running app? (using Figwheel). Iāve run cljs.spec.test/instrument which returns a list of fdefāed functions, but none of the fdef functions trigger when the contract is broken.
Hi, I've been trying all day to figure out how to correctly spec a variable-length vector as described here: http://stackoverflow.com/questions/43230546/a-clojure-spec-that-matches-and-generates-an-ordered-vector-of-variable-length
I can only seem to create a matching spec with spec/cat
but it in turn will only generate lists š
Iām rewriting my prismatic-schema spec into clojure.spec. Thereās a lot of it. Has anyone here heard of or used some utility to help with this?
thomas: I'm able to match them using the seq regexes, but not generate data since they generate lists and I can't seem to be able to message them that I want vectors instead.
thomas: I'd have to look up how that works first. The docs are very empty when it comes to explaining its use.
@thomas Alex helped me to find a solution: http://stackoverflow.com/a/43233374/501017
itās not uncommon to run into this when specāing a macro (the need exists in a few places in the clojure.core specs) and as you can see in the example, itās quite tedious to properly solve (even that example is missing what you really want for describe/form). Weāve been discussing something like s/vcat for this but Rich has several competing ideas for how to implement it and Iām not sure where he will end up going with it.
Are they design alternatives or impl alternatives @alexmiller ?
Following http://dev.clojure.org/jira/browse/CLJ-2141, it seems to me that Clojure is missing a predicate namespaced? which returns true if a thing is, well, namespaced.
(def spec (s/coll-of string? :into {}))
(s/explain-data spec {"1" "2"})
; #:clojure.spec{:problems ({:path [], :pred string?, :val ["1" "2"], :via [], :in [0]})}
(s/explain-data spec ["1" "2"])
; nil
(s/conform spec ["1" "2"])
; CompilerException java.lang.ClassCastException
@ikitommi if using :into {}, you should be using a spec for a map entry (like a 2 element tuple)
Like (s/coll-of (s/tuple string? string?) :into {})
@slipset I don't think that's generally useful enough
That's effectively how map-of is implemented
Is there any (idiomatic) way to attach custom s/explain
data for user specs? Use case is a predicate that supplies its own context information that I'd like to have preserved in the failure message.
@alexmiller can you elaborate around design alternatives for vcat
?
@takeoutweight you can vote at http://dev.clojure.org/jira/browse/CLJ-2115
or weigh in there
@ghadi at this point I just donāt remember the details (and Rich did not fully elaborate on them anyways)
we did talk about it for a while. I mostly remember that he didnāt like any of my ideas. :)