mirror of
https://github.com/penpot/penpot.git
synced 2025-07-31 05:58:46 +02:00
♻️ Replace :any schema with own ::sm/any
That a more specific, json friendly generator
This commit is contained in:
parent
d33a5e6df1
commit
3224ba26f1
9 changed files with 61 additions and 39 deletions
|
@ -92,9 +92,9 @@
|
||||||
[:string {:max 250}]
|
[:string {:max 250}]
|
||||||
[::sm/one-of {:format "string"} valid-event-types]]]
|
[::sm/one-of {:format "string"} valid-event-types]]]
|
||||||
[:props
|
[:props
|
||||||
[:map-of :keyword :any]]
|
[:map-of :keyword ::sm/any]]
|
||||||
[:context {:optional true}
|
[:context {:optional true}
|
||||||
[:map-of :keyword :any]]])
|
[:map-of :keyword ::sm/any]]])
|
||||||
|
|
||||||
(def schema:push-audit-events
|
(def schema:push-audit-events
|
||||||
[:map {:title "push-audit-events"}
|
[:map {:title "push-audit-events"}
|
||||||
|
|
|
@ -189,7 +189,7 @@
|
||||||
[:is-shared ::sm/boolean]
|
[:is-shared ::sm/boolean]
|
||||||
[:project-id ::sm/uuid]
|
[:project-id ::sm/uuid]
|
||||||
[:created-at ::dt/instant]
|
[:created-at ::dt/instant]
|
||||||
[:data {:optional true} :any]])
|
[:data {:optional true} ::sm/any]])
|
||||||
|
|
||||||
(def schema:permissions-mixin
|
(def schema:permissions-mixin
|
||||||
[:map {:title "PermissionsMixin"}
|
[:map {:title "PermissionsMixin"}
|
||||||
|
|
|
@ -80,9 +80,9 @@
|
||||||
(def ^:private schema:create-font-variant
|
(def ^:private schema:create-font-variant
|
||||||
[:map {:title "create-font-variant"}
|
[:map {:title "create-font-variant"}
|
||||||
[:team-id ::sm/uuid]
|
[:team-id ::sm/uuid]
|
||||||
[:data [:map-of :string :any]]
|
[:data [:map-of ::sm/text ::sm/any]]
|
||||||
[:font-id ::sm/uuid]
|
[:font-id ::sm/uuid]
|
||||||
[:font-family :string]
|
[:font-family ::sm/text]
|
||||||
[:font-weight [::sm/one-of {:format "number"} valid-weight]]
|
[:font-weight [::sm/one-of {:format "number"} valid-weight]]
|
||||||
[:font-style [::sm/one-of {:format "string"} valid-style]]])
|
[:font-style [::sm/one-of {:format "string"} valid-style]]])
|
||||||
|
|
||||||
|
|
|
@ -47,14 +47,14 @@
|
||||||
[:type [:= :assign]]
|
[:type [:= :assign]]
|
||||||
;; NOTE: the full decoding is happening on the handler because it
|
;; NOTE: the full decoding is happening on the handler because it
|
||||||
;; needs a proper context of the current shape and its type
|
;; needs a proper context of the current shape and its type
|
||||||
[:value [:map-of :keyword :any]]
|
[:value [:map-of :keyword ::sm/any]]
|
||||||
[:ignore-touched {:optional true} :boolean]
|
[:ignore-touched {:optional true} :boolean]
|
||||||
[:ignore-geometry {:optional true} :boolean]]]
|
[:ignore-geometry {:optional true} :boolean]]]
|
||||||
[:set
|
[:set
|
||||||
[:map {:title "SetOperation"}
|
[:map {:title "SetOperation"}
|
||||||
[:type [:= :set]]
|
[:type [:= :set]]
|
||||||
[:attr :keyword]
|
[:attr :keyword]
|
||||||
[:val :any]
|
[:val ::sm/any]
|
||||||
[:ignore-touched {:optional true} :boolean]
|
[:ignore-touched {:optional true} :boolean]
|
||||||
[:ignore-geometry {:optional true} :boolean]]]
|
[:ignore-geometry {:optional true} :boolean]]]
|
||||||
[:set-touched
|
[:set-touched
|
||||||
|
@ -238,9 +238,9 @@
|
||||||
[:component-id {:optional true} ::sm/uuid]
|
[:component-id {:optional true} ::sm/uuid]
|
||||||
[:ignore-touched {:optional true} :boolean]
|
[:ignore-touched {:optional true} :boolean]
|
||||||
[:parent-id ::sm/uuid]
|
[:parent-id ::sm/uuid]
|
||||||
[:shapes :any]
|
[:shapes ::sm/any]
|
||||||
[:index {:optional true} [:maybe :int]]
|
[:index {:optional true} [:maybe :int]]
|
||||||
[:after-shape {:optional true} :any]
|
[:after-shape {:optional true} ::sm/any]
|
||||||
[:component-swap {:optional true} :boolean]]]
|
[:component-swap {:optional true} :boolean]]]
|
||||||
|
|
||||||
[:reorder-children
|
[:reorder-children
|
||||||
|
@ -250,14 +250,14 @@
|
||||||
[:component-id {:optional true} ::sm/uuid]
|
[:component-id {:optional true} ::sm/uuid]
|
||||||
[:ignore-touched {:optional true} :boolean]
|
[:ignore-touched {:optional true} :boolean]
|
||||||
[:parent-id ::sm/uuid]
|
[:parent-id ::sm/uuid]
|
||||||
[:shapes :any]]]
|
[:shapes ::sm/any]]]
|
||||||
|
|
||||||
[:add-page
|
[:add-page
|
||||||
[:map {:title "AddPageChange"}
|
[:map {:title "AddPageChange"}
|
||||||
[:type [:= :add-page]]
|
[:type [:= :add-page]]
|
||||||
[:id {:optional true} ::sm/uuid]
|
[:id {:optional true} ::sm/uuid]
|
||||||
[:name {:optional true} :string]
|
[:name {:optional true} :string]
|
||||||
[:page {:optional true} :any]]]
|
[:page {:optional true} ::sm/any]]]
|
||||||
|
|
||||||
[:mod-page
|
[:mod-page
|
||||||
[:map {:title "ModPageChange"}
|
[:map {:title "ModPageChange"}
|
||||||
|
@ -327,14 +327,14 @@
|
||||||
[:type [:= :add-component]]
|
[:type [:= :add-component]]
|
||||||
[:id ::sm/uuid]
|
[:id ::sm/uuid]
|
||||||
[:name :string]
|
[:name :string]
|
||||||
[:shapes {:optional true} [:vector {:gen/max 3} :any]]
|
[:shapes {:optional true} [:vector {:gen/max 3} ::sm/any]]
|
||||||
[:path {:optional true} :string]]]
|
[:path {:optional true} :string]]]
|
||||||
|
|
||||||
[:mod-component
|
[:mod-component
|
||||||
[:map {:title "ModCompoenentChange"}
|
[:map {:title "ModCompoenentChange"}
|
||||||
[:type [:= :mod-component]]
|
[:type [:= :mod-component]]
|
||||||
[:id ::sm/uuid]
|
[:id ::sm/uuid]
|
||||||
[:shapes {:optional true} [:vector {:gen/max 3} :any]]
|
[:shapes {:optional true} [:vector {:gen/max 3} ::sm/any]]
|
||||||
[:name {:optional true} :string]
|
[:name {:optional true} :string]
|
||||||
[:variant-id {:optional true} ::sm/uuid]
|
[:variant-id {:optional true} ::sm/uuid]
|
||||||
[:variant-properties {:optional true} [:vector ::ctv/variant-property]]]]
|
[:variant-properties {:optional true} [:vector ::ctv/variant-property]]]]
|
||||||
|
@ -411,7 +411,7 @@
|
||||||
[:set-tokens-lib
|
[:set-tokens-lib
|
||||||
[:map {:title "SetTokensLib"}
|
[:map {:title "SetTokensLib"}
|
||||||
[:type [:= :set-tokens-lib]]
|
[:type [:= :set-tokens-lib]]
|
||||||
[:tokens-lib :any]]]
|
[:tokens-lib ::sm/any]]]
|
||||||
|
|
||||||
[:set-token-set
|
[:set-token-set
|
||||||
[:map {:title "SetTokenSetChange"}
|
[:map {:title "SetTokenSetChange"}
|
||||||
|
|
|
@ -25,18 +25,19 @@
|
||||||
|
|
||||||
;; Auxiliary functions to help create a set of changes (undo + redo)
|
;; Auxiliary functions to help create a set of changes (undo + redo)
|
||||||
|
|
||||||
(sm/register!
|
(def schema:changes
|
||||||
^{::sm/type ::changes}
|
(sm/register!
|
||||||
[:map {:title "changes"}
|
^{::sm/type ::changes}
|
||||||
[:redo-changes vector?]
|
[:map {:title "changes"}
|
||||||
[:undo-changes seq?]
|
[:redo-changes vector?]
|
||||||
[:origin {:optional true} any?]
|
[:undo-changes seq?]
|
||||||
[:save-undo? {:optional true} boolean?]
|
[:origin {:optional true} ::sm/any]
|
||||||
[:stack-undo? {:optional true} boolean?]
|
[:save-undo? {:optional true} boolean?]
|
||||||
[:undo-group {:optional true} any?]])
|
[:stack-undo? {:optional true} boolean?]
|
||||||
|
[:undo-group {:optional true} ::sm/any]]))
|
||||||
|
|
||||||
(def check-changes!
|
(def check-changes!
|
||||||
(sm/check-fn ::changes))
|
(sm/check-fn schema:changes))
|
||||||
|
|
||||||
(defn empty-changes
|
(defn empty-changes
|
||||||
([origin page-id]
|
([origin page-id]
|
||||||
|
|
|
@ -1045,6 +1045,8 @@
|
||||||
{:title "agent"
|
{:title "agent"
|
||||||
:description "instance of clojure agent"}}))
|
:description "instance of clojure agent"}}))
|
||||||
|
|
||||||
|
(register! ::any (mu/update-properties :any assoc :gen/gen sg/any))
|
||||||
|
|
||||||
;; ---- PREDICATES
|
;; ---- PREDICATES
|
||||||
|
|
||||||
(def valid-safe-number?
|
(def valid-safe-number?
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
;; Copyright (c) KALEIDOS INC
|
;; Copyright (c) KALEIDOS INC
|
||||||
|
|
||||||
(ns app.common.schema.generators
|
(ns app.common.schema.generators
|
||||||
(:refer-clojure :exclude [set subseq uuid filter map let boolean])
|
(:refer-clojure :exclude [set subseq uuid filter map let boolean vector keyword int double])
|
||||||
#?(:cljs (:require-macros [app.common.schema.generators]))
|
#?(:cljs (:require-macros [app.common.schema.generators]))
|
||||||
(:require
|
(:require
|
||||||
[app.common.schema.registry :as sr]
|
[app.common.schema.registry :as sr]
|
||||||
|
@ -38,10 +38,6 @@
|
||||||
([s opts]
|
([s opts]
|
||||||
(mg/generator s (assoc opts :registry sr/default-registry))))
|
(mg/generator s (assoc opts :registry sr/default-registry))))
|
||||||
|
|
||||||
(defn filter
|
|
||||||
[pred gen]
|
|
||||||
(tg/such-that pred gen 100))
|
|
||||||
|
|
||||||
(defn small-double
|
(defn small-double
|
||||||
[& {:keys [min max] :or {min -100 max 100}}]
|
[& {:keys [min max] :or {min -100 max 100}}]
|
||||||
(tg/double* {:min min, :max max, :infinite? false, :NaN? false}))
|
(tg/double* {:min min, :max max, :infinite? false, :NaN? false}))
|
||||||
|
@ -61,7 +57,7 @@
|
||||||
(defn word-keyword
|
(defn word-keyword
|
||||||
[]
|
[]
|
||||||
(->> (word-string)
|
(->> (word-string)
|
||||||
(tg/fmap keyword)))
|
(tg/fmap c/keyword)))
|
||||||
|
|
||||||
(defn email
|
(defn email
|
||||||
[]
|
[]
|
||||||
|
@ -100,12 +96,11 @@
|
||||||
(c/map second))
|
(c/map second))
|
||||||
(c/map list bools elements)))))))
|
(c/map list bools elements)))))))
|
||||||
|
|
||||||
(def any tg/any)
|
(defn map-of
|
||||||
(def boolean tg/boolean)
|
([kg vg]
|
||||||
|
(tg/map kg vg {:min-elements 1 :max-elements 3}))
|
||||||
(defn set
|
([kg vg opts]
|
||||||
[g]
|
(tg/map kg vg opts)))
|
||||||
(tg/set g))
|
|
||||||
|
|
||||||
(defn elements
|
(defn elements
|
||||||
[s]
|
[s]
|
||||||
|
@ -119,6 +114,10 @@
|
||||||
[f g]
|
[f g]
|
||||||
(tg/fmap f g))
|
(tg/fmap f g))
|
||||||
|
|
||||||
|
(defn filter
|
||||||
|
[pred gen]
|
||||||
|
(tg/such-that pred gen 100))
|
||||||
|
|
||||||
(defn mcat
|
(defn mcat
|
||||||
[f g]
|
[f g]
|
||||||
(tg/bind g f))
|
(tg/bind g f))
|
||||||
|
@ -126,3 +125,22 @@
|
||||||
(defn tuple
|
(defn tuple
|
||||||
[& opts]
|
[& opts]
|
||||||
(apply tg/tuple opts))
|
(apply tg/tuple opts))
|
||||||
|
|
||||||
|
(defn vector
|
||||||
|
[& opts]
|
||||||
|
(apply tg/vector opts))
|
||||||
|
|
||||||
|
(defn set
|
||||||
|
[g]
|
||||||
|
(tg/set g))
|
||||||
|
|
||||||
|
;; Static Generators
|
||||||
|
|
||||||
|
(def boolean tg/boolean)
|
||||||
|
(def text (word-string))
|
||||||
|
(def double (small-double))
|
||||||
|
(def int (small-int))
|
||||||
|
(def keyword (word-keyword))
|
||||||
|
|
||||||
|
(def any
|
||||||
|
(tg/one-of [text boolean double int keyword]))
|
||||||
|
|
|
@ -35,7 +35,7 @@
|
||||||
(.. r (toString 16) (padStart 2 "0"))
|
(.. r (toString 16) (padStart 2 "0"))
|
||||||
(.. g (toString 16) (padStart 2 "0"))
|
(.. g (toString 16) (padStart 2 "0"))
|
||||||
(.. b (toString 16) (padStart 2 "0"))))))
|
(.. b (toString 16) (padStart 2 "0"))))))
|
||||||
sg/any))
|
sg/int))
|
||||||
|
|
||||||
(defn rgb-color-string?
|
(defn rgb-color-string?
|
||||||
[o]
|
[o]
|
||||||
|
|
|
@ -118,7 +118,7 @@
|
||||||
[:map {:title "Token"}
|
[:map {:title "Token"}
|
||||||
[:name cto/token-name-ref]
|
[:name cto/token-name-ref]
|
||||||
[:type [::sm/one-of cto/token-types]]
|
[:type [::sm/one-of cto/token-types]]
|
||||||
[:value :any]
|
[:value ::sm/any]
|
||||||
[:description {:optional true} :string]
|
[:description {:optional true} :string]
|
||||||
[:modified-at {:optional true} ::sm/inst]])
|
[:modified-at {:optional true} ::sm/inst]])
|
||||||
|
|
||||||
|
@ -389,7 +389,8 @@
|
||||||
[:description {:optional true} :string]
|
[:description {:optional true} :string]
|
||||||
[:modified-at {:optional true} ::sm/inst]
|
[:modified-at {:optional true} ::sm/inst]
|
||||||
[:tokens {:optional true
|
[:tokens {:optional true
|
||||||
:gen/gen (->> (sg/generator [:map-of ::sm/text schema:token])
|
:gen/gen (->> (sg/map-of (sg/generator ::sm/text)
|
||||||
|
(sg/generator schema:token))
|
||||||
(sg/fmap #(into (d/ordered-map) %)))}
|
(sg/fmap #(into (d/ordered-map) %)))}
|
||||||
[:and
|
[:and
|
||||||
[:map-of {:gen/max 5
|
[:map-of {:gen/max 5
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue