mirror of
https://github.com/penpot/penpot.git
synced 2025-01-22 14:39:45 -05:00
Merge pull request #5076 from penpot/niwinz-exporter-config-parse
🐛 Fix issues on parsing configuration on exporter
This commit is contained in:
commit
133ca33cb5
3 changed files with 85 additions and 56 deletions
|
@ -476,7 +476,7 @@
|
|||
::oapi/type "string"
|
||||
::oapi/format "email"}})
|
||||
|
||||
(def non-empty-strings-xf
|
||||
(def xf:filter-word-strings
|
||||
(comp
|
||||
(filter string?)
|
||||
(remove str/empty?)
|
||||
|
@ -489,11 +489,8 @@
|
|||
:min 0
|
||||
:max 1
|
||||
:compile
|
||||
(fn [{:keys [coerce kind max min] :as props} children _]
|
||||
(let [xform (if coerce
|
||||
(comp non-empty-strings-xf (map coerce))
|
||||
non-empty-strings-xf)
|
||||
kind (or (last children) kind)
|
||||
(fn [{:keys [kind max min] :as props} children _]
|
||||
(let [kind (or (last children) kind)
|
||||
|
||||
pred
|
||||
(cond
|
||||
|
@ -501,9 +498,6 @@
|
|||
(nil? kind) any?
|
||||
:else (validator kind))
|
||||
|
||||
encode-child
|
||||
(encoder kind string-transformer)
|
||||
|
||||
pred
|
||||
(cond
|
||||
(and max min)
|
||||
|
@ -531,31 +525,49 @@
|
|||
(fn [value]
|
||||
(every? pred value)))
|
||||
|
||||
decode
|
||||
|
||||
decode-string-child
|
||||
(decoder kind string-transformer)
|
||||
|
||||
decode-string
|
||||
(fn [v]
|
||||
(let [v (if (string? v) (str/split v #"[\s,]+") v)]
|
||||
(into #{} xform v)))
|
||||
(let [v (if (string? v) (str/split v #"[\s,]+") 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
|
||||
(fn [o]
|
||||
(if (set? o)
|
||||
(vec o)
|
||||
o))
|
||||
|
||||
encode-string
|
||||
(fn [o]
|
||||
(if (set? o)
|
||||
(str/join ", " (map encode-child o))
|
||||
o))]
|
||||
|
||||
|
||||
{:pred pred
|
||||
:type-properties
|
||||
{:title "set"
|
||||
:description "Set of Strings"
|
||||
:error/message "should be a set of strings"
|
||||
:gen/gen (-> kind sg/generator sg/set)
|
||||
:decode/string decode
|
||||
:decode/json decode
|
||||
:decode/string decode-string
|
||||
:decode/json decode-json
|
||||
:encode/string encode-string
|
||||
:encode/json encode-json
|
||||
::oapi/type "array"
|
||||
|
@ -569,21 +581,14 @@
|
|||
:min 0
|
||||
:max 1
|
||||
:compile
|
||||
(fn [{:keys [coerce kind max min] :as props} children _]
|
||||
(let [xform (if coerce
|
||||
(comp non-empty-strings-xf (map coerce))
|
||||
non-empty-strings-xf)
|
||||
|
||||
kind (or (last children) kind)
|
||||
(fn [{:keys [kind max min] :as props} children _]
|
||||
(let [kind (or (last children) kind)
|
||||
pred
|
||||
(cond
|
||||
(fn? kind) kind
|
||||
(nil? kind) any?
|
||||
:else (validator kind))
|
||||
|
||||
encode-child
|
||||
(encoder kind string-transformer)
|
||||
|
||||
pred
|
||||
(cond
|
||||
(and max min)
|
||||
|
@ -611,15 +616,31 @@
|
|||
(fn [value]
|
||||
(every? pred value)))
|
||||
|
||||
decode
|
||||
decode-string-child
|
||||
(decoder kind string-transformer)
|
||||
|
||||
decode-json-child
|
||||
(decoder kind json-transformer)
|
||||
|
||||
decode-string
|
||||
(fn [v]
|
||||
(let [v (if (string? v) (str/split v #"[\s,]+") v)]
|
||||
(into [] xform v)))
|
||||
(let [v (if (string? v) (str/split v #"[\s,]+") 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
|
||||
(fn [o]
|
||||
(if (vector? o)
|
||||
(str/join ", " (map encode-child o))
|
||||
(str/join ", " (map encode-string-child o))
|
||||
o))]
|
||||
|
||||
{:pred pred
|
||||
|
@ -628,8 +649,8 @@
|
|||
:description "Set of Strings"
|
||||
:error/message "should be a set of strings"
|
||||
:gen/gen (-> kind sg/generator sg/set)
|
||||
:decode/string decode
|
||||
:decode/json decode
|
||||
:decode/string decode-string
|
||||
:decode/json decode-json
|
||||
:encode/string encode-string
|
||||
::oapi/type "array"
|
||||
::oapi/format "set"
|
||||
|
@ -646,7 +667,7 @@
|
|||
:gen/gen (-> :string sg/generator sg/set)
|
||||
:decode/string (fn [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/format "set"
|
||||
::oapi/items {:type "string"}
|
||||
|
@ -662,7 +683,7 @@
|
|||
:gen/gen (-> :keyword sg/generator sg/set)
|
||||
:decode/string (fn [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/format "set"
|
||||
::oapi/items {:type "string" :format "keyword"}
|
||||
|
|
|
@ -26,16 +26,24 @@
|
|||
|
||||
(def ^:private
|
||||
schema:config
|
||||
(sm/define
|
||||
[:map {:title "config"}
|
||||
[:public-uri {:optional true} ::sm/uri]
|
||||
[:host {:optional true} :string]
|
||||
[:tenant {:optional true} :string]
|
||||
[:flags {:optional true} ::sm/set-of-keywords]
|
||||
[:redis-uri {:optional true} :string]
|
||||
[:tempdir {:optional true} :string]
|
||||
[:browser-pool-max {:optional true} :int]
|
||||
[:browser-pool-min {:optional true} :int]]))
|
||||
[:map {:title "config"}
|
||||
[:public-uri {:optional true} ::sm/uri]
|
||||
[:host {:optional true} :string]
|
||||
[:tenant {:optional true} :string]
|
||||
[:flags {:optional true} [::sm/set :keyword]]
|
||||
[:redis-uri {:optional true} :string]
|
||||
[:tempdir {:optional true} :string]
|
||||
[:browser-pool-max {:optional true} ::sm/int]
|
||||
[:browser-pool-min {:optional true} ::sm/int]])
|
||||
|
||||
(def ^:private decode-config
|
||||
(sm/decoder schema:config sm/string-transformer))
|
||||
|
||||
(def ^:private explain-config
|
||||
(sm/explainer schema:config))
|
||||
|
||||
(def ^:private valid-config?
|
||||
(sm/validator schema:config))
|
||||
|
||||
(defn- parse-flags
|
||||
[config]
|
||||
|
@ -60,15 +68,15 @@
|
|||
[]
|
||||
(let [env (read-env "penpot")
|
||||
env (d/without-nils env)
|
||||
data (merge defaults env)]
|
||||
data (merge defaults env)
|
||||
data (decode-config data)]
|
||||
|
||||
(try
|
||||
(sm/conform! schema:config data)
|
||||
(catch :default cause
|
||||
(if-let [explain (some->> cause ex-data ::sm/explain)]
|
||||
(println (sm/humanize-explain explain))
|
||||
(js/console.error cause))
|
||||
(process/exit -1)))))
|
||||
(when-not (valid-config? data)
|
||||
(let [explain (explain-config data)]
|
||||
(println (sm/humanize-explain explain))
|
||||
(process/exit -1)))
|
||||
|
||||
data))
|
||||
|
||||
(def config
|
||||
(prepare-config))
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
[app.main.data.events :as ev]
|
||||
[app.util.browser-history :as bhistory]
|
||||
[app.util.dom :as dom]
|
||||
[app.util.globals :as globals]
|
||||
[app.util.globals :as globals]
|
||||
[app.util.timers :as ts]
|
||||
[beicon.v2.core :as rx]
|
||||
[cuerdas.core :as str]
|
||||
|
|
Loading…
Add table
Reference in a new issue