chore: cleanup different definitions of property

Also fixed some outdated docstrings
pull/11196/head
Gabriel Horner 2024-04-05 13:27:39 -04:00
parent 6045969179
commit 38849bf706
5 changed files with 34 additions and 27 deletions

View File

@ -10,10 +10,6 @@
;; :db/ident malli schemas
;; =======================
(def logseq-property-namespaces
#{"logseq.property" "logseq.property.table" "logseq.property.tldraw"
"logseq.task"})
(def db-attribute-properties
"Internal properties that are also db attributes"
#{:block/alias :block/tags})
@ -24,21 +20,20 @@
(def logseq-property-ident
[:and :keyword [:fn
{:error/message "should be a valid logseq property namespace"}
(fn logseq-namespace? [k]
(contains? logseq-property-namespaces (namespace k)))]])
db-property/logseq-property?]])
(def internal-property-ident
[:or logseq-property-ident db-attribute-ident])
(defn user-property-namespace?
(defn- user-property?
"Determines if keyword is a user property"
[kw]
(contains? #{"user.property"} (namespace kw)))
(contains? db-property/user-property-namespaces (namespace kw)))
(def user-property-ident
[:and :keyword [:fn
{:error/message "should be a valid user property namespace"}
user-property-namespace?]])
user-property?]])
(def property-ident
[:or internal-property-ident user-property-ident])
@ -48,7 +43,7 @@
db-attribute-ident. It's important to grow this list purposefully and have it
start with 'logseq' to allow for users and 3rd party plugins to provide their
own namespaces to core concepts."
(into logseq-property-namespaces #{"logseq.class" "logseq.kv"}))
(into db-property/logseq-property-namespaces #{"logseq.class" "logseq.kv"}))
(def logseq-ident
[:and :keyword [:fn
@ -247,7 +242,7 @@
(def property-page
[:multi {:dispatch (fn [m]
(or (contains? logseq-property-namespaces (namespace (m :db/ident)))
(or (db-property/logseq-property? (m :db/ident))
(contains? db-attribute-properties (m :db/ident))))}
[true internal-property]
[:malli.core/default user-property]])

View File

@ -1,7 +1,6 @@
(ns logseq.db.frontend.property
"Property related fns for DB graphs and frontend/datascript usage"
(:require [logseq.db.sqlite.util :as sqlite-util]
[datascript.core :as d]
(:require [datascript.core :as d]
[clojure.string :as string]))
(def ^:large-vars/data-var built-in-properties*
@ -19,8 +18,7 @@
* :name - Property's :block/name as a keyword. If none given, one is derived from the db/ident
* :attribute - Property keyword that is saved to a datascript attribute outside of :block/properties
* :closed-values - Vec of closed-value maps for properties with choices. Map
has keys :value, :db-ident, :uuid and :icon
* :db-ident - Keyword to set :db/ident and give property unique id in db"
has keys :value, :db-ident, :uuid and :icon"
{:block/alias {:original-name "Alias"
:attribute :block/alias
:schema {:type :page
@ -186,11 +184,11 @@
(not (re-find #"^(#|\[\[)" s)))
(defn get-pid
"Get a built-in property's id (keyword name for file graph and uuid for db graph)
given its db-ident. Use this fn on a file or db graph. Use
db-pu/get-built-in-property-uuid if only in a db graph context"
"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"
[repo db-ident]
(if (sqlite-util/db-based-graph? repo)
;; FIXME: Use db-based-graph? when this fn and others moves to another ns
(if (string/starts-with? repo "logseq_db_")
db-ident
(get-in built-in-properties [db-ident :name])))
@ -231,13 +229,25 @@
(when (= (closed-value-name e) value-name)
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 (string/starts-with? k-name "logseq.property")
(string/starts-with? k-name "logseq.task")
(string/starts-with? k-name "user.property")))))
(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.

View File

@ -156,6 +156,7 @@
(remove (fn [[k _v]]
(or (integer? k)
(and (keyword? k)
;; filters out all logseq-ident-namespaces
(string/starts-with? (namespace k) "logseq.")))))
(into {}))
idents (remove nil?

View File

@ -7,7 +7,8 @@
[datascript.transit :as dt]
[datascript.impl.entity :as de]
[datascript.core :as d]
[cljs-bean.transit]))
[cljs-bean.transit]
[logseq.db.frontend.property :as db-property]))
(defonce db-version-prefix "logseq_db_")
(defonce file-version-prefix "logseq_local_")
@ -70,8 +71,7 @@
"Build a standard new property so that it is is consistent across contexts"
[db-ident prop-name prop-schema]
(assert (keyword? db-ident))
(let [db-ident' (if (or (= "user.property" (namespace db-ident))
(string/starts-with? (namespace db-ident) "logseq.")
(let [db-ident' (if (or (db-property/property? db-ident)
(contains? #{:block/tags :block/alias} db-ident))
db-ident
(keyword "user.property" (name db-ident)))]

View File

@ -16,7 +16,8 @@
[cljs-time.core :as t]
[cljs-time.format :as tf]
[logseq.db :as ldb]
[clojure.string :as string]))
[clojure.string :as string]
[logseq.db.frontend.property :as db-property]))
(def <q db-async-util/<q)
(def <pull db-async-util/<pull)
@ -58,7 +59,7 @@
(->> result
;; remove private built-in properties
(remove #(and (:db/ident %)
(string/starts-with? (namespace (:db/ident %)) "logseq.")
(db-property/logseq-property? (:db/ident %))
(not (get-in % [:block/schema :public?])))))))
(defn <get-all-property-names