|
|
@@ -11,8 +11,11 @@
|
|
|
[clojure.string :as string]
|
|
|
[frontend.util :as util]
|
|
|
[logseq.graph-parser.util.block-ref :as block-ref]
|
|
|
+ [logseq.db.frontend.malli-schema :as db-malli-schema]
|
|
|
[frontend.db.fix :as db-fix]
|
|
|
- [frontend.handler.file-based.property.util :as property-util]))
|
|
|
+ [frontend.handler.file-based.property.util :as property-util]
|
|
|
+ [cljs.pprint :as pprint]
|
|
|
+ [malli.core :as m]))
|
|
|
|
|
|
(defn new-outliner-txs-state [] (atom []))
|
|
|
|
|
|
@@ -22,10 +25,29 @@
|
|
|
(instance? cljs.core/Atom state)
|
|
|
(coll? @state)))
|
|
|
|
|
|
+(defn- validate-db!
|
|
|
+ [{:keys [db-after tx-data tx-meta]}]
|
|
|
+ (let [changed-ids (->> tx-data (map :e) distinct)
|
|
|
+ ent-maps* (->> changed-ids (mapcat #(d/datoms db-after :eavt %)) db-malli-schema/datoms->entity-maps vals)
|
|
|
+ ent-maps (vec (db-malli-schema/update-properties-in-ents ent-maps*))
|
|
|
+ db-schema (db-malli-schema/update-properties-in-schema db-malli-schema/DB db-after)]
|
|
|
+ (js/console.log "changed eids:" changed-ids tx-meta)
|
|
|
+ (when-let [errors (->> ent-maps
|
|
|
+ (m/explain db-schema)
|
|
|
+ :errors)]
|
|
|
+ (js/console.error "Invalid datascript entities detected amongst changed entity ids:" changed-ids)
|
|
|
+ (pprint/pprint {:errors errors})
|
|
|
+ (pprint/pprint {:entity-maps ent-maps})
|
|
|
+ ;; (js/alert "Invalid DB!")
|
|
|
+ )))
|
|
|
+
|
|
|
(defn after-transact-pipelines
|
|
|
[repo {:keys [_db-before _db-after _tx-data _tempids tx-meta] :as tx-report}]
|
|
|
(when-not config/test?
|
|
|
(pipelines/invoke-hooks tx-report)
|
|
|
+ ;; Skip tx with update-tx-ids? because they are immediately followed by the original block tx
|
|
|
+ (when (and config/dev? (not (:update-tx-ids? tx-meta)))
|
|
|
+ (validate-db! tx-report))
|
|
|
|
|
|
(when (or (:outliner/transact? tx-meta)
|
|
|
(:outliner-op tx-meta)
|
|
|
@@ -118,7 +140,7 @@
|
|
|
(concat txs retracted-tx'))
|
|
|
txs))
|
|
|
|
|
|
-(defn validate-db!
|
|
|
+(defn fix-db!
|
|
|
[{:keys [db-before db-after tx-data]}]
|
|
|
(let [changed-pages (->> (filter (fn [d] (contains? #{:block/left :block/parent} (:a d))) tx-data)
|
|
|
(map :e)
|
|
|
@@ -168,7 +190,7 @@
|
|
|
rs (db/transact! repo txs (assoc opts :outliner/transact? true))
|
|
|
tx-id (get-tx-id rs)]
|
|
|
;; TODO: disable this when db is stable
|
|
|
- (when (and config/dev? (not util/node-test?)) (validate-db! rs))
|
|
|
+ (when (and config/dev? (not util/node-test?)) (fix-db! rs))
|
|
|
(state/update-state! :history/tx->editor-cursor
|
|
|
(fn [m] (assoc m tx-id before-editor-cursor)))
|
|
|
|