mirror of
https://github.com/penpot/penpot.git
synced 2025-07-22 19:18:05 +02:00
🐛 Fix decoding on sm/set schema
This commit is contained in:
parent
f5510234cf
commit
15faa57e01
2 changed files with 59 additions and 38 deletions
|
@ -476,7 +476,7 @@
|
||||||
::oapi/type "string"
|
::oapi/type "string"
|
||||||
::oapi/format "email"}})
|
::oapi/format "email"}})
|
||||||
|
|
||||||
(def non-empty-strings-xf
|
(def xf:filter-word-strings
|
||||||
(comp
|
(comp
|
||||||
(filter string?)
|
(filter string?)
|
||||||
(remove str/empty?)
|
(remove str/empty?)
|
||||||
|
@ -489,11 +489,8 @@
|
||||||
:min 0
|
:min 0
|
||||||
:max 1
|
:max 1
|
||||||
:compile
|
:compile
|
||||||
(fn [{:keys [coerce kind max min] :as props} children _]
|
(fn [{:keys [kind max min] :as props} children _]
|
||||||
(let [xform (if coerce
|
(let [kind (or (last children) kind)
|
||||||
(comp non-empty-strings-xf (map coerce))
|
|
||||||
non-empty-strings-xf)
|
|
||||||
kind (or (last children) kind)
|
|
||||||
|
|
||||||
pred
|
pred
|
||||||
(cond
|
(cond
|
||||||
|
@ -501,9 +498,6 @@
|
||||||
(nil? kind) any?
|
(nil? kind) any?
|
||||||
:else (validator kind))
|
:else (validator kind))
|
||||||
|
|
||||||
encode-child
|
|
||||||
(encoder kind string-transformer)
|
|
||||||
|
|
||||||
pred
|
pred
|
||||||
(cond
|
(cond
|
||||||
(and max min)
|
(and max min)
|
||||||
|
@ -531,31 +525,49 @@
|
||||||
(fn [value]
|
(fn [value]
|
||||||
(every? pred value)))
|
(every? pred value)))
|
||||||
|
|
||||||
decode
|
|
||||||
|
decode-string-child
|
||||||
|
(decoder kind string-transformer)
|
||||||
|
|
||||||
|
decode-string
|
||||||
(fn [v]
|
(fn [v]
|
||||||
(let [v (if (string? v) (str/split v #"[\s,]+") v)]
|
(let [v (if (string? v) (str/split v #"[\s,]+") v)
|
||||||
(into #{} xform v)))
|
x (comp xf:filter-word-strings (map decode-string-child))]
|
||||||
|
(into #{} x v)))
|
||||||
|
|
||||||
|
decode-json-child
|
||||||
|
(decoder kind json-transformer)
|
||||||
|
|
||||||
|
decode-json
|
||||||
|
(fn [v]
|
||||||
|
(let [v (if (string? v) (str/split v #"[\s,]+") v)
|
||||||
|
x (comp xf:filter-word-strings (map decode-json-child))]
|
||||||
|
(into #{} x v)))
|
||||||
|
|
||||||
|
encode-string-child
|
||||||
|
(encoder kind string-transformer)
|
||||||
|
|
||||||
|
encode-string
|
||||||
|
(fn [o]
|
||||||
|
(if (set? o)
|
||||||
|
(str/join ", " (map encode-string-child o))
|
||||||
|
o))
|
||||||
|
|
||||||
encode-json
|
encode-json
|
||||||
(fn [o]
|
(fn [o]
|
||||||
(if (set? o)
|
(if (set? o)
|
||||||
(vec o)
|
(vec o)
|
||||||
o))
|
|
||||||
|
|
||||||
encode-string
|
|
||||||
(fn [o]
|
|
||||||
(if (set? o)
|
|
||||||
(str/join ", " (map encode-child o))
|
|
||||||
o))]
|
o))]
|
||||||
|
|
||||||
|
|
||||||
{:pred pred
|
{:pred pred
|
||||||
:type-properties
|
:type-properties
|
||||||
{:title "set"
|
{:title "set"
|
||||||
:description "Set of Strings"
|
:description "Set of Strings"
|
||||||
:error/message "should be a set of strings"
|
:error/message "should be a set of strings"
|
||||||
:gen/gen (-> kind sg/generator sg/set)
|
:gen/gen (-> kind sg/generator sg/set)
|
||||||
:decode/string decode
|
:decode/string decode-string
|
||||||
:decode/json decode
|
:decode/json decode-json
|
||||||
:encode/string encode-string
|
:encode/string encode-string
|
||||||
:encode/json encode-json
|
:encode/json encode-json
|
||||||
::oapi/type "array"
|
::oapi/type "array"
|
||||||
|
@ -569,21 +581,14 @@
|
||||||
:min 0
|
:min 0
|
||||||
:max 1
|
:max 1
|
||||||
:compile
|
:compile
|
||||||
(fn [{:keys [coerce kind max min] :as props} children _]
|
(fn [{:keys [kind max min] :as props} children _]
|
||||||
(let [xform (if coerce
|
(let [kind (or (last children) kind)
|
||||||
(comp non-empty-strings-xf (map coerce))
|
|
||||||
non-empty-strings-xf)
|
|
||||||
|
|
||||||
kind (or (last children) kind)
|
|
||||||
pred
|
pred
|
||||||
(cond
|
(cond
|
||||||
(fn? kind) kind
|
(fn? kind) kind
|
||||||
(nil? kind) any?
|
(nil? kind) any?
|
||||||
:else (validator kind))
|
:else (validator kind))
|
||||||
|
|
||||||
encode-child
|
|
||||||
(encoder kind string-transformer)
|
|
||||||
|
|
||||||
pred
|
pred
|
||||||
(cond
|
(cond
|
||||||
(and max min)
|
(and max min)
|
||||||
|
@ -611,15 +616,31 @@
|
||||||
(fn [value]
|
(fn [value]
|
||||||
(every? pred value)))
|
(every? pred value)))
|
||||||
|
|
||||||
decode
|
decode-string-child
|
||||||
|
(decoder kind string-transformer)
|
||||||
|
|
||||||
|
decode-json-child
|
||||||
|
(decoder kind json-transformer)
|
||||||
|
|
||||||
|
decode-string
|
||||||
(fn [v]
|
(fn [v]
|
||||||
(let [v (if (string? v) (str/split v #"[\s,]+") v)]
|
(let [v (if (string? v) (str/split v #"[\s,]+") v)
|
||||||
(into [] xform v)))
|
x (comp xf:filter-word-strings (map decode-string-child))]
|
||||||
|
(into #{} x v)))
|
||||||
|
|
||||||
|
decode-json
|
||||||
|
(fn [v]
|
||||||
|
(let [v (if (string? v) (str/split v #"[\s,]+") v)
|
||||||
|
x (comp xf:filter-word-strings (map decode-json-child))]
|
||||||
|
(into #{} x v)))
|
||||||
|
|
||||||
|
encode-string-child
|
||||||
|
(encoder kind string-transformer)
|
||||||
|
|
||||||
encode-string
|
encode-string
|
||||||
(fn [o]
|
(fn [o]
|
||||||
(if (vector? o)
|
(if (vector? o)
|
||||||
(str/join ", " (map encode-child o))
|
(str/join ", " (map encode-string-child o))
|
||||||
o))]
|
o))]
|
||||||
|
|
||||||
{:pred pred
|
{:pred pred
|
||||||
|
@ -628,8 +649,8 @@
|
||||||
:description "Set of Strings"
|
:description "Set of Strings"
|
||||||
:error/message "should be a set of strings"
|
:error/message "should be a set of strings"
|
||||||
:gen/gen (-> kind sg/generator sg/set)
|
:gen/gen (-> kind sg/generator sg/set)
|
||||||
:decode/string decode
|
:decode/string decode-string
|
||||||
:decode/json decode
|
:decode/json decode-json
|
||||||
:encode/string encode-string
|
:encode/string encode-string
|
||||||
::oapi/type "array"
|
::oapi/type "array"
|
||||||
::oapi/format "set"
|
::oapi/format "set"
|
||||||
|
@ -646,7 +667,7 @@
|
||||||
:gen/gen (-> :string sg/generator sg/set)
|
:gen/gen (-> :string sg/generator sg/set)
|
||||||
:decode/string (fn [v]
|
:decode/string (fn [v]
|
||||||
(let [v (if (string? v) (str/split v #"[\s,]+") v)]
|
(let [v (if (string? v) (str/split v #"[\s,]+") v)]
|
||||||
(into #{} non-empty-strings-xf v)))
|
(into #{} xf:filter-word-strings v)))
|
||||||
::oapi/type "array"
|
::oapi/type "array"
|
||||||
::oapi/format "set"
|
::oapi/format "set"
|
||||||
::oapi/items {:type "string"}
|
::oapi/items {:type "string"}
|
||||||
|
@ -662,7 +683,7 @@
|
||||||
:gen/gen (-> :keyword sg/generator sg/set)
|
:gen/gen (-> :keyword sg/generator sg/set)
|
||||||
:decode/string (fn [v]
|
:decode/string (fn [v]
|
||||||
(let [v (if (string? v) (str/split v #"[\s,]+") v)]
|
(let [v (if (string? v) (str/split v #"[\s,]+") v)]
|
||||||
(into #{} (comp non-empty-strings-xf (map keyword)) v)))
|
(into #{} (comp xf:filter-word-strings (map keyword)) v)))
|
||||||
::oapi/type "array"
|
::oapi/type "array"
|
||||||
::oapi/format "set"
|
::oapi/format "set"
|
||||||
::oapi/items {:type "string" :format "keyword"}
|
::oapi/items {:type "string" :format "keyword"}
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
[app.main.data.events :as ev]
|
[app.main.data.events :as ev]
|
||||||
[app.util.browser-history :as bhistory]
|
[app.util.browser-history :as bhistory]
|
||||||
[app.util.dom :as dom]
|
[app.util.dom :as dom]
|
||||||
[app.util.globals :as globals]
|
[app.util.globals :as globals]
|
||||||
[app.util.timers :as ts]
|
[app.util.timers :as ts]
|
||||||
[beicon.v2.core :as rx]
|
[beicon.v2.core :as rx]
|
||||||
[cuerdas.core :as str]
|
[cuerdas.core :as str]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue