Browse Source

enhance(dev): add :dispatch-key to validate-db! errors

so it's available to tests and to app
Gabriel Horner 10 months ago
parent
commit
769e68a3c6

+ 1 - 4
deps/db/script/validate_client_db.cljs

@@ -23,10 +23,7 @@
                            (->> (map (fn [e] (dissoc e :db/id)) ent-maps) explainer not-empty))]
       (do
         (if group-errors
-          (let [ent-errors (->> (db-validate/group-errors-by-entity db ent-maps (:errors explanation))
-                                (map #(assoc %
-                                             :dispatch-key
-                                             (->> (dissoc (:entity %) :db/id) (db-malli-schema/entity-dispatch-key db)))))]
+          (let [ent-errors (db-validate/group-errors-by-entity db ent-maps (:errors explanation))]
             (println "Found" (count ent-errors) "entities in errors:")
             (cond
               verbose

+ 17 - 16
deps/db/src/logseq/db/frontend/validate.cljs

@@ -63,29 +63,30 @@
   (->> errors
        (group-by #(-> % :in first))
        (map (fn [[idx errors']]
-              {:entity (let [ent (get ent-maps idx)]
-                         (cond-> ent
+              (let [ent (get ent-maps idx)]
+                {:entity (cond-> ent
                            ;; Provide additional page info for debugging
                            (:block/page ent)
                            (update :block/page
                                    (fn [id] (select-keys (d/entity db id)
-                                                         [:block/name :block/tags :db/id :block/created-at])))))
-               :errors errors'
+                                                         [:block/name :block/tags :db/id :block/created-at]))))
+                 :dispatch-key (->> (dissoc ent :db/id) (db-malli-schema/entity-dispatch-key db))
+                 :errors errors'
                ;; Group by type to reduce verbosity
                ;; TODO: Move/remove this to another fn if unused
-               :errors-by-type
-               (->> (group-by :type errors')
-                    (map (fn [[type' type-errors]]
-                           [type'
-                            {:in-value-distinct (->> type-errors
-                                                     (map #(select-keys % [:in :value]))
+                 :errors-by-type
+                 (->> (group-by :type errors')
+                      (map (fn [[type' type-errors]]
+                             [type'
+                              {:in-value-distinct (->> type-errors
+                                                       (map #(select-keys % [:in :value]))
+                                                       distinct
+                                                       vec)
+                               :schema-distinct (->> (map :schema type-errors)
+                                                     (map m/form)
                                                      distinct
-                                                     vec)
-                             :schema-distinct (->> (map :schema type-errors)
-                                                   (map m/form)
-                                                   distinct
-                                                   vec)}]))
-                    (into {}))}))))
+                                                     vec)}]))
+                      (into {}))})))))
 
 (defn validate-db!
   "Validates all the entities of the given db using :eavt datoms. Returns a map

+ 1 - 0
deps/db/test/logseq/db/sqlite/create_graph_test.cljs

@@ -119,6 +119,7 @@
         validation (db-validate/validate-db! @conn)]
     ;; For debugging
     ;; (println (count (:errors validation)) "errors of" (count (:entities validation)))
+    ;; (cljs.pprint/pprint (:errors validation))
     (is (empty? (map :entity (:errors validation)))
         "New graph has no validation errors")))