mirror of
https://github.com/logseq/logseq.git
synced 2026-04-24 22:25:01 +00:00
chore: mv logseq.graph-parser.util.db to db dep
This ns is more appropriate in db and was only in graph-parser because the date-time-util lib wasn't accessible to db until #10933 landed. graph-parser dep is specific to file graphs and as much as possible anything unrelated to this should not be in this dep
This commit is contained in:
@@ -135,6 +135,8 @@
|
||||
logseq.common.util.page-ref page-ref
|
||||
logseq.common.util.block-ref block-ref
|
||||
logseq.db ldb
|
||||
logseq.db.frontend.content db-content
|
||||
logseq.db.frontend.inputs db-inputs
|
||||
logseq.db.frontend.property db-property
|
||||
logseq.db.frontend.property.type db-property-type
|
||||
logseq.db.frontend.property.util db-property-util
|
||||
@@ -147,7 +149,6 @@
|
||||
logseq.graph-parser.block gp-block
|
||||
logseq.graph-parser.mldoc gp-mldoc
|
||||
logseq.graph-parser.property gp-property
|
||||
logseq.graph-parser.util.db db-util
|
||||
logseq.outliner.core outliner-core
|
||||
logseq.outliner.op outliner-op
|
||||
logseq.outliner.pipeline outliner-pipeline
|
||||
|
||||
2
deps/db/.carve/ignore
vendored
2
deps/db/.carve/ignore
vendored
@@ -8,3 +8,5 @@ logseq.db.frontend.rules/extract-rules
|
||||
logseq.db.frontend.property.type/type-or-closed-value?
|
||||
;; Internal API
|
||||
logseq.db.frontend.rules/rules
|
||||
;; API
|
||||
logseq.db.frontend.inputs/resolve-input
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
(ns logseq.graph-parser.util.db
|
||||
"Db util fns that are useful for the frontend and nbb-logseq. This may be used
|
||||
by the graph-parser soon but if not, it should be in its own library"
|
||||
(ns logseq.db.frontend.inputs
|
||||
"Handles :inputs in queries"
|
||||
(:require [cljs-time.core :as t]
|
||||
[logseq.common.util.date-time :as date-time-util]
|
||||
[logseq.common.util :as common-util]
|
||||
@@ -17,9 +16,7 @@ it will return 1622433600000, which is equivalent to Mon May 31 2021 00 :00:00."
|
||||
([date hours mins secs millisecs]
|
||||
(.setHours (js/Date. date) hours mins secs millisecs)))
|
||||
|
||||
(def date->int date-time-util/date->int)
|
||||
|
||||
(defn old->new-relative-date-format [input]
|
||||
(defn- old->new-relative-date-format [input]
|
||||
(let [count (re-find #"^\d+" (name input))
|
||||
plus-minus (if (re-find #"after" (name input)) "+" "-")
|
||||
ms? (string/ends-with? (name input) "-ms")]
|
||||
@@ -33,11 +30,11 @@ it will return 1622433600000, which is equivalent to Mon May 31 2021 00 :00:00."
|
||||
(old->new-relative-date-format "1d-after-ms")
|
||||
(old->new-relative-date-format "1w-after-ms"))
|
||||
|
||||
(defn get-relative-date [input]
|
||||
(defn- get-relative-date [input]
|
||||
(case (or (namespace input) "today")
|
||||
"today" (t/today)))
|
||||
|
||||
(defn get-offset-date [relative-date direction amount unit]
|
||||
(defn- get-offset-date [relative-date direction amount unit]
|
||||
(let [offset-fn (case direction "+" t/plus "-" t/minus)
|
||||
offset-amount (parse-long amount)
|
||||
offset-unit-fn (case unit
|
||||
@@ -47,7 +44,7 @@ it will return 1622433600000, which is equivalent to Mon May 31 2021 00 :00:00."
|
||||
"y" t/years)]
|
||||
(offset-fn (offset-fn relative-date (offset-unit-fn offset-amount)))))
|
||||
|
||||
(defn get-ts-units
|
||||
(defn- get-ts-units
|
||||
"There are currently several time suffixes being used in inputs:
|
||||
- ms: milliseconds, will return a time relative to the direction the date is being adjusted
|
||||
- start: will return the time at the start of the day [00:00:00.000]
|
||||
@@ -69,7 +66,7 @@ it will return 1622433600000, which is equivalent to Mon May 31 2021 00 :00:00."
|
||||
(min 59 (parse-long (str s1 s2)))
|
||||
(min 999 (parse-long (str ms1 ms2 ms3)))])))
|
||||
|
||||
(defn keyword-input-dispatch [input]
|
||||
(defn- keyword-input-dispatch [input]
|
||||
(cond
|
||||
(#{:current-page :query-page :current-block :parent-block :today :yesterday :tomorrow :right-now-ms} input) input
|
||||
|
||||
@@ -101,13 +98,13 @@ it will return 1622433600000, which is equivalent to Mon May 31 2021 00 :00:00."
|
||||
(:db/id (:block/parent (d/entity db [:block/uuid current-block-uuid])))))
|
||||
|
||||
(defmethod resolve-keyword-input :today [_ _ _]
|
||||
(date->int (t/today)))
|
||||
(date-time-util/date->int (t/today)))
|
||||
|
||||
(defmethod resolve-keyword-input :yesterday [_ _ _]
|
||||
(date->int (t/minus (t/today) (t/days 1))))
|
||||
(date-time-util/date->int (t/minus (t/today) (t/days 1))))
|
||||
|
||||
(defmethod resolve-keyword-input :tomorrow [_ _ _]
|
||||
(date->int (t/plus (t/today) (t/days 1))))
|
||||
(date-time-util/date->int (t/plus (t/today) (t/days 1))))
|
||||
|
||||
(defmethod resolve-keyword-input :right-now-ms [_ _ _]
|
||||
(common-util/time-ms))
|
||||
@@ -125,7 +122,7 @@ it will return 1622433600000, which is equivalent to Mon May 31 2021 00 :00:00."
|
||||
(let [relative-to (get-relative-date input)
|
||||
[_ offset-direction offset offset-unit] (re-find #"^([+-])(\d+)([dwmy])$" (name input))
|
||||
offset-date (get-offset-date relative-to offset-direction offset offset-unit)]
|
||||
(date->int offset-date)))
|
||||
(date-time-util/date->int offset-date)))
|
||||
|
||||
;; relative-date-time returns an epoch int
|
||||
(defmethod resolve-keyword-input :relative-date-time [_ input _]
|
||||
2
deps/graph-parser/.carve/ignore
vendored
2
deps/graph-parser/.carve/ignore
vendored
@@ -7,8 +7,6 @@ logseq.graph-parser.mldoc/link?
|
||||
;; API
|
||||
logseq.graph-parser/get-blocks-to-delete
|
||||
;; API
|
||||
logseq.graph-parser.util.db/resolve-input
|
||||
;; API
|
||||
logseq.graph-parser.text/get-file-basename
|
||||
;; API
|
||||
logseq.graph-parser.mldoc/mldoc-link?
|
||||
|
||||
@@ -15,8 +15,8 @@
|
||||
[logseq.db.frontend.rules :as rules]
|
||||
[logseq.db.frontend.content :as db-content]
|
||||
[logseq.graph-parser.text :as text]
|
||||
[logseq.graph-parser.util.db :as db-util]
|
||||
[logseq.common.util :as common-util]
|
||||
[logseq.common.util.date-time :as date-time-util]
|
||||
[frontend.config :as config]
|
||||
[logseq.db :as ldb]))
|
||||
|
||||
@@ -601,7 +601,7 @@ independent of format as format specific heading characters are stripped"
|
||||
|
||||
(defn get-journals-length
|
||||
[]
|
||||
(let [today (db-util/date->int (js/Date.))]
|
||||
(let [today (date-time-util/date->int (js/Date.))]
|
||||
(d/q '[:find (count ?page) .
|
||||
:in $ ?today
|
||||
:where
|
||||
@@ -618,7 +618,7 @@ independent of format as format specific heading characters are stripped"
|
||||
(when (conn/get-db repo-url)
|
||||
(let [date (js/Date.)
|
||||
_ (.setDate date (- (.getDate date) (dec n)))
|
||||
today (db-util/date->int (js/Date.))]
|
||||
today (date-time-util/date->int (js/Date.))]
|
||||
(->>
|
||||
(react/q repo-url [:frontend.worker.react/journals] {:use-cache? false}
|
||||
'[:find [(pull ?page [*]) ...]
|
||||
|
||||
@@ -12,10 +12,10 @@
|
||||
[frontend.db.utils :as db-utils]
|
||||
[frontend.db.conn :as conn]
|
||||
[datascript.core :as d]
|
||||
[logseq.graph-parser.util.db :as db-util]
|
||||
[logseq.db.frontend.rules :as rules]
|
||||
[frontend.template :as template]
|
||||
[logseq.graph-parser.text :as text]
|
||||
[logseq.common.util.date-time :as date-time-util]
|
||||
[logseq.common.util.page-ref :as page-ref]
|
||||
[logseq.common.util :as common-util]
|
||||
[frontend.util.text :as text-util]
|
||||
@@ -57,13 +57,13 @@
|
||||
(let [input (string/lower-case (name input))]
|
||||
(cond
|
||||
(= "today" input)
|
||||
(db-util/date->int (t/today))
|
||||
(date-time-util/date->int (t/today))
|
||||
|
||||
(= "yesterday" input)
|
||||
(db-util/date->int (t/yesterday))
|
||||
(date-time-util/date->int (t/yesterday))
|
||||
|
||||
(= "tomorrow" input)
|
||||
(db-util/date->int (t/plus (t/today) (t/days 1)))
|
||||
(date-time-util/date->int (t/plus (t/today) (t/days 1)))
|
||||
|
||||
(page-ref/page-ref? input)
|
||||
(let [input (-> (page-ref/get-page-name input)
|
||||
@@ -80,7 +80,7 @@
|
||||
"m" t/months
|
||||
"w" t/weeks
|
||||
t/days)]
|
||||
(db-util/date->int (t/plus (t/today) (tf duration)))))))
|
||||
(date-time-util/date->int (t/plus (t/today) (tf duration)))))))
|
||||
|
||||
(defn- ->timestamp [input]
|
||||
(let [input (string/lower-case (name input))]
|
||||
|
||||
@@ -10,24 +10,24 @@
|
||||
[frontend.debug :as debug]
|
||||
[frontend.extensions.sci :as sci]
|
||||
[frontend.state :as state]
|
||||
[logseq.graph-parser.util.db :as db-util]
|
||||
[logseq.db.frontend.inputs :as db-inputs]
|
||||
[logseq.common.util.page-ref :as page-ref]
|
||||
[frontend.util :as util]
|
||||
[frontend.date :as date]
|
||||
[lambdaisland.glogi :as log]))
|
||||
|
||||
(defn resolve-input
|
||||
"Wrapper around db-util/resolve-input which provides editor-specific state"
|
||||
"Wrapper around db-inputs/resolve-input which provides editor-specific state"
|
||||
([db input]
|
||||
(resolve-input db input {}))
|
||||
([db input opts]
|
||||
(db-util/resolve-input db
|
||||
input
|
||||
(merge {:current-page-fn (fn []
|
||||
(or (state/get-current-page)
|
||||
(:page (state/get-default-home))
|
||||
(date/today)))}
|
||||
opts))))
|
||||
(db-inputs/resolve-input db
|
||||
input
|
||||
(merge {:current-page-fn (fn []
|
||||
(or (state/get-current-page)
|
||||
(:page (state/get-default-home))
|
||||
(date/today)))}
|
||||
opts))))
|
||||
|
||||
(defn custom-query-result-transform
|
||||
[query-result remove-blocks q]
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
[clojure.string :as string]
|
||||
[frontend.state :as state]
|
||||
[frontend.date :as date]
|
||||
[logseq.graph-parser.util.db :as db-util]
|
||||
[logseq.db.frontend.inputs :as db-inputs]
|
||||
[frontend.test.helper :as test-helper :refer [load-test-files]]
|
||||
[frontend.db.query-custom :as query-custom]
|
||||
[frontend.db.utils :as db-utils]
|
||||
@@ -64,6 +64,7 @@ adds rules that users often use"
|
||||
[?t :block/name ?tag-name]]}
|
||||
{:current-page-fn (constantly current-page)})))
|
||||
|
||||
;; TODO: Move most resolve-input tests to deps/db when a load-test-files helper is available for deps
|
||||
(deftest resolve-input-for-page-and-block-inputs
|
||||
(load-test-files [{:file/path "pages/page1.md"
|
||||
:file/content
|
||||
@@ -183,16 +184,16 @@ created-at:: %s
|
||||
created-at:: %s
|
||||
- +1y
|
||||
created-at:: %s"
|
||||
(db-util/date-at-local-ms (t/minus (t/today) (t/years 1)) 0 0 0 0)
|
||||
(db-util/date-at-local-ms (t/minus (t/today) (t/months 1)) 0 0 0 0)
|
||||
(db-util/date-at-local-ms (t/minus (t/today) (t/weeks 1)) 0 0 0 0)
|
||||
(db-util/date-at-local-ms (t/minus (t/today) (t/days 1)) 0 0 0 0)
|
||||
(db-util/date-at-local-ms (t/today) 12 0 0 0)
|
||||
(db-util/date-at-local-ms (t/today) 18 0 0 0)
|
||||
(db-util/date-at-local-ms (t/plus (t/today) (t/days 1)) 0 0 0 0)
|
||||
(db-util/date-at-local-ms (t/plus (t/today) (t/weeks 1)) 0 0 0 0)
|
||||
(db-util/date-at-local-ms (t/plus (t/today) (t/months 1)) 0 0 0 0)
|
||||
(db-util/date-at-local-ms (t/plus (t/today) (t/years 1)) 0 0 0 0))}])
|
||||
(db-inputs/date-at-local-ms (t/minus (t/today) (t/years 1)) 0 0 0 0)
|
||||
(db-inputs/date-at-local-ms (t/minus (t/today) (t/months 1)) 0 0 0 0)
|
||||
(db-inputs/date-at-local-ms (t/minus (t/today) (t/weeks 1)) 0 0 0 0)
|
||||
(db-inputs/date-at-local-ms (t/minus (t/today) (t/days 1)) 0 0 0 0)
|
||||
(db-inputs/date-at-local-ms (t/today) 12 0 0 0)
|
||||
(db-inputs/date-at-local-ms (t/today) 18 0 0 0)
|
||||
(db-inputs/date-at-local-ms (t/plus (t/today) (t/days 1)) 0 0 0 0)
|
||||
(db-inputs/date-at-local-ms (t/plus (t/today) (t/weeks 1)) 0 0 0 0)
|
||||
(db-inputs/date-at-local-ms (t/plus (t/today) (t/months 1)) 0 0 0 0)
|
||||
(db-inputs/date-at-local-ms (t/plus (t/today) (t/years 1)) 0 0 0 0))}])
|
||||
|
||||
(is (= ["today" "tonight"] (blocks-created-between-inputs :-0d-ms :+0d-ms))
|
||||
":+0d-ms and :-0d-ms resolve to correct datetime range")
|
||||
|
||||
Reference in New Issue
Block a user