Browse Source

simplify :map declarations in db schema

Make :closed opt in rather than required in order for --closed-maps
to work
Gabriel Horner 2 years ago
parent
commit
82bcd01525
2 changed files with 29 additions and 28 deletions
  1. 7 3
      deps/db/script/validate_client_db.cljs
  2. 22 25
      deps/db/src/logseq/db/malli_schema.cljs

+ 7 - 3
deps/db/script/validate_client_db.cljs

@@ -45,11 +45,15 @@
   [db-schema db {:keys [closed-maps]}]
   [db-schema db {:keys [closed-maps]}]
   (let [db-schema-with-property-vals (db-malli-schema/update-properties-in-schema db-schema db)]
   (let [db-schema-with-property-vals (db-malli-schema/update-properties-in-schema db-schema db)]
     (if closed-maps
     (if closed-maps
+      ;; closes maps that don't have an explicit :closed option
       (walk/postwalk (fn [e]
       (walk/postwalk (fn [e]
                        (if (and (vector? e)
                        (if (and (vector? e)
-                                (= :map (first e))
-                                (contains? (second e) :closed))
-                         (assoc e 1 (assoc (second e) :closed true))
+                                (= :map (first e)))
+                         (if (map? (second e))
+                           (if (not (contains? (second e) :closed))
+                             (assoc e 1 (assoc (second e) :closed true))
+                             e)
+                           (into [:map {:closed true}] (rest e)))
                          e))
                          e))
                      db-schema-with-property-vals)
                      db-schema-with-property-vals)
       db-schema-with-property-vals)))
       db-schema-with-property-vals)))

+ 22 - 25
deps/db/src/logseq/db/malli_schema.cljs

@@ -86,18 +86,18 @@
 (def normal-page
 (def normal-page
   (vec
   (vec
    (concat
    (concat
-    [:map {:closed false}]
-    page-attrs
-    ;; journal-day is only set for journal pages
-    [[:block/journal-day {:optional true} :int]
+    [:map
+     ;; journal-day is only set for journal pages
+     [:block/journal-day {:optional true} :int]
      [:block/namespace {:optional true} :int]]
      [:block/namespace {:optional true} :int]]
+    page-attrs
     page-or-block-attrs)))
     page-or-block-attrs)))
 
 
 (def object-page
 (def object-page
   (vec
   (vec
    (concat
    (concat
-    [:map {:closed false}]
-    [[:block/collapsed? {:optional true} :boolean]
+    [:map
+     [:block/collapsed? {:optional true} :boolean]
      [:block/tags [:set :int]]]
      [:block/tags [:set :int]]]
     page-attrs
     page-attrs
     (remove #(= :block/tags (first %)) page-or-block-attrs))))
     (remove #(= :block/tags (first %)) page-or-block-attrs))))
@@ -105,13 +105,12 @@
 (def class-page
 (def class-page
   (vec
   (vec
    (concat
    (concat
-    [:map {:closed false}]
-    [[:block/namespace {:optional true} :int]
+    [:map
+     [:block/namespace {:optional true} :int]
      ;; TODO: Require :block/schema
      ;; TODO: Require :block/schema
      [:block/schema
      [:block/schema
       {:optional true}
       {:optional true}
       [:map
       [:map
-       {:closed false}
        [:properties {:optional true} [:vector :uuid]]]]]
        [:properties {:optional true} [:vector :uuid]]]]]
     page-attrs
     page-attrs
     page-or-block-attrs)))
     page-or-block-attrs)))
@@ -119,10 +118,9 @@
 (def internal-property
 (def internal-property
   (vec
   (vec
    (concat
    (concat
-    [:map {:closed false}]
-    [[:block/schema
+    [:map
+     [:block/schema
       [:map
       [:map
-       {:closed false}
        [:type (apply vector :enum (into db-property-type/internal-builtin-schema-types
        [:type (apply vector :enum (into db-property-type/internal-builtin-schema-types
                                         db-property-type/user-builtin-schema-types))]
                                         db-property-type/user-builtin-schema-types))]
        [:hide? {:optional true} :boolean]
        [:hide? {:optional true} :boolean]
@@ -133,10 +131,9 @@
 (def user-property
 (def user-property
   (vec
   (vec
    (concat
    (concat
-    [:map {:closed false}]
-    [[:block/schema
+    [:map
+     [:block/schema
       [:map
       [:map
-       {:closed false}
        [:type (apply vector :enum db-property-type/user-builtin-schema-types)]
        [:type (apply vector :enum db-property-type/user-builtin-schema-types)]
        [:hide? {:optional true} :boolean]
        [:hide? {:optional true} :boolean]
        [:description {:optional true} :string]
        [:description {:optional true} :string]
@@ -144,14 +141,14 @@
        [:cardinality {:optional true} [:enum :one :many]]
        [:cardinality {:optional true} [:enum :one :many]]
        ;; Just for :enum type
        ;; Just for :enum type
        [:enum-config {:optional true}
        [:enum-config {:optional true}
-        [:map {:closed false}
+        [:map
          [:values
          [:values
           [:map-of
           [:map-of
-           :uuid [:map {:closed false}
+           :uuid [:map
                   [:name :string]
                   [:name :string]
                   [:description :string]
                   [:description :string]
                   [:icon {:optional true}
                   [:icon {:optional true}
-                   [:map {:closed false}
+                   [:map
                     [:id :string]
                     [:id :string]
                     [:name :string]
                     [:name :string]
                     [:type [:enum :tabler-icon :emoji]]]]]]]
                     [:type [:enum :tabler-icon :emoji]]]]]]]
@@ -185,7 +182,7 @@
    [:block/left :int]
    [:block/left :int]
    [:block/parent :int]
    [:block/parent :int]
    [:block/metadata {:optional true}
    [:block/metadata {:optional true}
-    [:map {:closed false}
+    [:map
      [:created-from-block :uuid]
      [:created-from-block :uuid]
      [:created-from-property :uuid]
      [:created-from-property :uuid]
      [:created-from-template {:optional true} :uuid]]]
      [:created-from-template {:optional true} :uuid]]]
@@ -203,7 +200,7 @@
   "A normal block with tags"
   "A normal block with tags"
   (vec
   (vec
    (concat
    (concat
-    [:map {:closed false}]
+    [:map]
     [[:block/type [:= #{"object"}]]
     [[:block/type [:= #{"object"}]]
      [:block/tags [:set :int]]]
      [:block/tags [:set :int]]]
     block-attrs
     block-attrs
@@ -213,7 +210,7 @@
   "A block with content and no special type or tag behavior"
   "A block with content and no special type or tag behavior"
   (vec
   (vec
    (concat
    (concat
-    [:map {:closed false}]
+    [:map]
     block-attrs
     block-attrs
     page-or-block-attrs)))
     page-or-block-attrs)))
 
 
@@ -228,12 +225,12 @@
   "A block that has an unknown type. This type of block should be removed when
   "A block that has an unknown type. This type of block should be removed when
   the above TODOs have been addressed and the frontend ensures no unknown blocks
   the above TODOs have been addressed and the frontend ensures no unknown blocks
   are being created"
   are being created"
-  [:map {:closed true}
+  [:map
    [:block/uuid :uuid]
    [:block/uuid :uuid]
    [:block/unknown? :boolean]])
    [:block/unknown? :boolean]])
 
 
 (def file-block
 (def file-block
-  [:map {:closed false}
+  [:map
    [:block/uuid :uuid]
    [:block/uuid :uuid]
    [:block/tx-id {:optional true} :int]
    [:block/tx-id {:optional true} :int]
    [:file/content :string]
    [:file/content :string]
@@ -242,11 +239,11 @@
    [:file/last-modified-at {:optional true} :any]])
    [:file/last-modified-at {:optional true} :any]])
 
 
 (def schema-version
 (def schema-version
-  [:map {:closed false}
+  [:map
    [:schema/version :int]])
    [:schema/version :int]])
 
 
 (def db-ident
 (def db-ident
-  [:map {:closed false}
+  [:map
    [:db/ident :keyword]
    [:db/ident :keyword]
    [:db/type {:optional true} :string]])
    [:db/type {:optional true} :string]])