Skip to content

Instantly share code, notes, and snippets.

@devth
Forked from swannodette/spec.cljs
Last active February 21, 2017 00:16
Show Gist options
  • Save devth/233cd43303658d40039ea27b033044d6 to your computer and use it in GitHub Desktop.
Save devth/233cd43303658d40039ea27b033044d6 to your computer and use it in GitHub Desktop.

Revisions

  1. devth revised this gist Feb 21, 2017. 1 changed file with 3 additions and 2 deletions.
    5 changes: 3 additions & 2 deletions spec.cljs
    Original file line number Diff line number Diff line change
    @@ -3,8 +3,9 @@

    (s/def ::ident (s/and vector? (s/cat :ident keyword? :value #(not (coll? %)))))
    (s/def ::join-key (s/or :prop keyword? :ident ::ident))
    (s/def ::join (s/and (s/map-of ::join-key ::query) #(= (count %) 1)))
    (s/def ::union (s/and (s/map-of keyword? ::query) #(> (count %) 1)))
    (s/def ::join (s/map-of ::join-key ::query))
    (s/def ::union (s/map-of keyword? (s/map-of keyword? ::query)))


    (s/def ::param-expr
    (s/cat :query-expr ::query-expr
  2. @swannodette swannodette revised this gist May 29, 2016. 1 changed file with 5 additions and 4 deletions.
    9 changes: 5 additions & 4 deletions spec.cljs
    Original file line number Diff line number Diff line change
    @@ -3,8 +3,8 @@

    (s/def ::ident (s/and vector? (s/cat :ident keyword? :value #(not (coll? %)))))
    (s/def ::join-key (s/or :prop keyword? :ident ::ident))
    (s/def ::join (s/and #(= (count %) 1) (s/map-of ::join-key ::query)))
    (s/def ::union (s/and #(> (count %) 1) (s/map-of keyword? ::query)))
    (s/def ::join (s/and (s/map-of ::join-key ::query) #(= (count %) 1)))
    (s/def ::union (s/and (s/map-of keyword? ::query) #(> (count %) 1)))

    (s/def ::param-expr
    (s/cat :query-expr ::query-expr
    @@ -24,16 +24,17 @@

    (s/def ::query
    (s/or :recursion (s/or :depth number?
    :unbounded (s/and symbol? #(= % '...)))
    :unbounded #(= % '...))
    :query (s/and vector?
    (s/+ ::query-expr))))


    (comment

    (s/explain ::query '[:name {:friend "foo"}])

    ; val: [:name {:friend "foo"}] fails at: [:recursion :depth] predicate: number?
    ; val: [:name {:friend "foo"}] fails at: [:recursion :unbounded] predicate: symbol?
    ; val: [:name {:friend "foo"}] fails at: [:recursion :unbounded] predicate: (= % (quote ...))
    ; In: [1] val: ({:friend "foo"}) fails at: [:query] predicate: (cat :_ (* :om.next.spec/query-expr)), Extra input

    )
  3. @swannodette swannodette created this gist May 29, 2016.
    39 changes: 39 additions & 0 deletions spec.cljs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,39 @@
    (ns om.next.spec
    (:require [cljs.spec :as s]))

    (s/def ::ident (s/and vector? (s/cat :ident keyword? :value #(not (coll? %)))))
    (s/def ::join-key (s/or :prop keyword? :ident ::ident))
    (s/def ::join (s/and #(= (count %) 1) (s/map-of ::join-key ::query)))
    (s/def ::union (s/and #(> (count %) 1) (s/map-of keyword? ::query)))

    (s/def ::param-expr
    (s/cat :query-expr ::query-expr
    :params map?))

    (s/def ::mutation-expr
    (s/or :no-params (s/cat :mutate-key symbol?)
    :with-params (s/cat :mutate-key symbol?
    :params map?)))

    (s/def ::query-expr
    (s/or :prop keyword?
    :ident ::ident
    :mutation-expr ::mutation-expr
    :union ::union
    :param-expr ::join))

    (s/def ::query
    (s/or :recursion (s/or :depth number?
    :unbounded (s/and symbol? #(= % '...)))
    :query (s/and vector?
    (s/+ ::query-expr))))

    (comment

    (s/explain ::query '[:name {:friend "foo"}])

    ; val: [:name {:friend "foo"}] fails at: [:recursion :depth] predicate: number?
    ; val: [:name {:friend "foo"}] fails at: [:recursion :unbounded] predicate: symbol?
    ; In: [1] val: ({:friend "foo"}) fails at: [:query] predicate: (cat :_ (* :om.next.spec/query-expr)), Extra input

    )