|
|
@@ -133,8 +133,8 @@
|
|
|
(map second (re-seq page-ref/page-ref-re s))))
|
|
|
|
|
|
(defn- ->block-tx [{:keys [build/properties] :as m} page-uuids all-idents page-id
|
|
|
- {properties-config :properties :keys [build-existing-tx? existing-page?]}]
|
|
|
- (let [build-existing-tx?' (and build-existing-tx? (::existing-block? (meta m)) existing-page?)
|
|
|
+ {properties-config :properties :keys [build-existing-tx?]}]
|
|
|
+ (let [build-existing-tx?' (and build-existing-tx? (::existing-block? (meta m)) (not (:build/keep-uuid? m)))
|
|
|
block (if build-existing-tx?'
|
|
|
(select-keys m [:block/uuid])
|
|
|
{:db/id (new-db-id)
|
|
|
@@ -211,7 +211,7 @@
|
|
|
(defn- build-properties-tx [properties page-uuids all-idents {:keys [build-existing-tx?]}]
|
|
|
(let [properties' (if build-existing-tx?
|
|
|
(->> properties
|
|
|
- (remove (fn [[_ v]] (and (:block/uuid v) (not (:build/new-property? v)))))
|
|
|
+ (remove (fn [[_ v]] (and (:block/uuid v) (not (:build/keep-uuid? v)))))
|
|
|
(into {}))
|
|
|
properties)
|
|
|
property-db-ids (->> (keys properties')
|
|
|
@@ -225,7 +225,7 @@
|
|
|
(defn- build-classes-tx [classes properties-config uuid-maps all-idents {:keys [build-existing-tx?]}]
|
|
|
(let [classes' (if build-existing-tx?
|
|
|
(->> classes
|
|
|
- (remove (fn [[_ v]] (and (:block/uuid v) (not (:build/new-class? v)))))
|
|
|
+ (remove (fn [[_ v]] (and (:block/uuid v) (not (:build/keep-uuid? v)))))
|
|
|
(into {}))
|
|
|
classes)
|
|
|
class-db-ids (->> (keys classes')
|
|
|
@@ -280,14 +280,16 @@
|
|
|
[:block/title :string]
|
|
|
[:build/children {:optional true} [:vector [:ref ::block]]]
|
|
|
[:build/properties {:optional true} User-properties]
|
|
|
- [:build/tags {:optional true} [:vector Class]]]}}
|
|
|
+ [:build/tags {:optional true} [:vector Class]]
|
|
|
+ [:build/keep-uuid? {:optional true} :boolean]]}}
|
|
|
[:page [:and
|
|
|
[:map
|
|
|
[:block/uuid {:optional true} :uuid]
|
|
|
[:block/title {:optional true} :string]
|
|
|
[:build/journal {:optional true} :int]
|
|
|
[:build/properties {:optional true} User-properties]
|
|
|
- [:build/tags {:optional true} [:vector Class]]]
|
|
|
+ [:build/tags {:optional true} [:vector Class]]
|
|
|
+ [:build/keep-uuid? {:optional true} :boolean]]
|
|
|
[:fn {:error/message ":block/title, :block/uuid or :build/journal required"
|
|
|
:error/path [:block/title]}
|
|
|
(fn [m]
|
|
|
@@ -307,7 +309,8 @@
|
|
|
[:value [:or :string :double]]
|
|
|
[:uuid {:optional true} :uuid]
|
|
|
[:icon {:optional true} :map]]]]
|
|
|
- [:build/property-classes {:optional true} [:vector Class]]]])
|
|
|
+ [:build/property-classes {:optional true} [:vector Class]]
|
|
|
+ [:build/keep-uuid? {:optional true} :boolean]]])
|
|
|
|
|
|
(def Classes
|
|
|
[:map-of
|
|
|
@@ -315,7 +318,8 @@
|
|
|
[:map
|
|
|
[:build/properties {:optional true} User-properties]
|
|
|
[:build/class-parent {:optional true} Class]
|
|
|
- [:build/class-properties {:optional true} [:vector Property]]]])
|
|
|
+ [:build/class-properties {:optional true} [:vector Property]]
|
|
|
+ [:build/keep-uuid? {:optional true} :boolean]]])
|
|
|
|
|
|
(def Options
|
|
|
[:map
|
|
|
@@ -413,10 +417,7 @@
|
|
|
(vec
|
|
|
(mapcat
|
|
|
(fn [{:keys [page blocks]}]
|
|
|
- (let [;; For a page to be ignored it's important that it only sends a {:block/uuid UUID} map.
|
|
|
- ;; This allows import processes to append blocks to an existing page or to create a page
|
|
|
- ;; that is referenced by another page
|
|
|
- ignore-page-tx? (and build-existing-tx? (not (::new-page? (meta page))) (= '(:block/uuid) (keys page)))
|
|
|
+ (let [ignore-page-tx? (and build-existing-tx? (not (::new-page? (meta page))) (not (:build/keep-uuid? page)))
|
|
|
page' (if ignore-page-tx?
|
|
|
page
|
|
|
(merge
|
|
|
@@ -428,8 +429,7 @@
|
|
|
(dissoc page :db/id :block/name :block/title)))
|
|
|
page-id-fn' (if (and build-existing-tx? (not (::new-page? (meta page))))
|
|
|
#(vector :block/uuid (:block/uuid %))
|
|
|
- page-id-fn)
|
|
|
- opts' (assoc opts :existing-page? (and build-existing-tx? (not (::new-page? (meta page)))))]
|
|
|
+ page-id-fn)]
|
|
|
(into
|
|
|
;; page tx
|
|
|
(if ignore-page-tx?
|
|
|
@@ -438,7 +438,7 @@
|
|
|
;; blocks tx
|
|
|
(reduce (fn [acc m]
|
|
|
(into acc
|
|
|
- (->block-tx m page-uuids all-idents (page-id-fn' page') opts')))
|
|
|
+ (->block-tx m page-uuids all-idents (page-id-fn' page') opts)))
|
|
|
[]
|
|
|
blocks))))
|
|
|
pages-and-blocks)))
|
|
|
@@ -641,11 +641,13 @@
|
|
|
* :build/journal - Define a journal pages as an integer e.g. 20240101 is Jan 1, 2024. :block/title
|
|
|
is not required if using this since it generates one
|
|
|
* :build/properties - Defines properties on a page
|
|
|
+ * :build/keep-uuid? - Keeps :block/uuid because another block depends on it
|
|
|
* :blocks - This is a vec of datascript attribute maps for blocks with
|
|
|
:block/title required. e.g. `{:block/title \"bar\"}`. Additional keys available:
|
|
|
* :build/children - A vec of blocks that are nested (indented) under the current block.
|
|
|
Allows for outlines to be expressed to whatever depth
|
|
|
* :build/properties - Defines properties on a block
|
|
|
+ * :build/keep-uuid? - Keeps :block/uuid because another block depends on it
|
|
|
* :properties - This is a map to configure properties where the keys are property name keywords
|
|
|
and the values are maps of datascript attributes e.g. `{:logseq.property/type :checkbox}`.
|
|
|
Additional keys available:
|
|
|
@@ -654,18 +656,21 @@
|
|
|
* :build/property-classes - Vec of class name keywords. Defines a property's range classes
|
|
|
* :build/properties-ref-types - Map of internal ref types to public ref types that are valid only for this property.
|
|
|
Useful when remapping value ref types e.g. for :logseq.property/default-value
|
|
|
+ * :build/keep-uuid? - Keeps :block/uuid because another block depends on it
|
|
|
* :classes - This is a map to configure classes where the keys are class name keywords
|
|
|
and the values are maps of datascript attributes e.g. `{:block/title \"Foo\"}`.
|
|
|
Additional keys available:
|
|
|
* :build/properties - Define properties on a class page
|
|
|
* :build/class-parent - Add a class parent by its keyword name
|
|
|
* :build/class-properties - Vec of property name keywords. Defines properties that a class gives to its objects
|
|
|
+ * :build/keep-uuid? - Keeps :block/uuid because another block depends on it
|
|
|
* :graph-namespace - namespace to use for db-ident creation. Useful when importing an ontology
|
|
|
* :auto-create-ontology? - When set to true, creates properties and classes from their use.
|
|
|
See auto-create-ontology for more details
|
|
|
* :build-existing-tx? - When set to true, blocks, pages, properties and classes with :block/uuid are treated as
|
|
|
existing in DB and are skipped for creation. This is useful for building tx on existing DBs e.g. for importing.
|
|
|
- Blocks are updated with any attributes passed to it while all other node types are ignored for update.
|
|
|
+ Blocks are updated with any attributes passed to it while all other node types are ignored for update unless
|
|
|
+ :build/keep-uuid? is set.
|
|
|
* :page-id-fn - custom fn that returns ent lookup id for page refs e.g. `[:block/uuid X]`
|
|
|
Default is :db/id
|
|
|
|