|
|
@@ -3,7 +3,9 @@
|
|
|
(:require [clojure.walk :as walk]
|
|
|
[clojure.string :as string]
|
|
|
[logseq.db.frontend.schema :as db-schema]
|
|
|
- [logseq.db.frontend.property.type :as db-property-type]))
|
|
|
+ [logseq.db.frontend.property.type :as db-property-type]
|
|
|
+ [datascript.core :as d]
|
|
|
+ [logseq.db.frontend.property :as db-property]))
|
|
|
|
|
|
;; Helper fns
|
|
|
;; ==========
|
|
|
@@ -28,11 +30,25 @@
|
|
|
(let [[property-type schema-fn] e
|
|
|
schema-fn' (if (db-property-type/property-types-with-db property-type) (partial schema-fn db) schema-fn)
|
|
|
validation-fn #(validate-property-value property-type schema-fn' %)]
|
|
|
- [property-type [:tuple :entity [:fn validation-fn]]])
|
|
|
+ ;; TODO: Be more specific about :keyword
|
|
|
+ [property-type [:tuple :keyword [:fn validation-fn]]])
|
|
|
:else
|
|
|
e)))
|
|
|
db-schema))
|
|
|
|
|
|
+(defn update-properties-in-ents
|
|
|
+ "Prepares properties in entities to be validated by DB schema"
|
|
|
+ [ents]
|
|
|
+ (mapv
|
|
|
+ (fn [ent]
|
|
|
+ (reduce (fn [m [k v]]
|
|
|
+ (if (db-property/property? k)
|
|
|
+ (update m :block/properties (fnil conj []) [k v])
|
|
|
+ (assoc m k v)))
|
|
|
+ {}
|
|
|
+ ent))
|
|
|
+ ents))
|
|
|
+
|
|
|
(defn datoms->entity-maps
|
|
|
"Returns entity maps for given :eavt datoms"
|
|
|
[datoms]
|
|
|
@@ -46,14 +62,30 @@
|
|
|
;; Malli schemas
|
|
|
;; =============
|
|
|
;; These schemas should be data vars to remain as simple and reusable as possible
|
|
|
+(def property-tuple
|
|
|
+ "Represents a tuple of a property and its property value. This schema
|
|
|
+ has 2 metadata hooks which are used to inject a datascript db later"
|
|
|
+ (into
|
|
|
+ [:multi {:dispatch ^:add-db (fn [db property-tuple]
|
|
|
+ (get-in (d/entity db (first property-tuple))
|
|
|
+ [:block/schema :type]))}]
|
|
|
+ (map (fn [[prop-type value-schema]]
|
|
|
+ ^:property-value [prop-type (if (vector? value-schema) (last value-schema) value-schema)])
|
|
|
+ db-property-type/built-in-validation-schemas)))
|
|
|
+
|
|
|
+(def block-properties
|
|
|
+ "Validates a slightly modified version of :block/properties. Properties are
|
|
|
+ expected to be a vector of tuples instead of a map in order to validate each
|
|
|
+ property with its property value that is valid for its type"
|
|
|
+ [:sequential property-tuple])
|
|
|
|
|
|
-;; FIXME: validate properties
|
|
|
(def page-or-block-attrs
|
|
|
"Common attributes for page and normal blocks"
|
|
|
[[:block/uuid :uuid]
|
|
|
[:block/created-at :int]
|
|
|
[:block/updated-at :int]
|
|
|
[:block/format [:enum :markdown]]
|
|
|
+ [:block/properties {:optional true} block-properties]
|
|
|
[:block/refs {:optional true} [:set :int]]
|
|
|
[:block/tags {:optional true} [:set :int]]
|
|
|
[:block/collapsed-properties {:optional true} [:set :int]]
|