diff --git a/backend/src/uxbox/config.clj b/backend/src/uxbox/config.clj index 795c563cb..803b61261 100644 --- a/backend/src/uxbox/config.clj +++ b/backend/src/uxbox/config.clj @@ -6,15 +6,15 @@ (ns uxbox.config "A configuration management." - (:require [clojure.java.io :as io] - [clojure.tools.logging :as log] - [clojure.edn :as edn] - [cuerdas.core :as str] - [buddy.core.hash :as hash] - [environ.core :refer [env]] - [mount.core :refer [defstate]] - [uxbox.util.exceptions :as ex] - [uxbox.util.data :refer [deep-merge]])) + (:require + [clojure.java.io :as io] + [clojure.tools.logging :as log] + [clojure.edn :as edn] + [cuerdas.core :as str] + [buddy.core.hash :as hash] + [environ.core :refer [env]] + [mount.core :refer [defstate]] + [uxbox.common.exceptions :as ex])) ;; --- Configuration Reading & Loading diff --git a/backend/src/uxbox/db.clj b/backend/src/uxbox/db.clj index 84d92e026..04d09681a 100644 --- a/backend/src/uxbox/db.clj +++ b/backend/src/uxbox/db.clj @@ -10,10 +10,10 @@ [lambdaisland.uri :refer [uri]] [mount.core :as mount :refer [defstate]] [promesa.core :as p] + [uxbox.common.exceptions :as ex] [uxbox.config :as cfg] [uxbox.core :refer [system]] [uxbox.util.data :as data] - [uxbox.util.exceptions :as ex] [uxbox.util.pgsql :as pg] [vertx.core :as vx]) (:import io.vertx.core.buffer.Buffer)) diff --git a/backend/src/uxbox/emails.clj b/backend/src/uxbox/emails.clj index 8a206eaf3..51d1c5436 100644 --- a/backend/src/uxbox/emails.clj +++ b/backend/src/uxbox/emails.clj @@ -10,12 +10,12 @@ [clojure.spec.alpha :as s] [promesa.core :as p] [uxbox.config :as cfg] + [uxbox.common.exceptions :as ex] + [uxbox.common.spec :as us] [uxbox.db :as db] [uxbox.media :as media] - [uxbox.util.exceptions :as ex] [uxbox.util.emails :as emails] - [uxbox.util.blob :as blob] - [uxbox.util.spec :as us])) + [uxbox.util.blob :as blob])) ;; --- Defaults @@ -44,8 +44,8 @@ (defn send! "Schedule the email for sending." [email context] - (s/assert fn? email) - (s/assert map? context) + (us/assert fn? email) + (us/assert map? context) (let [defaults {:from (:email-from cfg/config) :reply-to (:email-reply-to cfg/config)} data (->> (merge defaults context) diff --git a/backend/src/uxbox/http/interceptors.clj b/backend/src/uxbox/http/interceptors.clj index 45a33aef3..eff7fb232 100644 --- a/backend/src/uxbox/http/interceptors.clj +++ b/backend/src/uxbox/http/interceptors.clj @@ -7,8 +7,8 @@ (ns uxbox.http.interceptors (:require [vertx.web :as vw] - [uxbox.util.transit :as t] - [uxbox.util.exceptions :as ex]) + [uxbox.common.exceptions :as ex] + [uxbox.util.transit :as t]) (:import io.vertx.ext.web.RoutingContext io.vertx.ext.web.FileUpload diff --git a/backend/src/uxbox/http/session.clj b/backend/src/uxbox/http/session.clj index f85b12867..877138948 100644 --- a/backend/src/uxbox/http/session.clj +++ b/backend/src/uxbox/http/session.clj @@ -10,7 +10,6 @@ [sieppari.context :as spx] [vertx.core :as vc] [uxbox.db :as db] - [uxbox.util.exceptions :as ex] [uxbox.util.uuid :as uuid])) ;; --- Main API diff --git a/backend/src/uxbox/images.clj b/backend/src/uxbox/images.clj index 6b2c7633a..540ab8a44 100644 --- a/backend/src/uxbox/images.clj +++ b/backend/src/uxbox/images.clj @@ -12,9 +12,9 @@ [datoteka.core :as fs] [datoteka.proto :as pt] [datoteka.storages :as st] - [uxbox.media :as media] - [uxbox.util.data :refer (dissoc-in)] - [uxbox.util.spec :as us]) + [uxbox.common.data :as d] + [uxbox.common.spec :as us] + [uxbox.media :as media]) (:import java.io.ByteArrayInputStream java.io.InputStream @@ -43,8 +43,8 @@ width 200 height 200} :as opts}] - (s/assert ::thumbnail-opts opts) - (s/assert fs/path? input) + (us/assert ::thumbnail-opts opts) + (us/assert fs/path? input) (let [tmp (fs/create-tempfile :suffix (str "." format)) opr (doto (IMOperation.) (.addImage) @@ -60,7 +60,7 @@ (defn make-thumbnail [input {:keys [width height format quality] :as opts}] - (s/assert ::thumbnail-opts opts) + (us/assert ::thumbnail-opts opts) (let [[filename ext] (fs/split-ext (fs/name input)) suffix (->> [width height quality format] (interpose ".") @@ -102,6 +102,6 @@ entry (let [url (str (st/public-url storage value))] (-> entry - (dissoc-in src) + (d/dissoc-in src) (assoc-in dst url)))))) diff --git a/backend/src/uxbox/jobs/sendmail.clj b/backend/src/uxbox/jobs/sendmail.clj index 75e82a864..6435133b5 100644 --- a/backend/src/uxbox/jobs/sendmail.clj +++ b/backend/src/uxbox/jobs/sendmail.clj @@ -12,11 +12,11 @@ [promesa.core :as p] [uxbox.core :refer [system]] [postal.core :as postal] + [uxbox.common.exceptions :as ex] [uxbox.config :as cfg] [uxbox.db :as db] [uxbox.util.jobs :as uj] [uxbox.util.blob :as blob] - [uxbox.util.exceptions :as ex] [mount.core :as mount :refer [defstate]])) ;; TODO: implement low priority sending emails. diff --git a/backend/src/uxbox/media_loader.clj b/backend/src/uxbox/media_loader.clj index d111ba88c..896afa814 100644 --- a/backend/src/uxbox/media_loader.clj +++ b/backend/src/uxbox/media_loader.clj @@ -18,13 +18,13 @@ [datoteka.storages :as st] [datoteka.core :as fs] [uxbox.config] + [uxbox.common.spec :as us] [uxbox.db :as db] [uxbox.http] [uxbox.migrations] [uxbox.media :as media] [uxbox.util.svg :as svg] [uxbox.util.transit :as t] - [uxbox.util.spec :as us] [uxbox.util.blob :as blob] [uxbox.util.uuid :as uuid] [uxbox.util.data :as data]) diff --git a/backend/src/uxbox/services/mutations.clj b/backend/src/uxbox/services/mutations.clj index 6bfa98c50..3aba95007 100644 --- a/backend/src/uxbox/services/mutations.clj +++ b/backend/src/uxbox/services/mutations.clj @@ -6,8 +6,7 @@ (ns uxbox.services.mutations (:require - [uxbox.util.dispatcher :as uds] - [uxbox.util.exceptions :as ex])) + [uxbox.util.dispatcher :as uds])) (uds/defservice handle {:dispatch-by ::type diff --git a/backend/src/uxbox/services/mutations/auth.clj b/backend/src/uxbox/services/mutations/auth.clj index fa26f75b0..9011dfc01 100644 --- a/backend/src/uxbox/services/mutations/auth.clj +++ b/backend/src/uxbox/services/mutations/auth.clj @@ -10,10 +10,10 @@ [buddy.hashers :as hashers] [promesa.core :as p] [uxbox.config :as cfg] + [uxbox.common.exceptions :as ex] + [uxbox.common.spec :as us] [uxbox.db :as db] - [uxbox.services.mutations :as sm] - [uxbox.util.spec :as us] - [uxbox.util.exceptions :as ex])) + [uxbox.services.mutations :as sm])) (def ^:private user-by-username-sql "select id, password diff --git a/backend/src/uxbox/services/mutations/icons.clj b/backend/src/uxbox/services/mutations/icons.clj index d9c306526..304d1b3f5 100644 --- a/backend/src/uxbox/services/mutations/icons.clj +++ b/backend/src/uxbox/services/mutations/icons.clj @@ -9,11 +9,11 @@ [clojure.spec.alpha :as s] [promesa.core :as p] [uxbox.db :as db] + [uxbox.common.spec :as us] [uxbox.services.mutations :as sm] [uxbox.services.util :as su] [uxbox.services.queries.icons :refer [decode-icon-row]] [uxbox.util.blob :as blob] - [uxbox.util.spec :as us] [uxbox.util.uuid :as uuid])) ;; --- Helpers & Specs diff --git a/backend/src/uxbox/services/mutations/images.clj b/backend/src/uxbox/services/mutations/images.clj index b4270e0b4..39c144a84 100644 --- a/backend/src/uxbox/services/mutations/images.clj +++ b/backend/src/uxbox/services/mutations/images.clj @@ -11,6 +11,8 @@ [datoteka.storages :as ds] [promesa.core :as p] [promesa.exec :as px] + [uxbox.common.exceptions :as ex] + [uxbox.common.spec :as us] [uxbox.db :as db] [uxbox.media :as media] [uxbox.images :as images] @@ -18,8 +20,6 @@ [uxbox.services.util :as su] [uxbox.util.blob :as blob] [uxbox.util.data :as data] - [uxbox.util.exceptions :as ex] - [uxbox.util.spec :as us] [uxbox.util.uuid :as uuid] [vertx.core :as vc])) @@ -117,7 +117,15 @@ (def valid-image-types? #{"image/jpeg", "image/png", "image/webp"}) -(s/def ::file ::us/upload) +(s/def :uxbox$upload/name ::us/string) +(s/def :uxbox$upload/size ::us/integer) +(s/def :uxbox$upload/mtype ::us/string) +(s/def ::upload + (s/keys :req-un [:uxbox$upload/name + :uxbox$upload/size + :uxbox$upload/mtype])) + +(s/def ::file ::upload) (s/def ::width ::us/integer) (s/def ::height ::us/integer) (s/def ::mimetype valid-image-types?) diff --git a/backend/src/uxbox/services/mutations/project_files.clj b/backend/src/uxbox/services/mutations/project_files.clj index f2bfc6046..fb8283a87 100644 --- a/backend/src/uxbox/services/mutations/project_files.clj +++ b/backend/src/uxbox/services/mutations/project_files.clj @@ -9,11 +9,11 @@ [clojure.spec.alpha :as s] [promesa.core :as p] [uxbox.db :as db] - [uxbox.util.spec :as us] + [uxbox.common.exceptions :as ex] + [uxbox.common.spec :as us] [uxbox.services.mutations :as sm] [uxbox.services.mutations.projects :as proj] [uxbox.services.util :as su] - [uxbox.util.exceptions :as ex] [uxbox.util.blob :as blob] [uxbox.util.uuid :as uuid])) diff --git a/backend/src/uxbox/services/mutations/project_pages.clj b/backend/src/uxbox/services/mutations/project_pages.clj index 1df535578..52948a679 100644 --- a/backend/src/uxbox/services/mutations/project_pages.clj +++ b/backend/src/uxbox/services/mutations/project_pages.clj @@ -9,14 +9,14 @@ [clojure.spec.alpha :as s] [promesa.core :as p] [uxbox.common.pages :as cp] + [uxbox.common.exceptions :as ex] + [uxbox.common.spec :as us] [uxbox.db :as db] [uxbox.services.mutations :as sm] [uxbox.services.mutations.project-files :as files] [uxbox.services.queries.project-pages :refer [decode-row]] [uxbox.services.util :as su] [uxbox.util.blob :as blob] - [uxbox.util.exceptions :as ex] - [uxbox.util.spec :as us] [uxbox.util.sql :as sql] [uxbox.util.uuid :as uuid] [vertx.eventbus :as ve])) diff --git a/backend/src/uxbox/services/mutations/projects.clj b/backend/src/uxbox/services/mutations/projects.clj index 0b8392e15..c2ffd7742 100644 --- a/backend/src/uxbox/services/mutations/projects.clj +++ b/backend/src/uxbox/services/mutations/projects.clj @@ -9,11 +9,11 @@ [clojure.spec.alpha :as s] [promesa.core :as p] [uxbox.db :as db] - [uxbox.util.spec :as us] + [uxbox.common.exceptions :as ex] + [uxbox.common.spec :as us] [uxbox.services.mutations :as sm] [uxbox.services.util :as su] [uxbox.util.blob :as blob] - [uxbox.util.exceptions :as ex] [uxbox.util.uuid :as uuid])) ;; --- Helpers & Specs diff --git a/backend/src/uxbox/services/mutations/user_attrs.clj b/backend/src/uxbox/services/mutations/user_attrs.clj index 9d459ebb6..42c952025 100644 --- a/backend/src/uxbox/services/mutations/user_attrs.clj +++ b/backend/src/uxbox/services/mutations/user_attrs.clj @@ -9,11 +9,11 @@ [clojure.spec.alpha :as s] [promesa.core :as p] [uxbox.db :as db] + [uxbox.common.spec :as us] [uxbox.services.mutations :as sm] [uxbox.services.util :as su] [uxbox.services.queries.user-attrs :refer [decode-row]] - [uxbox.util.blob :as blob] - [uxbox.util.spec :as us])) + [uxbox.util.blob :as blob])) ;; --- Update diff --git a/backend/src/uxbox/services/mutations/users.clj b/backend/src/uxbox/services/mutations/users.clj index 308775ff9..95314f808 100644 --- a/backend/src/uxbox/services/mutations/users.clj +++ b/backend/src/uxbox/services/mutations/users.clj @@ -13,6 +13,8 @@ [promesa.core :as p] [promesa.exec :as px] [uxbox.config :as cfg] + [uxbox.common.exceptions :as ex] + [uxbox.common.spec :as us] [uxbox.db :as db] [uxbox.emails :as emails] [uxbox.images :as images] @@ -24,8 +26,6 @@ strip-private-attrs resolve-thumbnail]] [uxbox.util.blob :as blob] - [uxbox.util.exceptions :as ex] - [uxbox.util.spec :as us] [uxbox.util.token :as token] [uxbox.util.uuid :as uuid] [vertx.core :as vc])) @@ -125,7 +125,16 @@ ;; --- Mutation: Update Photo -(s/def ::file ::us/upload) + +(s/def :uxbox$upload/name ::us/string) +(s/def :uxbox$upload/size ::us/integer) +(s/def :uxbox$upload/mtype ::us/string) +(s/def ::upload + (s/keys :req-un [:uxbox$upload/name + :uxbox$upload/size + :uxbox$upload/mtype])) + +(s/def ::file ::upload) (s/def ::update-profile-photo (s/keys :req-un [::user ::file])) @@ -286,13 +295,13 @@ ;; (defmethod core/query :validate-profile-password-recovery-token ;; [{:keys [token]}] -;; (s/assert ::us/token token) +;; (us/assert ::us/token token) ;; (with-open [conn (db/connection)] ;; (recovery-token-exists? conn token))) ;; (defmethod core/novelty :request-profile-password-recovery ;; [{:keys [username]}] -;; (s/assert ::us/username username) +;; (us/assert ::us/username username) ;; (with-open [conn (db/connection)] ;; (db/atomic conn ;; (request-password-recovery conn username)))) @@ -302,7 +311,7 @@ ;; (defmethod core/novelty :recover-profile-password ;; [params] -;; (s/assert ::recover-password params) +;; (us/assert ::recover-password params) ;; (with-open [conn (db/connection)] ;; (db/apply-atomic conn recover-password params))) diff --git a/backend/src/uxbox/services/queries/icons.clj b/backend/src/uxbox/services/queries/icons.clj index eb7faecf1..36fdffa89 100644 --- a/backend/src/uxbox/services/queries/icons.clj +++ b/backend/src/uxbox/services/queries/icons.clj @@ -8,11 +8,11 @@ (:require [clojure.spec.alpha :as s] [promesa.core :as p] + [uxbox.common.exceptions :as ex] + [uxbox.common.spec :as us] [uxbox.db :as db] [uxbox.services.queries :as sq] - [uxbox.util.blob :as blob] - [uxbox.util.exceptions :as ex] - [uxbox.util.spec :as us])) + [uxbox.util.blob :as blob])) ;; --- Helpers & Specs diff --git a/backend/src/uxbox/services/queries/images.clj b/backend/src/uxbox/services/queries/images.clj index 17fb9e86d..033b37574 100644 --- a/backend/src/uxbox/services/queries/images.clj +++ b/backend/src/uxbox/services/queries/images.clj @@ -9,6 +9,8 @@ [clojure.spec.alpha :as s] [promesa.core :as p] [promesa.exec :as px] + [uxbox.common.exceptions :as ex] + [uxbox.common.spec :as us] [uxbox.db :as db] [uxbox.media :as media] [uxbox.images :as images] @@ -16,8 +18,6 @@ [uxbox.services.util :as su] [uxbox.util.blob :as blob] [uxbox.util.data :as data] - [uxbox.util.exceptions :as ex] - [uxbox.util.spec :as us] [uxbox.util.uuid :as uuid] [vertx.core :as vc])) @@ -75,8 +75,9 @@ and deleted_at is null;"] (db/query-one conn [sql id]))) +(s/def ::id ::us/uuid) (s/def ::image-by-id - (s/keys :req-un [::user ::us/id])) + (s/keys :req-un [::user ::id])) (sq/defquery ::image-by-id [params] diff --git a/backend/src/uxbox/services/queries/project_files.clj b/backend/src/uxbox/services/queries/project_files.clj index c103cc87b..92df618e7 100644 --- a/backend/src/uxbox/services/queries/project_files.clj +++ b/backend/src/uxbox/services/queries/project_files.clj @@ -9,11 +9,11 @@ [clojure.spec.alpha :as s] [cuerdas.core :as str] [promesa.core :as p] + [uxbox.common.spec :as us] [uxbox.db :as db] [uxbox.services.queries :as sq] [uxbox.services.util :as su] - [uxbox.util.blob :as blob] - [uxbox.util.spec :as us])) + [uxbox.util.blob :as blob])) (declare decode-row) diff --git a/backend/src/uxbox/services/queries/project_pages.clj b/backend/src/uxbox/services/queries/project_pages.clj index e19530f95..c2e884609 100644 --- a/backend/src/uxbox/services/queries/project_pages.clj +++ b/backend/src/uxbox/services/queries/project_pages.clj @@ -8,11 +8,11 @@ (:require [clojure.spec.alpha :as s] [promesa.core :as p] + [uxbox.common.spec :as us] [uxbox.db :as db] [uxbox.services.queries :as sq] [uxbox.services.util :as su] [uxbox.util.blob :as blob] - [uxbox.util.spec :as us] [uxbox.util.sql :as sql])) ;; --- Helpers & Specs diff --git a/backend/src/uxbox/services/queries/projects.clj b/backend/src/uxbox/services/queries/projects.clj index c47c04479..b428f67be 100644 --- a/backend/src/uxbox/services/queries/projects.clj +++ b/backend/src/uxbox/services/queries/projects.clj @@ -8,11 +8,11 @@ (:require [clojure.spec.alpha :as s] [promesa.core :as p] + [uxbox.common.spec :as us] [uxbox.db :as db] [uxbox.services.queries :as sq] [uxbox.services.util :as su] - [uxbox.util.blob :as blob] - [uxbox.util.spec :as us])) + [uxbox.util.blob :as blob])) (declare decode-row) diff --git a/backend/src/uxbox/services/queries/user_attrs.clj b/backend/src/uxbox/services/queries/user_attrs.clj index 4498e2a46..8a86c73fe 100644 --- a/backend/src/uxbox/services/queries/user_attrs.clj +++ b/backend/src/uxbox/services/queries/user_attrs.clj @@ -8,11 +8,11 @@ (:require [clojure.spec.alpha :as s] [promesa.core :as p] + [uxbox.common.spec :as us] [uxbox.db :as db] [uxbox.services.queries :as sq] [uxbox.services.util :as su] - [uxbox.util.blob :as blob] - [uxbox.util.spec :as us])) + [uxbox.util.blob :as blob])) (defn decode-row [{:keys [val] :as row}] @@ -20,6 +20,9 @@ (cond-> row val (assoc :val (blob/decode val))))) +(s/def ::key ::us/string) +(s/def ::user ::us/uuid) + (s/def ::user-attr (s/keys :req-un [::key ::user])) diff --git a/backend/src/uxbox/services/queries/users.clj b/backend/src/uxbox/services/queries/users.clj index 55982c859..e6f228340 100644 --- a/backend/src/uxbox/services/queries/users.clj +++ b/backend/src/uxbox/services/queries/users.clj @@ -9,12 +9,12 @@ [clojure.spec.alpha :as s] [promesa.core :as p] [promesa.exec :as px] + [uxbox.common.spec :as us] [uxbox.db :as db] [uxbox.images :as images] [uxbox.services.queries :as sq] [uxbox.services.util :as su] - [uxbox.util.blob :as blob] - [uxbox.util.spec :as us])) + [uxbox.util.blob :as blob])) ;; --- Helpers & Specs diff --git a/backend/src/uxbox/services/util.clj b/backend/src/uxbox/services/util.clj index 32ded7296..3b0705ca1 100644 --- a/backend/src/uxbox/services/util.clj +++ b/backend/src/uxbox/services/util.clj @@ -10,9 +10,9 @@ [cuerdas.core :as str] [vertx.core :as vc] [uxbox.core :refer [system]] + [uxbox.common.exceptions :as ex] [uxbox.util.uuid :as uuid] - [uxbox.util.dispatcher :as uds] - [uxbox.util.exceptions :as ex])) + [uxbox.util.dispatcher :as uds])) ;; (def logging-interceptor ;; {:enter (fn [data] diff --git a/backend/src/uxbox/util/dispatcher.clj b/backend/src/uxbox/util/dispatcher.clj index db9588b54..4d304e109 100644 --- a/backend/src/uxbox/util/dispatcher.clj +++ b/backend/src/uxbox/util/dispatcher.clj @@ -13,8 +13,7 @@ [expound.alpha :as expound] [sieppari.core :as sp] [sieppari.context :as spx] - [uxbox.util.spec :as us] - [uxbox.util.exceptions :as ex]) + [uxbox.common.exceptions :as ex]) (:import clojure.lang.IDeref clojure.lang.MapEntry diff --git a/backend/src/uxbox/util/emails.clj b/backend/src/uxbox/util/emails.clj index 02534840a..4b819ccd3 100644 --- a/backend/src/uxbox/util/emails.clj +++ b/backend/src/uxbox/util/emails.clj @@ -10,8 +10,8 @@ [clojure.spec.alpha :as s] [cuerdas.core :as str] [instaparse.core :as insta] - [uxbox.util.exceptions :as ex] - [uxbox.util.spec :as us] + [uxbox.common.spec :as us] + [uxbox.common.exceptions :as ex] [uxbox.util.template :as tmpl])) ;; --- Impl. @@ -44,9 +44,9 @@ (rest parts))) state))) -(s/def ::subject ::us/string) -(s/def ::body-text ::us/string) -(s/def ::body-html ::us/string) +(s/def ::subject string?) +(s/def ::body-text string?) +(s/def ::body-html string?) (s/def ::parsed-email (s/keys :req-un [::subject ::body-html ::body-html])) @@ -79,7 +79,7 @@ (s/def ::to ::us/email) (s/def ::from ::us/email) (s/def ::reply-to ::us/email) -(s/def ::lang ::us/string) +(s/def ::lang string?) (s/def ::context (s/keys :req-un [::to] @@ -90,7 +90,7 @@ ([id extra-context] (s/assert keyword? id) (fn [context] - (s/assert ::context context) + (us/assert ::context context) (when-let [spec (s/get-spec id)] (s/assert spec context)) diff --git a/backend/src/uxbox/util/exceptions.clj b/backend/src/uxbox/util/exceptions.clj deleted file mode 100644 index f5bdde57b..000000000 --- a/backend/src/uxbox/util/exceptions.clj +++ /dev/null @@ -1,34 +0,0 @@ -;; This Source Code Form is subject to the terms of the Mozilla Public -;; License, v. 2.0. If a copy of the MPL was not distributed with this -;; file, You can obtain one at http://mozilla.org/MPL/2.0/. -;; -;; Copyright (c) 2016 Andrey Antukh - -;; WARNING: DEPRECATED: please use uxbox.common.exceptions - -(ns uxbox.util.exceptions - "A helpers for work with exceptions." - (:require [clojure.spec.alpha :as s])) - -(s/def ::type keyword?) -(s/def ::code keyword?) -(s/def ::mesage string?) -(s/def ::hint string?) -(s/def ::cause #(instance? Throwable %)) -(s/def ::error-params - (s/keys :req-un [::type] - :opt-un [::code - ::hint - ::mesage - ::cause])) - -(defn error - [& {:keys [type code message hint cause] :as params}] - (s/assert ::error-params params) - (let [message (or message hint "") - payload (dissoc params :cause :message)] - (ex-info message payload cause))) - -(defmacro raise - [& args] - `(throw (error ~@args))) diff --git a/backend/src/uxbox/util/spec.clj b/backend/src/uxbox/util/spec.clj deleted file mode 100644 index 1fac49aaf..000000000 --- a/backend/src/uxbox/util/spec.clj +++ /dev/null @@ -1,145 +0,0 @@ -;; This Source Code Form is subject to the terms of the Mozilla Public -;; License, v. 2.0. If a copy of the MPL was not distributed with this -;; file, You can obtain one at http://mozilla.org/MPL/2.0/. -;; -;; Copyright (c) 2016-2019 Andrey Antukh - -;; WARNING: DEPRECATED: please use uxbox.common.spec - -(ns uxbox.util.spec - (:refer-clojure :exclude [keyword uuid vector boolean map set]) - (:require - [clojure.spec.alpha :as s] - [cuerdas.core :as str] - [datoteka.core :as fs] - [expound.alpha :as expound] - [uxbox.util.exceptions :as ex]) - (:import java.time.Instant)) - -(s/check-asserts true) - -;; --- Constants - -(def email-rx - #"^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$") - -(def uuid-rx - #"^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$") - -;; --- Public Api - -(defn conform - [spec data] - (let [result (s/conform spec data)] - (when (= result ::s/invalid) - (throw (ex/error :type :validation - :code :spec-validation - :explain (with-out-str - (expound/printer data)) - :data (::s/problems data)))) - result)) - -;; --- Predicates - -(defn email? - [v] - (and (string? v) - (re-matches email-rx v))) - -(defn instant? - [v] - (instance? Instant v)) - -(defn path? - [v] - (instance? java.nio.file.Path v)) - -(defn regex? - [v] - (instance? java.util.regex.Pattern v)) - -;; --- Conformers - -(defn- uuid-conformer - [v] - (cond - (uuid? v) v - (string? v) - (cond - (re-matches uuid-rx v) - (java.util.UUID/fromString v) - - (str/empty? v) - nil - - :else - ::s/invalid) - :else ::s/invalid)) - -(defn- integer-conformer - [v] - (cond - (integer? v) v - (string? v) - (if (re-matches #"^[-+]?\d+$" v) - (Long/parseLong v) - ::s/invalid) - :else ::s/invalid)) - -(defn boolean-conformer - [v] - (cond - (boolean? v) v - (string? v) - (if (re-matches #"^(?:t|true|false|f|0|1)$" v) - (contains? #{"t" "true" "1"} v) - ::s/invalid) - :else ::s/invalid)) - -(defn boolean-unformer - [v] - (if v "true" "false")) - -(defn path-conformer - [v] - (cond - (string? v) (fs/path v) - (fs/path? v) v - :else ::s/invalid)) - -(defn- number-conformer - [v] - (cond - (number? v) v - (str/numeric? v) (Double/parseDouble v) - :else ::s/invalid)) - - -;; --- Default Specs - -(s/def ::string string?) -(s/def ::integer (s/conformer integer-conformer str)) -(s/def ::uuid (s/conformer uuid-conformer str)) -(s/def ::boolean (s/conformer boolean-conformer boolean-unformer)) -(s/def ::number (s/conformer number-conformer str)) -(s/def ::path (s/conformer path-conformer str)) - -(s/def ::positive pos?) -(s/def ::negative neg?) -(s/def ::uploaded-file any?) -(s/def ::bytes bytes?) -(s/def ::email email?) -(s/def ::file any?) - -(s/def ::name ::string) -(s/def ::size ::integer) -(s/def ::mtype ::string) -(s/def ::upload - (s/keys :req-un [::name ::path ::size ::mtype])) - -;; TODO: deprecated -(s/def ::id ::uuid) -(s/def ::username ::string) -(s/def ::password ::string) -(s/def ::token ::string) - diff --git a/backend/src/uxbox/util/svg.clj b/backend/src/uxbox/util/svg.clj index f646cad26..7c8147d50 100644 --- a/backend/src/uxbox/util/svg.clj +++ b/backend/src/uxbox/util/svg.clj @@ -9,8 +9,8 @@ (:require [clojure.spec.alpha :as s] [cuerdas.core :as str] - [uxbox.util.spec :as us] - [uxbox.util.exceptions :as ex]) + [uxbox.common.spec :as us] + [uxbox.common.exceptions :as ex]) (:import org.jsoup.Jsoup org.jsoup.nodes.Attribute @@ -18,10 +18,10 @@ org.jsoup.nodes.Document java.io.InputStream)) -(s/def ::content ::us/string) +(s/def ::content string?) (s/def ::width ::us/number) (s/def ::height ::us/number) -(s/def ::name ::us/string) +(s/def ::name string?) (s/def ::view-box (s/coll-of ::us/number :min-count 4 :max-count 4)) (s/def ::svg-entity diff --git a/backend/src/uxbox/util/template.clj b/backend/src/uxbox/util/template.clj index a2ac92915..a48ef1ea1 100644 --- a/backend/src/uxbox/util/template.clj +++ b/backend/src/uxbox/util/template.clj @@ -11,7 +11,7 @@ [clojure.tools.logging :as log] [clojure.walk :as walk] [clojure.java.io :as io] - [uxbox.util.exceptions :as ex]) + [uxbox.common.exceptions :as ex]) (:import java.io.StringReader java.util.HashMap diff --git a/common/uxbox/common/data.cljc b/common/uxbox/common/data.cljc index ad5be360a..4774241a5 100644 --- a/common/uxbox/common/data.cljc +++ b/common/uxbox/common/data.cljc @@ -15,6 +15,17 @@ ;; Data Structures Manipulation ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +(defn dissoc-in + [m [k & ks :as keys]] + (if ks + (if-let [nextmap (get m k)] + (let [newmap (dissoc-in nextmap ks)] + (if (seq newmap) + (assoc m k newmap) + (dissoc m k))) + m) + (dissoc m k))) + (defn concat [& colls] (loop [result (first colls) diff --git a/common/uxbox/common/spec.cljc b/common/uxbox/common/spec.cljc index f3319f733..10ed85db7 100644 --- a/common/uxbox/common/spec.cljc +++ b/common/uxbox/common/spec.cljc @@ -98,6 +98,7 @@ ;; --- Default Specs (s/def ::inst inst?) +(s/def ::string string?) (s/def ::email (s/conformer email-conformer str)) (s/def ::color (s/conformer color-conformer str)) (s/def ::uuid (s/conformer uuid-conformer str))