|
@@ -3,6 +3,9 @@
|
|
|
(:require [datascript.core :as d]
|
|
(:require [datascript.core :as d]
|
|
|
[clojure.string :as string]))
|
|
[clojure.string :as string]))
|
|
|
|
|
|
|
|
|
|
+;; Main property vars
|
|
|
|
|
+;; ==================
|
|
|
|
|
+
|
|
|
(def ^:large-vars/data-var built-in-properties*
|
|
(def ^:large-vars/data-var built-in-properties*
|
|
|
"Map of built in properties for db graphs with their :db/ident as keys.
|
|
"Map of built in properties for db graphs with their :db/ident as keys.
|
|
|
Each property has a config map with the following keys:
|
|
Each property has a config map with the following keys:
|
|
@@ -183,9 +186,40 @@
|
|
|
|
|
|
|
|
(assert (= db-attribute-properties
|
|
(assert (= db-attribute-properties
|
|
|
(set (keep (fn [[k {:keys [attribute]}]] (when attribute k))
|
|
(set (keep (fn [[k {:keys [attribute]}]] (when attribute k))
|
|
|
- built-in-properties)))
|
|
|
|
|
|
|
+ built-in-properties)))
|
|
|
"All db attribute properties are configured in built-in-properties")
|
|
"All db attribute properties are configured in built-in-properties")
|
|
|
|
|
|
|
|
|
|
+(def logseq-property-namespaces
|
|
|
|
|
+ #{"logseq.property" "logseq.property.table" "logseq.property.tldraw"
|
|
|
|
|
+ "logseq.task"})
|
|
|
|
|
+
|
|
|
|
|
+(defn logseq-property?
|
|
|
|
|
+ "Determines if keyword is a logseq property"
|
|
|
|
|
+ [kw]
|
|
|
|
|
+ (contains? logseq-property-namespaces (namespace kw)))
|
|
|
|
|
+
|
|
|
|
|
+(def user-property-namespaces
|
|
|
|
|
+ #{"user.property"})
|
|
|
|
|
+
|
|
|
|
|
+(defn property?
|
|
|
|
|
+ "Determines if ident kw is a property"
|
|
|
|
|
+ [k]
|
|
|
|
|
+ (let [k-name (namespace k)]
|
|
|
|
|
+ (and k-name
|
|
|
|
|
+ (or (contains? logseq-property-namespaces k-name)
|
|
|
|
|
+ (contains? user-property-namespaces k-name)))))
|
|
|
|
|
+
|
|
|
|
|
+;; Helper fns
|
|
|
|
|
+;; ==========
|
|
|
|
|
+
|
|
|
|
|
+(defn properties
|
|
|
|
|
+ "Fetch all properties of entity like :block/properties used to do.
|
|
|
|
|
+ Use this in deps because nbb can't use :block/properties from entity-plus"
|
|
|
|
|
+ [e]
|
|
|
|
|
+ (->> (into {} e)
|
|
|
|
|
+ (filter (fn [[k _]] (property? k)))
|
|
|
|
|
+ (into {})))
|
|
|
|
|
+
|
|
|
(defn valid-property-name?
|
|
(defn valid-property-name?
|
|
|
[s]
|
|
[s]
|
|
|
{:pre [(string? s)]}
|
|
{:pre [(string? s)]}
|
|
@@ -196,7 +230,7 @@
|
|
|
"Get a built-in property's id (keyword name for file graph and db-ident for db
|
|
"Get a built-in property's id (keyword name for file graph and db-ident for db
|
|
|
graph) given its db-ident. No need to use this fn in a db graph only context"
|
|
graph) given its db-ident. No need to use this fn in a db graph only context"
|
|
|
[repo db-ident]
|
|
[repo db-ident]
|
|
|
- ;; FIXME: Use db-based-graph? when this fn and others moves to another ns
|
|
|
|
|
|
|
+ ;; FIXME: Use db-based-graph? when this fn moves to another ns
|
|
|
(if (string/starts-with? repo "logseq_db_")
|
|
(if (string/starts-with? repo "logseq_db_")
|
|
|
db-ident
|
|
db-ident
|
|
|
(get-in built-in-properties [db-ident :name])))
|
|
(get-in built-in-properties [db-ident :name])))
|
|
@@ -210,9 +244,12 @@
|
|
|
"Get the value of built-in block's property by its db-ident"
|
|
"Get the value of built-in block's property by its db-ident"
|
|
|
[repo db block db-ident]
|
|
[repo db block db-ident]
|
|
|
(when db
|
|
(when db
|
|
|
- (let [block (or (d/entity db (:db/id block)) block)]
|
|
|
|
|
- (when-let [properties (:block/properties block)]
|
|
|
|
|
- (lookup repo properties db-ident)))))
|
|
|
|
|
|
|
+ (let [block (or (d/entity db (:db/id block)) block)
|
|
|
|
|
+ ;; FIXME: Use db-based-graph? when this fn moves to another ns
|
|
|
|
|
+ properties' (if (string/starts-with? repo "logseq_db_")
|
|
|
|
|
+ (properties block)
|
|
|
|
|
+ (:block/properties block))]
|
|
|
|
|
+ (lookup repo properties' db-ident))))
|
|
|
|
|
|
|
|
(defn shape-block?
|
|
(defn shape-block?
|
|
|
[repo db block]
|
|
[repo db block]
|
|
@@ -238,33 +275,6 @@
|
|
|
(when (= (closed-value-name e) value-name)
|
|
(when (= (closed-value-name e) value-name)
|
|
|
e))) values)))
|
|
e))) values)))
|
|
|
|
|
|
|
|
-(def logseq-property-namespaces
|
|
|
|
|
- #{"logseq.property" "logseq.property.table" "logseq.property.tldraw"
|
|
|
|
|
- "logseq.task"})
|
|
|
|
|
-
|
|
|
|
|
-(defn logseq-property?
|
|
|
|
|
- "Determines if keyword is a logseq property"
|
|
|
|
|
- [kw]
|
|
|
|
|
- (contains? logseq-property-namespaces (namespace kw)))
|
|
|
|
|
-
|
|
|
|
|
-(def user-property-namespaces
|
|
|
|
|
- #{"user.property"})
|
|
|
|
|
-
|
|
|
|
|
-(defn property?
|
|
|
|
|
- "Determines if ident kw is a property"
|
|
|
|
|
- [k]
|
|
|
|
|
- (let [k-name (namespace k)]
|
|
|
|
|
- (and k-name
|
|
|
|
|
- (or (contains? logseq-property-namespaces k-name)
|
|
|
|
|
- (contains? user-property-namespaces k-name)))))
|
|
|
|
|
-
|
|
|
|
|
-(defn properties
|
|
|
|
|
- "Fetch all properties of entity like :block/properties used to do.
|
|
|
|
|
- Use this in deps because nbb can't use :block/properties from entity-plus"
|
|
|
|
|
- [e]
|
|
|
|
|
- (->> (into {} e)
|
|
|
|
|
- (filter (fn [[k _]] (property? k)))
|
|
|
|
|
- (into {})))
|
|
|
|
|
|
|
|
|
|
;; TODO: db ident should obey clojure's rules for keywords
|
|
;; TODO: db ident should obey clojure's rules for keywords
|
|
|
(defn get-db-ident-from-name
|
|
(defn get-db-ident-from-name
|