enhance(db-worker): remove direct-pass in thread-api calling

This commit is contained in:
rcmerci
2026-05-03 20:00:41 +08:00
parent 7b68c57056
commit 17ae997013
47 changed files with 598 additions and 606 deletions

View File

@@ -85,7 +85,6 @@
(p/let [runtime (db-worker/ensure-runtime! db-name window-id)]
(cli-transport/invoke runtime
:thread-api/backup-db-sqlite
false
[db-name dst-path]))))))
(defn- active-repo-window-ids

View File

@@ -35,20 +35,17 @@
#?(:cljs
(defn remote-function
"Return a promise whose value is transit-str."
[qualified-kw-str direct-pass? args-transit-str-or-args-array]
[qualified-kw-str args-transit-str]
(let [qkw (keyword qualified-kw-str)]
(vswap! *profile update qkw inc)
(if-let [f (@*thread-apis qkw)]
(let [result (apply f (cond-> args-transit-str-or-args-array
(not direct-pass?) ldb/read-transit-str))
(let [result (apply f (ldb/read-transit-str args-transit-str))
result-promise
(if (fn? result) ;; missionary task is a fn
(js/Promise. result)
result)]
(->
(p/let [result' result-promise]
(if direct-pass?
result'
(write-transit-str-with-catch result' qualified-kw-str)))
(write-transit-str-with-catch result' qualified-kw-str))
(p/catch (fn [e] (write-transit-str-with-catch e qualified-kw-str)))))
(throw (ex-info (str "not found thread-api: " qualified-kw-str) {}))))))

View File

@@ -61,9 +61,9 @@
(defn- <invoke-worker-get-blocks
[graph requests]
(p/let [result-transit-str
(state/<invoke-db-worker-direct-pass :thread-api/get-blocks
graph
(ldb/write-transit-str requests))]
(state/<invoke-db-worker :thread-api/get-blocks
graph
(ldb/write-transit-str requests))]
(some-> result-transit-str ldb/read-transit-str)))
(defonce ^:private *get-blocks-batch-enabled? (atom true))

View File

@@ -103,24 +103,6 @@
(string/replace #"[\\/]+" "_")
(str "_client_ops_" (quot (util/time-ms) 1000))))
(defn- ->uint8array
[data]
(cond
(instance? js/Uint8Array data)
data
(js/ArrayBuffer.isView data)
(js/Uint8Array. (.-buffer data) (.-byteOffset data) (.-byteLength data))
(instance? js/ArrayBuffer data)
(js/Uint8Array. data)
(array? data)
(js/Uint8Array. data)
:else
nil))
(defn- <fetch-server-checksum-diagnostics
[repo]
(let [base (rtc-handler/http-base)
@@ -230,9 +212,9 @@
(defn ^:export export-client-ops-sqlite
[]
(if-let [repo (state/get-current-repo)]
(-> (state/<invoke-db-worker-direct-pass :thread-api/export-client-ops-db repo)
(-> (state/<invoke-db-worker :thread-api/export-client-ops-db-base64 repo)
(p/then (fn [data]
(if-let [payload (->uint8array data)]
(if-let [payload (some-> data util/base64string-to-unit8array)]
(let [filename (client-ops-export-file-name repo)
blob (js/Blob. #js [payload] (clj->js {:type "application/octet-stream"}))]
(utils/saveToFile blob filename "sqlite")

View File

@@ -114,7 +114,7 @@
(if (electron-runtime?)
(if (= repo @remote-repo)
(if-let [remote-client @remote-db]
(p/let [_ (-> (remote/invoke! (:client remote-client) "thread-api/close-db" false [repo])
(p/let [_ (-> (remote/invoke! (:client remote-client) "thread-api/close-db" [repo])
(p/catch (fn [_] nil)))
_ (<stop-remote-if-current! repo)]
nil)

View File

@@ -147,16 +147,11 @@
"&publishing=" config/publishing?))
_ (set-worker-fs worker)
wrapped-worker* (Comlink/wrap worker)
wrapped-worker (fn [qkw direct-pass? & args]
wrapped-worker (fn [qkw & args]
(p/let [result (.remoteInvoke ^js wrapped-worker*
(str (namespace qkw) "/" (name qkw))
direct-pass?
(if direct-pass?
(into-array args)
(ldb/write-transit-str args)))]
(if direct-pass?
result
(ldb/read-transit-str result))))
(ldb/write-transit-str args))]
(ldb/read-transit-str result)))
t1 (util/time-ms)]
(reset! state/*db-worker-thread worker)
(Comlink/expose #js{"remoteInvoke" thread-api/remote-function} worker)
@@ -219,7 +214,8 @@
(p/catch sqlite-error-handler)))
(<export-db [_this repo opts]
(-> (p/let [data (state/<invoke-db-worker-direct-pass :thread-api/export-db repo)]
(-> (p/let [base64 (state/<invoke-db-worker :thread-api/export-db-base64 repo)
data (some-> base64 util/base64string-to-unit8array)]
(when data
(if (:return-data? opts)
data
@@ -230,8 +226,8 @@
(<import-db [_this repo data]
(->
(p/let [result-str (state/<invoke-db-worker-direct-pass :thread-api/import-db repo data)]
(ldb/read-transit-str result-str))
(p/let [base64 (util/unit8array-to-base64string data)]
(state/<invoke-db-worker :thread-api/import-db-base64 repo base64))
(p/catch (fn [error]
(log/error :import-db-error repo error "SQLiteDB import error")
(notification/show! (t :storage/sqlitedb-import-error error) :error) {})))))

View File

@@ -2,6 +2,7 @@
"Remote `PersistentDB` implementation for Electron renderer via db-worker-node HTTP and SSE."
(:require [clojure.string :as string]
[frontend.persist-db.protocol :as protocol]
[frontend.util :as util]
[logseq.db :as ldb]
[promesa.core :as p]
[lambdaisland.glogi :as log]
@@ -94,15 +95,10 @@
:reconnect-delay-ms (or reconnect-delay-ms 1000))))
(defn invoke!
[{:keys [base-url auth-token fetch-fn]} method direct-pass? args]
[{:keys [base-url auth-token fetch-fn]} method args]
(let [payload (js/JSON.stringify
(clj->js (if direct-pass?
{:method method
:directPass true
:args args}
{:method method
:directPass false
:argsTransit (ldb/write-transit-str args)})))]
(clj->js {:method method
:argsTransit (ldb/write-transit-str args)}))]
(p/let [{:keys [status body]}
(fetch-fn {:method "POST"
:url (invoke-url base-url)
@@ -110,9 +106,7 @@
:body payload})
parsed (parse-response-body body)]
(if (<= 200 status 299)
(if direct-pass?
(:result parsed)
(ldb/read-transit-str (:resultTransit parsed)))
(ldb/read-transit-str (:resultTransit parsed))
(let [error (:error parsed)]
(throw (ex-info (or (:message error) "db-worker invoke failed")
(cond-> {:status status
@@ -163,28 +157,29 @@
(defrecord InRemote [client wrapped-worker disconnect!]
protocol/PersistentDB
(<new [_this repo opts]
(invoke! client "thread-api/create-or-open-db" false [repo opts]))
(invoke! client "thread-api/create-or-open-db" [repo opts]))
(<list-db [_this]
(invoke! client "thread-api/list-db" false []))
(invoke! client "thread-api/list-db" []))
(<unsafe-delete [_this repo]
(invoke! client "thread-api/unsafe-unlink-db" false [repo]))
(invoke! client "thread-api/unsafe-unlink-db" [repo]))
(<release-access-handles [_this repo]
(invoke! client "thread-api/release-access-handles" false [repo]))
(invoke! client "thread-api/release-access-handles" [repo]))
(<fetch-initial-data [_this repo opts]
(p/let [_ (invoke! client "thread-api/create-or-open-db" false [repo opts])]
(invoke! client "thread-api/get-initial-data" false [repo opts])))
(p/let [_ (invoke! client "thread-api/create-or-open-db" [repo opts])]
(invoke! client "thread-api/get-initial-data" [repo opts])))
(<export-db [_this repo _opts]
(invoke! client "thread-api/export-db" true [repo]))
(p/let [base64 (invoke! client "thread-api/export-db-base64" [repo])]
(some-> base64 util/base64string-to-unit8array)))
(<import-db [_this repo data]
(->
(p/let [result-str (invoke! client "thread-api/import-db" true [repo data])]
(ldb/read-transit-str result-str))
(p/let [base64 (util/unit8array-to-base64string data)]
(invoke! client "thread-api/import-db-base64" [repo base64]))
(p/catch (fn [error]
(log/error :import-db-error repo error "SQLiteDB import error")
(notification/show! (t :storage/sqlitedb-import-error error) :error) {})))))
@@ -192,8 +187,8 @@
(defn start!
[{:keys [base-url auth-token event-handler] :as opts}]
(let [client (create-client (assoc opts :base-url base-url :auth-token auth-token))
wrapped-worker (fn [qkw direct-pass? & args]
(invoke! client (method->str qkw) direct-pass? args))
wrapped-worker (fn [qkw & args]
(invoke! client (method->str qkw) args))
{:keys [disconnect!]} (connect-events! (assoc client
:event-handler event-handler
:auth-token auth-token)

View File

@@ -64,24 +64,14 @@
(->> (m/watch *db-worker)
(m/eduction (map some?))))
(defn- <invoke-db-worker*
[qkw direct-pass? args-list]
(defn <invoke-db-worker
"invoke db-worker thread api"
[qkw & args]
(let [worker @*db-worker]
(when (nil? worker)
(prn :<invoke-db-worker-error qkw)
(throw (ex-info "db-worker has not been initialized" {})))
(apply worker qkw direct-pass? args-list)))
(defn <invoke-db-worker
"invoke db-worker thread api"
[qkw & args]
(<invoke-db-worker* qkw false args))
(defn <invoke-db-worker-direct-pass
"invoke db-worker thread api.
But directly pass args to db-worker, and result from db-worker as well."
[qkw & args]
(<invoke-db-worker* qkw true args))
(apply worker qkw args)))
;; Stores main application state
(defonce ^:large-vars/data-var state

View File

@@ -105,6 +105,23 @@
#?(:cljs (defonce convert-to-letters utils/convertToLetters))
#?(:cljs (defonce hsl2hex utils/hsl2hex))
#?(:cljs (defonce base64string-to-unit8array utils/base64ToUint8Array))
#?(:cljs
(defn unit8array-to-base64string
[payload]
(when payload
(let [buffer (cond
(instance? js/Buffer payload)
payload
(instance? js/Uint8Array payload)
(js/Buffer.from payload)
(instance? js/ArrayBuffer payload)
(js/Buffer.from payload)
:else
(js/Buffer.from payload))]
(.toString buffer "base64")))))
#?(:cljs (def string-join-path common-util/string-join-path))

View File

@@ -886,14 +886,18 @@
[repo]
(<db-exists? repo))
(def-thread-api :thread-api/export-db
(def-thread-api :thread-api/export-db-base64
[repo]
(when-let [^js db (worker-state/get-sqlite-conn repo :db)]
(checkpoint-db! repo db))
(p/let [data (<export-db-file repo)]
(platform/transfer (platform/current) data #js [(.-buffer data)])))
(when data
(let [buffer (if (instance? js/Buffer data)
data
(js/Buffer.from data))]
(.toString buffer "base64")))))
(def-thread-api :thread-api/export-client-ops-db
(def-thread-api :thread-api/export-client-ops-db-base64
[repo]
(when-let [^js db (worker-state/get-sqlite-conn repo :client-ops)]
(checkpoint-db! repo db))
@@ -910,19 +914,11 @@
(str "/client-ops" repo-path)
(str "client-ops-" repo-path)]]
(p/let [payload (<export-db-file-with-paths repo export-paths)]
(when (instance? js/Uint8Array payload)
(platform/transfer (platform/current) payload #js [(.-buffer payload)])))))
(def-thread-api :thread-api/export-db-base64
[repo]
(when-let [^js db (worker-state/get-sqlite-conn repo :db)]
(checkpoint-db! repo db))
(p/let [data (<export-db-file repo)]
(when data
(let [buffer (if (instance? js/Buffer data)
data
(js/Buffer.from data))]
(.toString buffer "base64")))))
(when payload
(let [buffer (if (instance? js/Buffer payload)
payload
(js/Buffer.from payload))]
(.toString buffer "base64"))))))
(def-thread-api :thread-api/backup-db-sqlite
[repo dst-path]
@@ -940,14 +936,6 @@
(p/let [_ (backup-db-fn db dst-path)]
{:path dst-path}))))
(def-thread-api :thread-api/import-db
[repo data]
(when-not (string/blank? repo)
(p/let [pool (<get-opfs-pool repo)
payload (require-sqlite-payload repo data)]
(<import-db pool payload)
nil)))
(def-thread-api :thread-api/import-db-base64
[repo base64]
(when-not (string/blank? repo)

View File

@@ -42,14 +42,9 @@
(* 1000 25))
(Comlink/expose proxy-object)
(let [^js wrapped-main-thread* (Comlink/wrap js/self)
wrapped-main-thread (fn [qkw direct-pass? & args]
wrapped-main-thread (fn [qkw & args]
(p/let [result (.remoteInvoke wrapped-main-thread*
(str (namespace qkw) "/" (name qkw))
direct-pass?
(if direct-pass?
(into-array args)
(ldb/write-transit-str args)))]
(if direct-pass?
result
(ldb/read-transit-str result))))]
(ldb/write-transit-str args))]
(ldb/read-transit-str result)))]
(reset! worker-state/*main-thread wrapped-main-thread))))

View File

@@ -120,12 +120,10 @@
(swap! *sse-clients disj res))))
(defn- <invoke!
[^js proxy method-str method-kw direct-pass? args]
(let [args' (if direct-pass?
(into-array (or args []))
(if (string? args)
args
(ldb/write-transit-str args)))
[^js proxy method-str method-kw args]
(let [args-transit (if (string? args)
args
(ldb/write-transit-str args))
started-at (js/Date.now)
timeout-id (js/setTimeout
(fn []
@@ -133,7 +131,7 @@
{:method (or method-kw method-str)
:elapsed-ms (- (js/Date.now) started-at)}))
10000)]
(-> (p/do! (.remoteInvoke proxy method-str (boolean direct-pass?) args'))
(-> (p/do! (.remoteInvoke proxy method-str args-transit))
(p/finally (fn []
(js/clearTimeout timeout-id))))))
@@ -141,7 +139,7 @@
[proxy]
(let [method-kw :thread-api/init
method-str (normalize-method-str method-kw)]
(<invoke! proxy method-str method-kw true #js [])))
(<invoke! proxy method-str method-kw [])))
(defn- <close-bound-repo!
[proxy repo]
@@ -149,7 +147,7 @@
(p/resolved nil)
(let [method-kw :thread-api/close-db
method-str (normalize-method-str method-kw)]
(-> (<invoke! proxy method-str method-kw false [repo])
(-> (<invoke! proxy method-str method-kw [repo])
(p/catch (fn [error]
(log/warn :db-worker-node-close-db-before-stop-failed
{:repo repo
@@ -196,7 +194,6 @@
(def ^:private write-methods
#{:thread-api/transact
:thread-api/import-db
:thread-api/import-db-base64
:thread-api/backup-db-sqlite
:thread-api/import-edn
@@ -237,7 +234,7 @@
(defn- set-main-thread-stub!
[]
(reset! worker-state/*main-thread
(fn [qkw _direct-pass? & _args]
(fn [qkw & _args]
(p/rejected (ex-info "main-thread is not available in db-worker-node"
{:method qkw})))))
@@ -305,27 +302,20 @@
(if (= method "POST")
(-> (p/let [body (<read-body req)
payload (js/JSON.parse body)
{:keys [method directPass argsTransit args]} (js->clj payload :keywordize-keys true)
{:keys [method argsTransit args]} (js->clj payload :keywordize-keys true)
method-kw (normalize-method-kw method)
method-str (normalize-method-str method)
direct-pass? (boolean directPass)
args' (if direct-pass?
args
(or argsTransit args))
args-for-validation (if direct-pass?
args'
(if (string? args')
(ldb/read-transit-str args')
args'))]
args' (or argsTransit args)
args-for-validation (if (string? args')
(ldb/read-transit-str args')
args')]
(if-let [{:keys [status error]} (repo-error method-kw args-for-validation bound-repo)]
(send-json! res status {:ok false :error error})
(p/let [_ (when (contains? write-methods method-kw)
(let [{:keys [path lock]} @*lock-info]
(db-lock/assert-lock-owner! path lock)))
result (<invoke! proxy method-str method-kw direct-pass? args')]
(send-json! res 200 (if direct-pass?
{:ok true :result result}
{:ok true :resultTransit result})))))
result (<invoke! proxy method-str method-kw args')]
(send-json! res 200 {:ok true :resultTransit result}))))
(p/catch (fn [error]
(let [data (ex-data error)
status (invoke-error-status data)
@@ -585,7 +575,7 @@
_ (reset! *lock-info {:path path :lock lock})
_ (let [method-kw :thread-api/create-or-open-db
method-str (normalize-method-str method-kw)]
(<invoke! proxy method-str method-kw false [repo (startup-db-opts opts)]))]
(<invoke! proxy method-str method-kw [repo (startup-db-opts opts)]))]
(start-http-server! {:proxy proxy
:repo repo
:host host

View File

@@ -146,9 +146,3 @@
[platform type payload]
(when-let [f (get-in platform [:broadcast :post-message!])]
(f type payload)))
(defn transfer
[platform data transferables]
(if-let [f (get-in platform [:storage :transfer])]
(f data transferables)
data))

View File

@@ -10,7 +10,7 @@
(defn <invoke-main-thread
[qkw & args]
(if-let [main-thread @*main-thread]
(apply main-thread qkw false args)
(apply main-thread qkw args)
(p/rejected (ex-info "main thread is not available in db-worker"
{:method qkw}))))

View File

@@ -20,7 +20,7 @@
(defn- today-page-title
[config repo]
(p/let [journal (transport/invoke config :thread-api/pull false
(p/let [journal (transport/invoke config :thread-api/pull
[repo [:logseq.property.journal/title-format] :logseq.class/Journal])
formatter (or (:logseq.property.journal/title-format journal) "MMM do, yyyy")
now (-> (js/Date.)
@@ -33,7 +33,7 @@
of entity maps. Because :block/name is not unique (a tag, property and page
can share the same name), callers should check for ambiguity."
[config repo page-name selector]
(p/let [results (transport/invoke config :thread-api/q false
(p/let [results (transport/invoke config :thread-api/q
[repo
[{:find [[(list 'pull '?e selector) '...]]
:in '[$ ?name]
@@ -67,15 +67,15 @@
(if (:db/id page)
page
(let [page-name-lc (common-util/page-name-sanity-lc page-name)]
(p/let [_ (transport/invoke config :thread-api/apply-outliner-ops false
(p/let [_ (transport/invoke config :thread-api/apply-outliner-ops
[repo [[:create-page [page-name {}]]] {}])]
(transport/invoke config :thread-api/pull false
(transport/invoke config :thread-api/pull
[repo [:db/id :block/uuid :block/name :block/title] [:block/name page-name-lc]]))))))
(defn pull-tag-by-name
"Look up a tag by name, constrained to entities tagged with :logseq.class/Tag."
[config repo tag-name selector]
(p/let [result (transport/invoke config :thread-api/q false
(p/let [result (transport/invoke config :thread-api/q
[repo
[{:find [[(list 'pull '?e selector) '...]]
:in '[$ ?name]
@@ -88,7 +88,7 @@
(defn pull-property-by-name
"Look up a property by name, constrained to entities tagged with :logseq.class/Property."
[config repo property-name selector]
(p/let [result (transport/invoke config :thread-api/q false
(p/let [result (transport/invoke config :thread-api/q
[repo
[{:find [[(list 'pull '?e selector) '...]]
:in '[$ ?name]
@@ -229,7 +229,7 @@
:reason :missing-created-uuids}))
(p/let [entities (p/all
(map (fn [block-uuid]
(transport/invoke config :thread-api/pull false
(transport/invoke config :thread-api/pull
[repo [:db/id :block/uuid] [:block/uuid block-uuid]]))
ordered-uuids))]
(created-ids-in-order ordered-uuids entities :block)))))
@@ -306,7 +306,7 @@
(when (seq uuid-refs)
(p/all
(map (fn [uuid-ref]
(p/let [entity (transport/invoke config :thread-api/pull false
(p/let [entity (transport/invoke config :thread-api/pull
[repo [:db/id :block/uuid] [:block/uuid (uuid uuid-ref)]])]
(when-not (:db/id entity)
(throw (ex-info (str "block ref not found: " uuid-ref)
@@ -322,7 +322,7 @@
(p/let [entities (p/all
(map (fn [id-str]
(let [id (parse-long id-str)]
(p/let [entity (transport/invoke config :thread-api/pull false
(p/let [entity (transport/invoke config :thread-api/pull
[repo [:db/id :block/uuid :block/title] id])]
(when-not (:db/id entity)
(throw (ex-info (str "id ref not found: " id-str)
@@ -706,7 +706,7 @@
(defn- pull-entity
[config repo selector lookup]
(transport/invoke config :thread-api/pull false [repo selector lookup]))
(transport/invoke config :thread-api/pull [repo selector lookup]))
(defn- tag-lookup-ref
[tag]
@@ -1054,14 +1054,14 @@
[config {:keys [repo target-id target-uuid target-page-name]}]
(cond
(some? target-id)
(p/let [block (transport/invoke config :thread-api/pull false
(p/let [block (transport/invoke config :thread-api/pull
[repo [:db/id :block/uuid :block/title] target-id])]
(if-let [block-uuid (:block/uuid block)]
block-uuid
(throw (ex-info "target block not found" {:code :target-not-found}))))
(seq target-uuid)
(p/let [block (transport/invoke config :thread-api/pull false
(p/let [block (transport/invoke config :thread-api/pull
[repo [:db/id :block/uuid :block/title] [:block/uuid (uuid target-uuid)]])]
(if-let [block-uuid (:block/uuid block)]
block-uuid
@@ -1207,7 +1207,7 @@
(into (map (fn [[k v]]
[:batch-set-property [block-uuids k v {}]])
properties)))
apply-result (transport/invoke cfg :thread-api/apply-outliner-ops false [(:repo action) ops {}])
apply-result (transport/invoke cfg :thread-api/apply-outliner-ops [(:repo action) ops {}])
created-ids (resolve-created-block-ids cfg (:repo action) blocks-for-insert apply-result)]
{:status :ok
:data {:result created-ids}})))

View File

@@ -85,7 +85,7 @@
(defn execute-debug-pull
[action config]
(-> (p/let [cfg (cli-server/ensure-server! config (:repo action))
entity (transport/invoke cfg :thread-api/pull false
entity (transport/invoke cfg :thread-api/pull
[(:repo action) (:selector action) (:lookup action)])]
(if (some? entity)
{:status :ok

View File

@@ -264,7 +264,6 @@
:action {:type :invoke
:command :graph-create
:method :thread-api/create-or-open-db
:direct-pass? false
:args [repo {}]
:repo repo
:graph (core/repo->graph repo)
@@ -296,7 +295,6 @@
:action {:type :invoke
:command :graph-validate
:method :thread-api/validate-db
:direct-pass? false
:args [repo options]
:repo repo
:graph (core/repo->graph repo)}})
@@ -442,7 +440,6 @@
_ (fs/mkdirSync dir-path #js {:recursive true})
_ (transport/invoke cfg
:thread-api/backup-db-sqlite
true
[(:repo action) db-path])]
{:status :ok
:data {:backup-name backup-name
@@ -503,7 +500,6 @@
(p/resolved config))
result (transport/invoke cfg
(:method action)
(:direct-pass? action)
(:args action))]
(when-let [repo (:persist-repo action)]
(cli-config/update-config! config {:graph repo}))
@@ -561,7 +557,7 @@
(or (get kv key)
(get kv (str ":" key))))]
(-> (p/let [cfg (cli-server/ensure-server! config (:repo action))
rows (transport/invoke cfg :thread-api/q false [(:repo action) [graph-info-kv-query]])
rows (transport/invoke cfg :thread-api/q [(:repo action) [graph-info-kv-query]])
kv (reduce (fn [acc [ident value]]
(assoc acc (ident->kv-key ident) value))
{}
@@ -584,7 +580,6 @@
export-result (when (= export-type "edn")
(transport/invoke cfg
:thread-api/export-edn
false
[(:repo action) payload]))
_ (case export-type
"edn"
@@ -594,7 +589,6 @@
"sqlite"
(transport/invoke cfg
:thread-api/backup-db-sqlite
true
[(:repo action) (:file action)])
(throw (ex-info "unsupported export type" {:export-type export-type}))) ]
{:status :ok
@@ -618,8 +612,7 @@
method (if (= import-type "sqlite")
:thread-api/import-db-base64
:thread-api/import-edn)
direct-pass? (= import-type "sqlite")
_ (transport/invoke cfg method direct-pass? [(:repo action) payload])
_ (transport/invoke cfg method [(:repo action) payload])
_ (cli-server/restart-server! config (:repo action))]
{:status :ok
:data {:new-graph? new-graph?

View File

@@ -334,7 +334,7 @@
[action config]
(-> (p/let [cfg (cli-server/ensure-server! config (:repo action))
options (:options action)
items (transport/invoke cfg :thread-api/cli-list-pages false
items (transport/invoke cfg :thread-api/cli-list-pages
[(:repo action) options])
sort-field (effective-sort-field options)
order (or (:order options) "desc")
@@ -352,7 +352,7 @@
options (cond-> (:options action)
((some-fn :with-extends :with-properties) (:options action))
(assoc :expand true))
items (transport/invoke cfg :thread-api/cli-list-tags false
items (transport/invoke cfg :thread-api/cli-list-tags
[(:repo action) options])
sort-field (effective-sort-field options)
order (or (:order options) "desc")
@@ -370,7 +370,7 @@
(-> (p/let [cfg (cli-server/ensure-server! config (:repo action))
options (cond-> (:options action)
(:with-classes (:options action)) (assoc :expand true))
items (transport/invoke cfg :thread-api/cli-list-properties false
items (transport/invoke cfg :thread-api/cli-list-properties
[(:repo action) options])
sort-field (effective-sort-field options)
order (or (:order options) "desc")
@@ -426,7 +426,7 @@
worker-options (cond-> (dissoc options :tags :properties)
(seq tag-ids) (assoc :tag-ids tag-ids)
(seq property-idents) (assoc :property-idents property-idents))
items (transport/invoke cfg :thread-api/cli-list-nodes false
items (transport/invoke cfg :thread-api/cli-list-nodes
[(:repo action) worker-options])
sort-field (effective-sort-field options)
order (or (:order options) "desc")
@@ -443,7 +443,7 @@
(defn- ensure-asset-tag-id!
[config repo]
(p/let [entity (transport/invoke config :thread-api/pull false
(p/let [entity (transport/invoke config :thread-api/pull
[repo [:db/id] [:db/ident asset-tag-ident]])]
(if-let [tag-id (:db/id entity)]
tag-id
@@ -456,7 +456,7 @@
options (:options action)
asset-tag-id (ensure-asset-tag-id! cfg (:repo action))
worker-options (assoc options :tag-ids [asset-tag-id])
items (transport/invoke cfg :thread-api/cli-list-nodes false
items (transport/invoke cfg :thread-api/cli-list-nodes
[(:repo action) worker-options])
sort-field (effective-sort-field options)
order (or (:order options) "desc")
@@ -480,7 +480,7 @@
options (:options action)
status-input (some-> (:status options) string/trim)
available-statuses (when (seq status-input)
(transport/invoke cfg :thread-api/q false
(transport/invoke cfg :thread-api/q
[(:repo action)
[task-status-command/status-closed-values-query]]))
resolved-status (when (seq status-input)
@@ -494,7 +494,7 @@
(assoc :status resolved-status)
(seq (some-> (:priority options) string/trim))
(assoc :priority (normalize-priority (:priority options))))]
(p/let [items (transport/invoke cfg :thread-api/cli-list-tasks false
(p/let [items (transport/invoke cfg :thread-api/cli-list-tasks
[(:repo action) normalized-options])
sort-field (effective-sort-field normalized-options)
order (or (:order normalized-options) "desc")

View File

@@ -282,7 +282,7 @@
args (cond-> (into [(:query action)] (:inputs action))
(= '% (last (:in query-map)))
(conj (rules/extract-rules rules/db-query-dsl-rules)))
results (transport/invoke cfg :thread-api/q false [(:repo action) args])]
results (transport/invoke cfg :thread-api/q [(:repo action) args])]
{:status :ok
:data {:result results}}))))

View File

@@ -105,26 +105,26 @@
(defn- fetch-block-by-id
[config repo id]
(transport/invoke config :thread-api/pull false
(transport/invoke config :thread-api/pull
[repo block-id-selector id]))
(defn- fetch-block-by-uuid
[config repo uuid-str]
(p/let [entity (transport/invoke config :thread-api/pull false
(p/let [entity (transport/invoke config :thread-api/pull
[repo block-id-selector [:block/uuid (uuid uuid-str)]])]
(if (:db/id entity)
entity
(transport/invoke config :thread-api/pull false
(transport/invoke config :thread-api/pull
[repo block-id-selector [:block/uuid uuid-str]]))))
(defn- delete-block-uuids
[config repo block-uuids]
(transport/invoke config :thread-api/apply-outliner-ops false
(transport/invoke config :thread-api/apply-outliner-ops
[repo [[:delete-blocks [block-uuids {}]]] {}]))
(defn- delete-page-by-uuid
[config repo page-uuid]
(p/let [result (transport/invoke config :thread-api/apply-outliner-ops false
(p/let [result (transport/invoke config :thread-api/apply-outliner-ops
[repo [[:delete-page [page-uuid {}]]] {}])]
(if (nil? result) true result)))
@@ -202,7 +202,7 @@
(defn- resolve-page-by-id
[config repo id]
(transport/invoke config :thread-api/pull false
(transport/invoke config :thread-api/pull
[repo page-id-selector id]))
(defn- item-id
@@ -229,7 +229,7 @@
(defn- list-matches-by-name
[config repo method name]
(let [normalized (normalize-name name)]
(p/let [items (transport/invoke config method false [repo {:include-built-in true :expand true}])
(p/let [items (transport/invoke config method [repo {:include-built-in true :expand true}])
matches (->> (or items [])
(filter (fn [item]
(= normalized (normalize-name (item-name item)))))
@@ -353,7 +353,7 @@
(if-not (:ok? resolved)
{:status :error
:error (:error resolved)}
(p/let [entity (transport/invoke config :thread-api/pull false
(p/let [entity (transport/invoke config :thread-api/pull
[(:repo action) entity-selector (:lookup resolved)])
validation (validate-fn entity)]
(if-not (:ok? validation)

View File

@@ -121,7 +121,7 @@
[action config]
(-> (p/let [cfg (cli-server/ensure-server! config (:repo action))
query (query-by-command (:type action))
result (transport/invoke cfg :thread-api/q false
result (transport/invoke cfg :thread-api/q
[(:repo action) [query (:query action)]])
;; Hide recycled entries so search doesn't surface entries that
;; `remove page` / `remove block` already soft-deleted. Tag and

View File

@@ -121,7 +121,7 @@
[config repo root]
(if (and (ordinary-block-root? root)
(:db/id root))
(-> (transport/invoke config :thread-api/get-block-parents false [repo (:db/id root)])
(-> (transport/invoke config :thread-api/get-block-parents [repo (:db/id root)])
(p/then (fn [parents]
(or parents []))))
(p/resolved [])))
@@ -442,11 +442,11 @@
(defn- fetch-linked-references
[config repo root-id]
(p/let [refs (transport/invoke config :thread-api/get-block-refs false [repo root-id])
(p/let [refs (transport/invoke config :thread-api/get-block-refs [repo root-id])
ref-ids (vec (keep :db/id refs))
pulled (if (seq ref-ids)
(p/all (map (fn [id]
(transport/invoke config :thread-api/pull false [repo linked-ref-selector id]))
(transport/invoke config :thread-api/pull [repo linked-ref-selector id]))
ref-ids))
[])]
(let [blocks (vec (remove (fn [block]
@@ -476,7 +476,7 @@
(p/let [blocks (attach-user-properties config repo blocks)
pages (if (seq page-ids)
(p/all (map (fn [id]
(transport/invoke config :thread-api/pull false
(transport/invoke config :thread-api/pull
[repo [:db/id :block/name :block/title :block/uuid] id]))
page-ids))
[])]
@@ -636,7 +636,7 @@
selector [:db/id :db/ident :block/title :block/name
:logseq.property/hide? :logseq.property/public?]]
(p/let [entities (p/all (map (fn [property-key]
(transport/invoke config :thread-api/pull false
(transport/invoke config :thread-api/pull
[repo selector [:db/ident property-key]]))
keys))]
(->> (map vector keys entities)
@@ -655,13 +655,13 @@
uuids* (vec uuids)]
(p/let [id-entities (if (seq ids*)
(p/all (map (fn [id]
(transport/invoke config :thread-api/pull false
(transport/invoke config :thread-api/pull
[repo selector id]))
ids*))
[])
uuid-entities (if (seq uuids*)
(p/all (map (fn [uuid]
(transport/invoke config :thread-api/pull false
(transport/invoke config :thread-api/pull
[repo selector [:block/uuid uuid]]))
uuids*))
[])]
@@ -706,14 +706,14 @@
[?b ?a ?v]]
ids (vec block-ids)
built-in-idents (vec displayable-built-in-properties)]
(p/let [user-pairs (transport/invoke config :thread-api/q false [repo [idents-query]])
built-in-pairs (transport/invoke config :thread-api/q false
(p/let [user-pairs (transport/invoke config :thread-api/q [repo [idents-query]])
built-in-pairs (transport/invoke config :thread-api/q
[repo [built-in-query built-in-idents]])
ident-type-pairs (into (vec user-pairs) built-in-pairs)
datetime-idents (set (keep (fn [[a type]] (when (= :datetime type) a)) ident-type-pairs))
property-idents (vec (map first ident-type-pairs))]
(if (seq property-idents)
(p/let [rows (transport/invoke config :thread-api/q false
(p/let [rows (transport/invoke config :thread-api/q
[repo [props-query ids property-idents]])]
(reduce (fn [acc [block-id attr value]]
(let [value (if (and (number? value) (contains? datetime-idents attr))
@@ -759,7 +759,7 @@
(let [query [:find (list 'pull '?b tree-block-selector)
:in '$ '?page-id
:where ['?b :block/page '?page-id]]]
(p/let [rows (transport/invoke config :thread-api/q false [repo [query page-id]])
(p/let [rows (transport/invoke config :thread-api/q [repo [query page-id]])
blocks (->> rows
(map first)
(remove property-value-block?)
@@ -799,7 +799,7 @@
uuid-str (:uuid opts)]
(cond
(some? id)
(p/let [entity (transport/invoke config :thread-api/pull false
(p/let [entity (transport/invoke config :thread-api/pull
[repo show-root-selector id])]
(p/let [entity (attach-user-properties-to-entity config repo entity)]
(if (missing-show-entity? entity)
@@ -815,12 +815,12 @@
(throw (ex-info "entity not found" {:code :entity-not-found})))))))
(seq uuid-str)
(p/let [entity (transport/invoke config :thread-api/pull false
(p/let [entity (transport/invoke config :thread-api/pull
[repo show-root-selector
[:block/uuid (uuid uuid-str)]])
entity (if (:db/id entity)
entity
(transport/invoke config :thread-api/pull false
(transport/invoke config :thread-api/pull
[repo show-root-selector
[:block/uuid uuid-str]]))]
(p/let [entity (attach-user-properties-to-entity config repo entity)]
@@ -837,7 +837,7 @@
(throw (ex-info "entity not found" {:code :entity-not-found})))))))
(seq page)
(p/let [page-entity (transport/invoke config :thread-api/pull false
(p/let [page-entity (transport/invoke config :thread-api/pull
[repo [:db/id :db/ident :block/uuid :block/title
:logseq.property/deleted-at
{:logseq.property/status [:db/ident :block/title]}

View File

@@ -224,8 +224,8 @@
(p/resolved nil)
(-> (p/let [refresh-token (ensure-refresh-token! config)
_ (if (seq e2ee-password)
(transport/invoke cfg :thread-api/verify-and-save-e2ee-password false [refresh-token e2ee-password])
(transport/invoke cfg :thread-api/get-e2ee-password false [refresh-token]))]
(transport/invoke cfg :thread-api/verify-and-save-e2ee-password [refresh-token e2ee-password])
(transport/invoke cfg :thread-api/get-e2ee-password [refresh-token]))]
nil)
(p/catch (fn [error]
(if (missing-e2ee-password-diagnostic? error)
@@ -467,15 +467,15 @@
[cfg config]
(let [auth-state (worker-auth-state config)]
(p/let [_ (when (seq auth-state)
(transport/invoke cfg :thread-api/sync-app-state false [auth-state]))
_ (transport/invoke cfg :thread-api/set-db-sync-config false [(sync-config config)])]
(transport/invoke cfg :thread-api/sync-app-state [auth-state]))
_ (transport/invoke cfg :thread-api/set-db-sync-config [(sync-config config)])]
nil)))
(defn- invoke-with-repo
[config repo method args]
(p/let [cfg (cli-server/ensure-server! config repo)
_ (<sync-worker-runtime! cfg config)
result (transport/invoke cfg method false args)]
result (transport/invoke cfg method args)]
result))
(defn- invoke-global
@@ -483,7 +483,7 @@
(let [base-url (:base-url config)]
(if (seq base-url)
(p/let [_ (<sync-worker-runtime! config config)]
(transport/invoke config method false args))
(transport/invoke config method args))
(p/let [repo (or (core/resolve-repo (:graph config))
(p/let [graphs (cli-server/list-graphs config)]
(some-> graphs first core/resolve-repo)))
@@ -492,7 +492,7 @@
(p/rejected (ex-info "graph name is required"
{:code :missing-graph})))
_ (<sync-worker-runtime! cfg config)]
(transport/invoke cfg method false args)))))
(transport/invoke cfg method args)))))
(defn- download-config
[config]
@@ -500,7 +500,7 @@
(defn- ensure-empty-download-db!
[cfg repo]
(p/let [non-empty-entity-count (transport/invoke cfg :thread-api/q false [repo [sync-download-non-empty-query]])]
(p/let [non-empty-entity-count (transport/invoke cfg :thread-api/q [repo [sync-download-non-empty-query]])]
(when (and (number? non-empty-entity-count)
(pos? non-empty-entity-count))
(throw (ex-info "graph db is not empty"
@@ -573,7 +573,7 @@
[cfg config {:keys [e2ee-password]}]
(if (seq e2ee-password)
(p/let [refresh-token (ensure-refresh-token! config)
_ (transport/invoke cfg :thread-api/verify-and-save-e2ee-password false [refresh-token e2ee-password])]
_ (transport/invoke cfg :thread-api/verify-and-save-e2ee-password [refresh-token e2ee-password])]
nil)
(p/resolved nil)))
@@ -582,7 +582,7 @@
(-> (p/let [cfg (cli-server/ensure-server! config (:repo action))
_ (<sync-worker-runtime! cfg config)
_ (<verify-and-save-e2ee-password-on-worker-if-provided! cfg config action)
result (transport/invoke cfg :thread-api/db-sync-upload-graph false [(:repo action)])]
result (transport/invoke cfg :thread-api/db-sync-upload-graph [(:repo action)])]
{:status :ok
:data (if (map? result)
result
@@ -670,7 +670,7 @@
(fn [event-type payload]
(when-let [message (download-progress-message graph-id event-type payload)]
(print-progress-line! message)))))
result (-> (transport/invoke download-cfg :thread-api/db-sync-download-graph-by-id false
result (-> (transport/invoke download-cfg :thread-api/db-sync-download-graph-by-id
[(:repo action) graph-id (:graph-e2ee? remote-graph)])
(p/finally (fn []
(when-let [close! (:close! events-sub)]
@@ -698,7 +698,7 @@
(-> (p/let [config' (resolve-runtime-config! action config)
cfg (cli-server/ensure-server! config' (:repo action))
_ (<sync-worker-runtime! cfg config')
result (transport/invoke cfg :thread-api/db-sync-status false [(:repo action)])]
result (transport/invoke cfg :thread-api/db-sync-status [(:repo action)])]
{:status :ok
:data result})
(p/catch (fn [error]
@@ -713,9 +713,9 @@
(missing-sync-config-error (:type action) missing-keys)
(p/let [cfg (cli-server/ensure-server! start-config (:repo action))
_ (<sync-worker-runtime! cfg start-config)
graph-e2ee? (transport/invoke cfg :thread-api/q false [(:repo action) [graph-e2ee-query]])
graph-e2ee? (transport/invoke cfg :thread-api/q [(:repo action) [graph-e2ee-query]])
_ (<ensure-e2ee-password-available! cfg start-config action (true? graph-e2ee?))
_ (transport/invoke cfg :thread-api/db-sync-start false [(:repo action)])
_ (transport/invoke cfg :thread-api/db-sync-start [(:repo action)])
result (wait-sync-start-ready start-config (:repo action) action)]
result)))
(p/catch (fn [error]

View File

@@ -60,11 +60,11 @@
(defn- fetch-entity-by-uuid
[config repo uuid-str]
(p/let [entity (transport/invoke config :thread-api/pull false
(p/let [entity (transport/invoke config :thread-api/pull
[repo block-selector [:block/uuid (uuid uuid-str)]])]
(if (:db/id entity)
entity
(transport/invoke config :thread-api/pull false
(transport/invoke config :thread-api/pull
[repo block-selector [:block/uuid uuid-str]]))))
(defn- ensure-non-page
@@ -77,7 +77,7 @@
[config repo {:keys [id uuid]}]
(cond
(some? id)
(p/let [entity (transport/invoke config :thread-api/pull false
(p/let [entity (transport/invoke config :thread-api/pull
[repo block-selector id])]
(if (:db/id entity)
(ensure-non-page entity "source must be a non-page block" :invalid-source)
@@ -96,7 +96,7 @@
[config repo {:keys [target-id target-uuid target-page]}]
(cond
(some? target-id)
(p/let [entity (transport/invoke config :thread-api/pull false
(p/let [entity (transport/invoke config :thread-api/pull
[repo block-selector target-id])]
(if (:db/id entity)
(ensure-non-page entity "target must be a block" :invalid-target)
@@ -110,7 +110,7 @@
(seq target-page)
(let [page-name (common-util/page-name-sanity-lc target-page)]
(p/let [entity (transport/invoke config :thread-api/pull false
(p/let [entity (transport/invoke config :thread-api/pull
[repo [:db/id :block/uuid :block/name :block/title]
[:block/name page-name]])]
(if (:db/id entity)
@@ -285,7 +285,7 @@
[:batch-set-property [block-uuids k v {}]])
update-properties)))
result (if (seq ops)
(transport/invoke cfg :thread-api/apply-outliner-ops false
(transport/invoke cfg :thread-api/apply-outliner-ops
[(:repo action) ops {}])
(p/resolved nil))]
{:status :ok

View File

@@ -687,7 +687,7 @@
(defn- pull-page-by-name
[config repo page-name selector]
(transport/invoke config :thread-api/pull false
(transport/invoke config :thread-api/pull
[repo selector [:block/name (common-util/page-name-sanity-lc page-name)]]))
(def ^:private pull-tag-by-name add-command/pull-tag-by-name)
@@ -731,7 +731,7 @@
(if (seq property-idents)
(p/all
(map (fn [property-ident]
(p/let [entity (transport/invoke config :thread-api/pull false
(p/let [entity (transport/invoke config :thread-api/pull
[repo [:db/id] [:db/ident property-ident]])]
(when-not (:db/id entity)
(throw (ex-info "property not found"
@@ -753,12 +753,12 @@
;; :create-page in both cases is correct: outliner-page/create has a
;; (ldb/recycled? existing-page) branch that restores the recycled page
;; instead of creating a duplicate.
(p/let [result (transport/invoke config :thread-api/apply-outliner-ops false
(p/let [result (transport/invoke config :thread-api/apply-outliner-ops
[repo [[:create-page [page-name {}]]] {}])
;; create-page returns [title' page-uuid]; use uuid to find
;; the page since the stored name may differ from the input
created (if-let [page-uuid (second result)]
(transport/invoke config :thread-api/pull false
(transport/invoke config :thread-api/pull
[repo [:db/id :block/uuid] [:block/uuid page-uuid]])
(pull-page-by-name config repo page-name [:db/id :block/uuid]))]
(if (:db/id created)
@@ -798,7 +798,7 @@
(defn- pull-entity-by-id
[config repo selector id]
(transport/invoke config :thread-api/pull false
(transport/invoke config :thread-api/pull
[repo selector id]))
(defn- throw-upsert-id-not-found!
@@ -907,7 +907,7 @@
(defn- pull-entity-by-uuid
[config repo selector uuid-value]
(when-let [uuid* (normalize-lookup-uuid uuid-value)]
(transport/invoke config :thread-api/pull false
(transport/invoke config :thread-api/pull
[repo selector [:block/uuid uuid*]])))
(defn- ensure-task-node!
@@ -962,7 +962,7 @@
(defn- ensure-task-tag-id!
[config repo]
(p/let [entity (transport/invoke config :thread-api/pull false
(p/let [entity (transport/invoke config :thread-api/pull
[repo [:db/id] [:db/ident task-tag-ident]])]
(if-let [tag-id (:db/id entity)]
tag-id
@@ -1012,7 +1012,7 @@
block-uuids
task-op-plan)]
(if (seq ops)
(transport/invoke cfg :thread-api/apply-outliner-ops false
(transport/invoke cfg :thread-api/apply-outliner-ops
[repo ops {}])
(p/resolved nil)))
(p/resolved nil)))
@@ -1128,7 +1128,7 @@
:update-properties update-properties
:remove-properties remove-properties})
_ (when (seq ops)
(transport/invoke cfg :thread-api/apply-outliner-ops false
(transport/invoke cfg :thread-api/apply-outliner-ops
[(:repo action) ops {}]))]
{:status :ok
:data {:result [page-id]}})
@@ -1148,7 +1148,7 @@
(let [status-input (or (normalize-status-input (:status-input action))
(normalize-status-input (:status action)))]
(if (seq status-input)
(p/let [available-statuses (transport/invoke cfg :thread-api/q false
(p/let [available-statuses (transport/invoke cfg :thread-api/q
[(:repo action)
[task-status-command/status-closed-values-query]])
resolved-status (task-status-command/resolve-status-ident status-input available-statuses)]
@@ -1283,7 +1283,7 @@
(defn- ensure-asset-tag-id!
[config repo]
(p/let [entity (transport/invoke config :thread-api/pull false
(p/let [entity (transport/invoke config :thread-api/pull
[repo [:db/id] [:db/ident asset-tag-ident]])]
(if-let [tag-id (:db/id entity)]
tag-id
@@ -1374,7 +1374,7 @@
_ (when (and (seq target-name)
(not conflict)
(not (rename-target-same-as-current? entity target-name)))
(transport/invoke cfg :thread-api/apply-outliner-ops false
(transport/invoke cfg :thread-api/apply-outliner-ops
[(:repo action)
[[:rename-page [(:block/uuid entity) target-name]]]
{}]))]
@@ -1388,7 +1388,7 @@
{:block/tags [:db/ident]}])
existing-id (:db/id existing)]
(p/let [_ (when-not existing-id
(transport/invoke cfg :thread-api/apply-outliner-ops false
(transport/invoke cfg :thread-api/apply-outliner-ops
[(:repo action)
[[:create-page [(:name action) {:class? true}]]]
{}]))
@@ -1426,7 +1426,7 @@
(p/let [existing (ensure-property-by-id! cfg (:repo action) (:id action))
property-ident (:db/ident existing)
_ (when (seq (:schema action))
(transport/invoke cfg :thread-api/apply-outliner-ops false
(transport/invoke cfg :thread-api/apply-outliner-ops
[(:repo action)
[[:upsert-property [property-ident
(:schema action)
@@ -1440,7 +1440,7 @@
property-opts (cond-> {}
(nil? property-ident)
(assoc :property-name (:name action)))
_ (transport/invoke cfg :thread-api/apply-outliner-ops false
_ (transport/invoke cfg :thread-api/apply-outliner-ops
[(:repo action)
[[:upsert-property [property-ident
(:schema action)

View File

@@ -115,7 +115,7 @@
(defn invoke
[{:keys [base-url timeout-ms profile-session]}
method direct-pass? args]
method args]
(let [base-url (normalize-base-url base-url)
method* (cond
(keyword? method) (subs (str method) 1)
@@ -128,43 +128,28 @@
stage-key (str "transport.invoke:" method*)
start-ms (js/Date.now)
args-preview (cli-log/truncate-preview args)
payload (if direct-pass?
{:method method*
:directPass true
:args args}
{:method method*
:directPass false
:argsTransit (ldb/write-transit-str args)})
payload {:method method*
:argsTransit (ldb/write-transit-str args)}
body (js/JSON.stringify (clj->js payload))]
(profile/time! profile-session stage-key
(fn []
(log/debug :event :cli.transport/invoke
:method method*
:direct-pass? direct-pass?
:args args-preview
:url url)
(p/let [{:keys [body]} (request {:method "POST"
:url url
:headers (base-headers)
:body body
:timeout-ms timeout-ms})
{:keys [result resultTransit]} (js->clj (js/JSON.parse body) :keywordize-keys true)]
(if direct-pass?
(let [response-preview (cli-log/truncate-preview result)]
(log/debug :event :cli.transport/response
:method method*
:direct-pass? direct-pass?
:elapsed-ms (- (js/Date.now) start-ms)
:response response-preview)
result)
(let [decoded (ldb/read-transit-str resultTransit)
(fn []
(log/debug :event :cli.transport/invoke
:method method*
:args args-preview
:url url)
(p/let [{:keys [body]} (request {:method "POST"
:url url
:headers (base-headers)
:body body
:timeout-ms timeout-ms})
{:keys [resultTransit]} (js->clj (js/JSON.parse body) :keywordize-keys true)
decoded (ldb/read-transit-str resultTransit)
response-preview (cli-log/truncate-preview decoded)]
(log/debug :event :cli.transport/response
:method method*
:direct-pass? direct-pass?
:elapsed-ms (- (js/Date.now) start-ms)
:response response-preview)
decoded))))))))
(log/debug :event :cli.transport/response
:method method*
:elapsed-ms (- (js/Date.now) start-ms)
:response response-preview)
decoded))))))
(defn- decode-event
[{:keys [type payload]}]

View File

@@ -80,7 +80,7 @@
vec)]
(if (seq uuid-strings)
(p/let [blocks (p/all (map (fn [uuid-str]
(transport/invoke config :thread-api/pull false
(transport/invoke config :thread-api/pull
[repo uuid-lookup-selector
[:block/uuid (uuid uuid-str)]]))
uuid-strings))]

View File

@@ -1,5 +1,6 @@
(ns frontend.persist-db.remote-test
(:require [cljs.test :refer [async deftest is]]
[frontend.persist-db.protocol :as protocol]
[frontend.persist-db.remote :as remote]
[logseq.db :as ldb]
[promesa.core :as p]))
@@ -16,10 +17,13 @@
:body (js/JSON.stringify
#js {:ok true
:resultTransit (ldb/write-transit-str [{:repo "graph-a"}])})}))})]
(-> (p/let [result (remote/invoke! client "thread-api/list-db" false [])
headers (:headers @captured)]
(-> (p/let [result (remote/invoke! client "thread-api/list-db" [])
headers (:headers @captured)
body (js->clj (js/JSON.parse (:body @captured)) :keywordize-keys true)]
(is (= [{:repo "graph-a"}] result))
(is (= "Bearer token-1" (get headers "Authorization"))))
(is (= "Bearer token-1" (get headers "Authorization")))
(is (= "thread-api/list-db" (:method body)))
(is (string? (:argsTransit body))))
(p/catch (fn [e]
(is false (str "unexpected error: " e))))
(p/finally (fn [] (done)))))))
@@ -34,7 +38,7 @@
#js {:ok false
:error #js {:code "repo-locked"
:message "graph already locked"}})}))})]
(-> (remote/invoke! client "thread-api/transact" false ["graph-a" [] {}])
(-> (remote/invoke! client "thread-api/transact" ["graph-a" [] {}])
(p/then (fn [_]
(is false "expected invoke! to reject on non-2xx status")))
(p/catch (fn [e]
@@ -93,8 +97,42 @@
:body (js/JSON.stringify
#js {:ok true
:resultTransit (ldb/write-transit-str [])})}))})]
(-> (p/let [_ (remote/invoke! client "thread-api/list-db" false [])]
(is (nil? (get (:headers @captured) "Authorization"))))
(-> (p/let [_ (remote/invoke! client "thread-api/list-db" [])
body (js->clj (js/JSON.parse (:body @captured)) :keywordize-keys true)]
(is (nil? (get (:headers @captured) "Authorization")))
(is (string? (:argsTransit body))))
(p/catch (fn [e]
(is false (str "unexpected error: " e))))
(p/finally (fn [] (done)))))))
(deftest remote-export-db-uses-base64-thread-api
(async done
(let [calls (atom [])
client {:base-url "http://127.0.0.1:9101"}
db (remote/->InRemote client nil nil)]
(-> (p/with-redefs [remote/invoke! (fn [client' method args]
(swap! calls conj [client' method args])
(p/resolved "c3FsaXRlLWJ5dGVz"))]
(p/let [result (protocol/<export-db db "graph-a" {:return-data? true})]
(is (= [client "thread-api/export-db-base64" ["graph-a"]]
(first @calls)))
(is (= "sqlite-bytes" (.toString (js/Buffer.from result) "utf8")))))
(p/catch (fn [e]
(is false (str "unexpected error: " e))))
(p/finally (fn [] (done)))))))
(deftest remote-import-db-uses-base64-thread-api
(async done
(let [calls (atom [])
client {:base-url "http://127.0.0.1:9101"}
db (remote/->InRemote client nil nil)
payload (.from js/Buffer "sqlite-bytes")]
(-> (p/with-redefs [remote/invoke! (fn [client' method args]
(swap! calls conj [client' method args])
(p/resolved nil))]
(p/let [_ (protocol/<import-db db "graph-a" payload)]
(is (= [client "thread-api/import-db-base64" ["graph-a" "c3FsaXRlLWJ5dGVz"]]
(first @calls)))))
(p/catch (fn [e]
(is false (str "unexpected error: " e))))
(p/finally (fn [] (done)))))))

View File

@@ -203,15 +203,14 @@
(set! config/db-sync-http-base (fn [] "https://sync.example.test"))
(set! remote/start! (fn [{:keys [repo]}]
(->FakeRemote repo
(fn [qkw direct-pass? & args]
(swap! worker-calls conj [qkw direct-pass? args])
(fn [qkw & args]
(swap! worker-calls conj [qkw args])
(p/resolved nil)))))
(set! remote/stop! (fn [_] (p/resolved true)))
(-> (p/let [_ (ensure-remote! "logseq_db_graph_a")]
(let [set-config-call (first (filter #(= :thread-api/set-db-sync-config (first %))
@worker-calls))]
(is (= [:thread-api/set-db-sync-config
false
[{:enabled? true
:ws-url "wss://sync.example.test/sync/%s"
:http-base "https://sync.example.test"}]]
@@ -274,14 +273,14 @@
(reset! persist-db/remote-db fake-client)
(reset! persist-db/remote-repo "logseq_db_graph_a")
(set! util/electron? (constantly true))
(set! remote/invoke! (fn [client method direct-pass? args]
(swap! invoke-calls conj [client method direct-pass? args])
(set! remote/invoke! (fn [client method args]
(swap! invoke-calls conj [client method args])
(p/resolved nil)))
(set! remote/stop! (fn [client]
(swap! stop-calls conj client)
(p/resolved true)))
(-> (p/let [_ (persist-db/<close-db "logseq_db_graph_a")]
(is (= [[(:client fake-client) "thread-api/close-db" false ["logseq_db_graph_a"]]]
(is (= [[(:client fake-client) "thread-api/close-db" ["logseq_db_graph_a"]]]
@invoke-calls))
(is (= [fake-client] @stop-calls))
(is (nil? @persist-db/remote-db))
@@ -307,8 +306,8 @@
(reset! persist-db/remote-db fake-client)
(reset! persist-db/remote-repo "logseq_db_graph_a")
(set! util/electron? (constantly true))
(set! remote/invoke! (fn [client method direct-pass? args]
(swap! invoke-calls conj [client method direct-pass? args])
(set! remote/invoke! (fn [client method args]
(swap! invoke-calls conj [client method args])
(p/resolved nil)))
(set! remote/stop! (fn [client]
(swap! stop-calls conj client)
@@ -345,28 +344,28 @@
(set! state/<invoke-db-worker original-invoke)
(done)))))))
(deftest browser-export-db-on-electron-triggers-worker-export-then-local-backup
(deftest browser-export-db-on-electron-triggers-worker-base64-export-then-local-backup
(async done
(let [ipc-calls (atom [])
worker-export-calls (atom [])
original-electron? util/electron?
original-ipc ipc/ipc
original-invoke state/<invoke-db-worker-direct-pass]
original-invoke state/<invoke-db-worker]
(set! util/electron? (constantly true))
(set! ipc/ipc (fn [& args]
(swap! ipc-calls conj args)
(p/resolved :ok)))
(set! state/<invoke-db-worker-direct-pass
(set! state/<invoke-db-worker
(fn [qkw & _]
(swap! worker-export-calls conj qkw)
(case qkw
:thread-api/export-db (p/resolved (.from js/Buffer "sqlite-bytes"))
:thread-api/export-db-base64 (p/resolved "c3FsaXRlLWJ5dGVz")
(p/rejected (ex-info "unexpected worker call" {:qkw qkw})))))
(-> (protocol/<export-db (browser/->InBrowser) "logseq_db_graph_a" {})
(p/then (fn [_]
(is (= [[:db-export "logseq_db_graph_a" false]]
@ipc-calls))
(is (= [:thread-api/export-db]
(is (= [:thread-api/export-db-base64]
@worker-export-calls))))
(p/catch (fn [e]
(is false (str "unexpected error: " e))))
@@ -374,5 +373,27 @@
(fn []
(set! util/electron? original-electron?)
(set! ipc/ipc original-ipc)
(set! state/<invoke-db-worker-direct-pass original-invoke)
(set! state/<invoke-db-worker original-invoke)
(done)))))))
(deftest browser-import-db-uses-base64-thread-api
(async done
(let [worker-import-calls (atom [])
original-invoke state/<invoke-db-worker
payload (.from js/Buffer "sqlite-bytes")]
(set! state/<invoke-db-worker
(fn [qkw & args]
(swap! worker-import-calls conj [qkw args])
(case qkw
:thread-api/import-db-base64 (p/resolved nil)
(p/rejected (ex-info "unexpected worker call" {:qkw qkw})))) )
(-> (protocol/<import-db (browser/->InBrowser) "logseq_db_graph_a" payload)
(p/then (fn [_]
(is (= [[:thread-api/import-db-base64 ["logseq_db_graph_a" "c3FsaXRlLWJ5dGVz"]]]
@worker-import-calls))))
(p/catch (fn [e]
(is false (str "unexpected error: " e))))
(p/finally
(fn []
(set! state/<invoke-db-worker original-invoke)
(done)))))))

View File

@@ -122,26 +122,28 @@
(is (= "" (resolve-initial-config "")))
(is (= "{:foo true}" (resolve-initial-config "{:foo true}")))))
(deftest import-db-rejects-non-sqlite-payload
(deftest import-db-base64-rejects-non-sqlite-payload
(async done
(restoring-worker-state
(fn []
(let [import-db! (get @thread-api/*thread-apis :thread-api/import-db)
imports (atom [])
invalid-payload (.encode (js/TextEncoder.) "[\"~#js/Error\",[\"^ \",\"~:message\",\"File not found: /db.sqlite\"]]")]
(platform/set-platform!
(build-test-platform
{:import-db (fn [_pool _path data]
(swap! imports conj data)
(p/resolved nil))}))
(-> (import-db! test-repo invalid-payload)
(p/then (fn [_]
(is false "expected import-db to reject invalid payload")))
(p/catch (fn [error]
(is (= :invalid-sqlite-import-data (:code (ex-data error))))))
(p/finally (fn []
(is (empty? @imports))
(done)))))))))
(->
(restoring-worker-state
(fn []
(let [import-db! (get @thread-api/*thread-apis :thread-api/import-db-base64)
imports (atom [])
invalid-payload (.encode (js/TextEncoder.) "[\"~#js/Error\",[\"^ \",\"~:message\",\"File not found: /db.sqlite\"]]")
invalid-base64 (.toString (js/Buffer.from invalid-payload) "base64")]
(platform/set-platform!
(build-test-platform
{:import-db (fn [_pool _path data]
(swap! imports conj data)
(p/resolved nil))}))
(-> (import-db! test-repo invalid-base64)
(p/then (fn [_]
(is false "expected import-db-base64 to reject invalid payload")))
(p/catch (fn [error]
(is (= :invalid-sqlite-import-data (:code (ex-data error))))))
(p/finally (fn []
(is (empty? @imports))))))))
(p/finally done))))
(deftest set-db-sync-config-keeps-only-non-auth-fields-test
(let [set-config! (get @thread-api/*thread-apis :thread-api/set-db-sync-config)
@@ -218,50 +220,54 @@
(deftest search-build-blocks-indice-in-worker-reports-progress-to-main-thread-test
(async done
(restoring-worker-state
(fn []
(let [build-index! (get @thread-api/*thread-apis :thread-api/search-build-blocks-indice-in-worker)
conn (d/create-conn db-schema/schema)
search-db (fake-db)
progress-calls (atom [])
idle-status-atom (:thread-atom/search-input-idle-status @worker-state/*state)]
(d/transact! conn [{:block/uuid (random-uuid)}])
(reset! worker-state/*sqlite-conns {test-repo {:search search-db}})
(reset! worker-state/*datascript-conns {test-repo conn})
(reset! idle-status-atom {test-repo {:idle? true
:ts (.now js/Date)}})
(reset! worker-state/*main-thread
(fn [qkw direct-pass? & args]
(when (= qkw :thread-api/search-index-build-progress)
(let [[repo payload] args]
(swap! progress-calls conj {:qkw qkw
:direct-pass? direct-pass?
:repo repo
:payload payload})))
(p/resolved nil)))
(with-redefs [search/truncate-table! (fn [_db] nil)
search/upsert-blocks! (fn [_db _blocks] nil)
search/hidden-entity? (constantly false)
search/block->index (fn [_entity]
{:id "block-1"
:page "page-1"
:title "Hello"})]
(-> (build-index! test-repo true)
(p/then (fn [_]
(let [statuses (map (comp :status :payload) @progress-calls)
completed (some #(when (= :completed (get-in % [:payload :status]))
%)
@progress-calls)]
(is (= false (:direct-pass? (first @progress-calls))))
(is (= test-repo (:repo (first @progress-calls))))
(is (= :running (first statuses)))
(is (some #{:completed} statuses))
(is (= :idle (last statuses)))
(is (= 1 (get-in completed [:payload :processed])))
(is (= 1 (get-in completed [:payload :total]))))))
(p/catch (fn [error]
(is false (str error))))
(p/finally done))))))))
(->
(restoring-worker-state
(fn []
(let [build-index! (get @thread-api/*thread-apis :thread-api/search-build-blocks-indice-in-worker)
conn (d/create-conn db-schema/schema)
search-db (fake-db)
progress-calls (atom [])
idle-status-atom (:thread-atom/search-input-idle-status @worker-state/*state)]
(d/transact! conn [{:block/uuid (random-uuid)}])
(reset! worker-state/*sqlite-conns {test-repo {:search search-db}})
(reset! worker-state/*datascript-conns {test-repo conn})
(reset! idle-status-atom {test-repo {:idle? true
:ts (.now js/Date)}})
(reset! worker-state/*main-thread
(fn [qkw & args]
(when (= qkw :thread-api/search-index-build-progress)
(let [[repo payload] args]
(swap! progress-calls conj {:qkw qkw
:repo repo
:payload payload})))
(p/resolved nil)))
(with-redefs [search/truncate-table! (fn [_db] nil)
search/upsert-blocks! (fn [_db _blocks] nil)
search/hidden-entity? (constantly false)
search/block->index (fn [_entity]
{:id "block-1"
:page "page-1"
:title "Hello"})]
(-> (p/let [_ (build-index! test-repo true)
_ (p/loop [remaining 20]
(if (or (seq @progress-calls)
(zero? remaining))
nil
(p/let [_ (p/delay 5)]
(p/recur (dec remaining)))))]
(let [statuses (map (comp :status :payload) @progress-calls)
completed (some #(when (= :completed (get-in % [:payload :status]))
%)
@progress-calls)]
(is (= test-repo (:repo (first @progress-calls))))
(is (= :running (first statuses)))
(is (some #{:completed} statuses))
(is (= :idle (last statuses)))
(is (= 1 (get-in completed [:payload :processed])))
(is (= 1 (get-in completed [:payload :total])))))
(p/catch (fn [error]
(is false (str error)))))))))
(p/finally done))))
(deftest release-access-handles-clears-active-import-state-test
(restoring-worker-state

View File

@@ -425,7 +425,7 @@
:auth/oauth-token-url "https://auth.example.com/oauth2/token"
:auth/oauth-client-id "worker-client-id"))
(reset! worker-state/*main-thread
(fn [qkw _direct-pass? _args-list]
(fn [qkw & _args]
(when (= qkw :thread-api/ensure-id&access-token)
(swap! main-thread-calls inc))
(p/resolved {:id-token "legacy-token"})))
@@ -473,7 +473,7 @@
:auth/oauth-token-url "https://auth.example.com/oauth2/token"
:auth/oauth-client-id "worker-client-id"))
(reset! worker-state/*main-thread
(fn [qkw _direct-pass? _args-list]
(fn [qkw & _args]
(when (= qkw :thread-api/ensure-id&access-token)
(swap! main-thread-calls inc))
(p/resolved {:id-token "fresh-legacy-token"})))

View File

@@ -58,7 +58,6 @@
[host port method args]
(let [payload (js/JSON.stringify
(clj->js {:method method
:directPass false
:argsTransit (ldb/write-transit-str args)}))]
(p/let [{:keys [status body]}
(http-request {:hostname host
@@ -81,7 +80,6 @@
[host port method args]
(let [payload (js/JSON.stringify
(clj->js {:method method
:directPass false
:argsTransit (ldb/write-transit-str args)}))]
(http-request {:hostname host
:port port
@@ -522,14 +520,11 @@
invoke-calls (atom [])]
(-> (p/with-redefs [platform-node/node-platform (fn [_opts] #js {})
db-core/init-core! (fn [_platform]
#js {:remoteInvoke (fn [method direct-pass? args]
#js {:remoteInvoke (fn [method args-transit]
(swap! invoke-calls conj
[method
direct-pass?
(if direct-pass?
(vec (js->clj args))
(ldb/read-transit-str args))])
(p/resolved nil))})
(ldb/read-transit-str args-transit)])
(p/resolved (ldb/write-transit-str nil)))})
db-lock/ensure-lock! (fn [_]
(p/resolved {:path lock-file-path
:lock {:repo repo
@@ -542,10 +537,10 @@
:repo repo
:create-empty-db? true
:log-level "error"})
_ (is (= ["thread-api/init" true []]
_ (is (= ["thread-api/init" []]
(first @invoke-calls)))
_ (is (= ["thread-api/create-or-open-db" false [repo {:datoms []
:sync-download-graph? true}]]
_ (is (= ["thread-api/create-or-open-db" [repo {:datoms []
:sync-download-graph? true}]]
(second @invoke-calls)))
_ (stop!)]
true))
@@ -561,14 +556,11 @@
invoke-calls (atom [])]
(-> (p/with-redefs [platform-node/node-platform (fn [_opts] #js {})
db-core/init-core! (fn [_platform]
#js {:remoteInvoke (fn [method direct-pass? args]
#js {:remoteInvoke (fn [method args-transit]
(swap! invoke-calls conj
[method
direct-pass?
(if direct-pass?
(vec (js->clj args))
(ldb/read-transit-str args))])
(p/resolved nil))})
(ldb/read-transit-str args-transit)])
(p/resolved (ldb/write-transit-str nil)))})
db-lock/ensure-lock! (fn [_]
(p/resolved {:path lock-file-path
:lock {:repo repo
@@ -580,9 +572,9 @@
(p/let [{:keys [stop!]} (db-worker-node/start-daemon! {:root-dir data-dir
:repo repo
:log-level "error"})
_ (is (= ["thread-api/init" true []]
_ (is (= ["thread-api/init" []]
(first @invoke-calls)))
_ (is (= ["thread-api/create-or-open-db" false [repo {}]]
_ (is (= ["thread-api/create-or-open-db" [repo {}]]
(second @invoke-calls)))
_ (stop!)]
true))
@@ -598,14 +590,11 @@
invoke-calls (atom [])]
(-> (p/with-redefs [platform-node/node-platform (fn [_opts] #js {})
db-core/init-core! (fn [_platform]
#js {:remoteInvoke (fn [method direct-pass? args]
#js {:remoteInvoke (fn [method args-transit]
(swap! invoke-calls conj
[method
direct-pass?
(if direct-pass?
(vec (js->clj args))
(ldb/read-transit-str args))])
(p/resolved nil))})
(ldb/read-transit-str args-transit)])
(p/resolved (ldb/write-transit-str nil)))})
db-lock/ensure-lock! (fn [_]
(p/resolved {:path lock-file-path
:lock {:repo repo
@@ -618,11 +607,11 @@
:repo repo
:log-level "error"})
_ (stop!)]
(is (= ["thread-api/init" true []]
(is (= ["thread-api/init" []]
(first @invoke-calls)))
(is (= ["thread-api/create-or-open-db" false [repo {}]]
(is (= ["thread-api/create-or-open-db" [repo {}]]
(second @invoke-calls)))
(is (= ["thread-api/close-db" false [repo]]
(is (= ["thread-api/close-db" [repo]]
(nth @invoke-calls 2)))))
(p/catch (fn [e]
(is false (str "unexpected error: " e))))
@@ -636,8 +625,8 @@
server-list-file (cli-config/server-list-path data-dir)]
(-> (p/with-redefs [platform-node/node-platform (fn [_opts] #js {})
db-core/init-core! (fn [_platform]
#js {:remoteInvoke (fn [_method _direct-pass? _args]
(p/resolved nil))})
#js {:remoteInvoke (fn [_method _args-transit]
(p/resolved (ldb/write-transit-str nil)))})
db-lock/ensure-lock! (fn [_]
(p/resolved {:path lock-file-path
:lock {:repo repo
@@ -992,6 +981,30 @@
:else
(done)))))))))
(deftest db-worker-node-export-client-ops-db-base64
(async done
(let [daemon (atom nil)
data-dir (node-helper/create-tmp-dir "db-worker-export-client-ops")
repo (str "logseq_db_export_client_ops_" (subs (str (random-uuid)) 0 8))]
(-> (p/let [{:keys [host port stop!]}
(start-daemon! {:root-dir data-dir
:repo repo})
_ (reset! daemon {:stop! stop!})
_ (invoke host port "thread-api/create-or-open-db" [repo {}])
export-base64 (invoke host port "thread-api/export-client-ops-db-base64" [repo])
decoded (js/Buffer.from export-base64 "base64")]
(is (string? export-base64))
(is (pos? (count export-base64)))
(is (= "SQLite format 3\u0000"
(.toString (.subarray decoded 0 16) "utf8"))))
(p/catch (fn [e]
(println "[db-worker-node-test] export-client-ops-db-base64 error:" e)
(is false (str e))))
(p/finally (fn []
(if-let [stop! (:stop! @daemon)]
(-> (stop!) (p/finally (fn [] (done))))
(done))))))))
(deftest db-worker-node-backup-db-sqlite
(async done
(let [daemon-a (atom nil)

View File

@@ -201,7 +201,7 @@
(vreset! thread-api/*thread-apis
(assoc thread-apis-prev
:thread-api/create-or-open-db (fn [_repo _opts] (p/resolved nil))
:thread-api/export-db (fn [_repo] (p/resolved nil))
:thread-api/export-db-base64 (fn [_repo] (p/resolved nil))
:thread-api/db-sync-rehydrate-large-titles (fn [_repo _graph-id] (p/resolved nil))))
(-> (p/with-redefs [rtc-log-and-state/rtc-log (fn [& _] nil)
client-op/update-graph-uuid (fn [& _] nil)
@@ -575,11 +575,11 @@
(reset! db-sync/*repo->latest-remote-tx latest-tx-prev)
(reset! db-sync/*repo->latest-remote-checksum latest-checksum-prev)))))))
(deftest thread-api-export-client-ops-db-checkpoints-and-exports-client-ops-file-test
(deftest thread-api-export-client-ops-db-base64-checkpoints-and-exports-client-ops-file-test
(async done
(restoring-worker-state
(fn []
(let [export-client-ops-db (@thread-api/*thread-apis :thread-api/export-client-ops-db)
(let [export-client-ops-db-base64 (@thread-api/*thread-apis :thread-api/export-client-ops-db-base64)
sql-calls (atom [])
export-calls (atom [])
expected-data (js/Uint8Array. #js [1 2 3])
@@ -596,15 +596,16 @@
(when (= :client-ops which-db)
#js {:exec (fn [sql]
(swap! sql-calls conj sql))}))]
(-> (export-client-ops-db test-repo)
(-> (export-client-ops-db-base64 test-repo)
(p/then (fn [result]
(is (= ["PRAGMA wal_checkpoint(TRUNCATE)"] @sql-calls))
(is (= 1 (count @export-calls)))
(is (contains? #{"client-ops/db.sqlite"
"client-ops-/db.sqlite"}
(first @export-calls)))
(is (instance? js/Uint8Array result))
(is (= [1 2 3] (vec result)))
(is (string? result))
(is (= [1 2 3]
(vec (js/Uint8Array. (.from js/Buffer result "base64")))))
(done)))
(p/catch (fn [error]
(is false (str error))

View File

@@ -17,7 +17,7 @@
(reset! worker-state/*db-sync-config {:ws-url "wss://example.com/sync/%s"})
(reset! worker-state/*state (assoc state-prev :auth/id-token "state-token"))
(reset! worker-state/*main-thread
(fn [qkw _direct-pass? _args-list]
(fn [qkw & _args]
(when (= qkw :thread-api/ensure-id&access-token)
(swap! refresh-calls inc))
(p/resolved {:id-token "refreshed-token"})))

View File

@@ -31,15 +31,14 @@
(fn [_] (p/resolved nil))
#{}
{:import? false})
args (list "thread-api/foo" true #js [1 2])
args (list "thread-api/foo" "transit-payload")
remote-invoke (aget (:proxy service) "remoteInvoke")]
(is (fn? remote-invoke))
(when (fn? remote-invoke)
(remote-invoke args))
(let [[method direct-pass? payload] @received]
(let [[method payload] @received]
(is (= "thread-api/foo" method))
(is (= true direct-pass?))
(is (= [1 2] (js->clj payload)))))
(is (= "transit-payload" payload))))
(p/finally (fn []
(when prev-platform
(platform/set-platform! prev-platform))))

View File

@@ -11,7 +11,7 @@
(deftest test-today-page-title-uses-default-time-zone
(async done
(let [formatted-args* (atom nil)]
(-> (p/with-redefs [transport/invoke (fn [_ method _ _args]
(-> (p/with-redefs [transport/invoke (fn [_ method _args]
(if (= method :thread-api/pull)
(p/resolved {:logseq.property.journal/title-format "yyyy-MM-dd"})
(p/rejected (ex-info "unexpected method" {:method method}))))
@@ -97,7 +97,7 @@
(is (= ["3.14" "1e5"] (:page-refs result))))))
(def ^:private mock-transport-invoke
(fn [_ method _ args]
(fn [_ method args]
(case method
;; pull-tag-by-name uses :thread-api/q
:thread-api/q
@@ -130,7 +130,7 @@
(testing "resolves integer id refs to uuid+title maps"
(async done
(let [page-uuid (random-uuid)
mock-invoke (fn [_ _ _ args]
mock-invoke (fn [_ _ args]
(let [[_ _ lookup] args]
(p/resolved
(cond
@@ -198,7 +198,7 @@
(deftest test-resolve-date-page-id-rejects-invalid-date
(async done
(let [mock-invoke (fn [_ _ _ args]
(let [mock-invoke (fn [_ _ args]
(let [[_ _ lookup] args]
(p/resolved
(if (= lookup :logseq.class/Journal)
@@ -236,7 +236,7 @@
:logseq.property/public? true})
(def ^:private selector-mock-transport-invoke
(fn [_ method _ args]
(fn [_ method args]
(case method
:thread-api/q
(let [[_ [_ name-arg]] args]

View File

@@ -49,7 +49,7 @@
:lookup 42
:selector '[*]}]
(-> (p/with-redefs [cli-server/ensure-server! (fn [config _repo] config)
transport/invoke (fn [_ method _ args]
transport/invoke (fn [_ method args]
(swap! invoke-calls* conj {:method method :args args})
(p/resolved {:db/id 42 :block/title "Debug Home"}))]
(p/let [result (debug-command/execute-debug-pull action {:base-url "http://example"})]
@@ -72,7 +72,7 @@
:lookup [:db/ident :missing/ident]
:selector '[*]}]
(-> (p/with-redefs [cli-server/ensure-server! (fn [config _repo] config)
transport/invoke (fn [_ _method _ _args]
transport/invoke (fn [_ _method _args]
(p/resolved nil))]
(p/let [result (debug-command/execute-debug-pull action {:base-url "http://example"})]
(is (= :error (:status result)))

View File

@@ -40,7 +40,7 @@
:graph "demo-graph"}]
(-> (p/with-redefs [cli-server/ensure-server! (fn [_ _]
(p/resolved {:base-url "http://example"}))
transport/invoke (fn [_ method _ args]
transport/invoke (fn [_ method args]
(swap! invoke-calls* conj [method args])
(p/resolved [[:logseq.kv/schema-version 7]
[:logseq.kv/graph-created-at 40000]
@@ -64,8 +64,8 @@
(-> (p/with-redefs [cli-server/list-graphs (fn [_] ["demo"])
cli-server/ensure-server! (fn [config _repo]
(p/resolved (assoc config :base-url "http://example")))
transport/invoke (fn [_ method direct-pass? args]
(swap! invoke-calls conj [method direct-pass? args])
transport/invoke (fn [_ method args]
(swap! invoke-calls conj [method args])
(p/resolved {:path (second args)}))]
(p/let [result (commands/execute {:type :graph-backup-create
:repo "logseq_db_demo"
@@ -74,7 +74,7 @@
{:root-dir root-dir})]
(is (= :ok (:status result)))
(is (= 1 (count @invoke-calls)))
(let [[method _ [repo backup-db-path]] (first @invoke-calls)
(let [[method [repo backup-db-path]] (first @invoke-calls)
expected-segment (node-path/join
(graph-dir/repo->encoded-graph-dir-name repo)
"backup"
@@ -188,7 +188,7 @@
transport/read-input (fn [{:keys [format path]}]
(swap! read-calls conj [format path])
(js/Buffer.from "sqlite" "utf8"))
transport/invoke (fn [_ method _ args]
transport/invoke (fn [_ method args]
(swap! invoke-calls conj [method args])
(p/resolved {:ok true}))]
(p/let [result (commands/execute {:type :graph-backup-restore
@@ -242,7 +242,7 @@
:graph "demo-graph"}]
(-> (p/with-redefs [cli-server/ensure-server! (fn [_ _]
(p/resolved {:base-url "http://example"}))
transport/invoke (fn [_ method _ _]
transport/invoke (fn [_ method _]
(case method
:thread-api/q
(p/resolved [[:logseq.kv/db-type :sqlite]

View File

@@ -10,7 +10,7 @@
(let [ref-uuid "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"
calls* (atom [])]
(-> (p/with-redefs [cli-server/ensure-server! (fn [_ _] {:base-url "http://example"})
transport/invoke (fn [_ method _ args]
transport/invoke (fn [_ method args]
(swap! calls* conj {:method method :args args})
(case method
:thread-api/cli-list-pages
@@ -47,7 +47,7 @@
(let [ref-uuid "bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb"
calls* (atom [])]
(-> (p/with-redefs [cli-server/ensure-server! (fn [_ _] {:base-url "http://example"})
transport/invoke (fn [_ method _ args]
transport/invoke (fn [_ method args]
(swap! calls* conj {:method method :args args})
(case method
:thread-api/cli-list-nodes

View File

@@ -15,7 +15,7 @@
:multi-id? false}]
(-> (p/with-redefs [cli-server/ensure-server! (fn [config _repo]
(p/resolved (assoc config :base-url "http://example")))
transport/invoke (fn [_ method _ args]
transport/invoke (fn [_ method args]
(case method
:thread-api/pull
(p/resolved {:db/id 190
@@ -48,7 +48,7 @@
:multi-id? true}]
(-> (p/with-redefs [cli-server/ensure-server! (fn [config _repo]
(p/resolved (assoc config :base-url "http://example")))
transport/invoke (fn [_ method _ _]
transport/invoke (fn [_ method _]
(case method
:thread-api/pull
(p/resolved {:db/id 190
@@ -79,7 +79,7 @@
:multi-id? false}]
(-> (p/with-redefs [cli-server/ensure-server! (fn [config _repo]
(p/resolved (assoc config :base-url "http://example")))
transport/invoke (fn [_ method _ args]
transport/invoke (fn [_ method args]
(case method
:thread-api/pull
(p/resolved {:db/id 190
@@ -110,7 +110,7 @@
boom (js/Error. "transport exploded")]
(-> (p/with-redefs [cli-server/ensure-server! (fn [config _repo]
(p/resolved (assoc config :base-url "http://example")))
transport/invoke (fn [_ method _ _args]
transport/invoke (fn [_ method _args]
(case method
:thread-api/pull
(p/rejected boom)

View File

@@ -48,7 +48,7 @@
(async done
(let [calls* (atom [])]
(-> (p/with-redefs [cli-server/ensure-server! (fn [_ _] {:base-url "http://example"})
transport/invoke (fn [_ method _ [repo [query-text query-input]]]
transport/invoke (fn [_ method [repo [query-text query-input]]]
(swap! calls* conj {:method method
:repo repo
:query-text (pr-str query-text)
@@ -89,7 +89,7 @@
(let [ref-uuid "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"
calls* (atom [])]
(-> (p/with-redefs [cli-server/ensure-server! (fn [_ _] {:base-url "http://example"})
transport/invoke (fn [_ method _ args]
transport/invoke (fn [_ method args]
(swap! calls* conj {:method method :args args})
(case method
:thread-api/q
@@ -133,7 +133,7 @@
live-page-parent {:db/id 51
:block/title "Live Page"}]
(-> (p/with-redefs [cli-server/ensure-server! (fn [_ _] {:base-url "http://example"})
transport/invoke (fn [_ _ _ _]
transport/invoke (fn [_ _ _]
[{:db/id 1 :block/title "alpha live"
:block/parent live-page-parent}
{:db/id 2 :block/title "alpha orphan"
@@ -155,7 +155,7 @@
(deftest test-execute-search-page-skips-recycled-pages
(async done
(-> (p/with-redefs [cli-server/ensure-server! (fn [_ _] {:base-url "http://example"})
transport/invoke (fn [_ _ _ _]
transport/invoke (fn [_ _ _]
[{:db/id 1 :block/title "Home"}
{:db/id 2 :block/title "Recycled Home"
:logseq.property/deleted-at 1712000000000}

View File

@@ -106,7 +106,7 @@
(deftest test-fetch-user-properties-formats-datetime
(let [fetch #'show-command/fetch-user-properties
call-count (atom 0)
mock-invoke (fn [_ _method _ _args]
mock-invoke (fn [_ _method _args]
(let [call-idx (swap! call-count inc)]
(p/resolved
(case call-idx
@@ -137,7 +137,7 @@
(deftest test-fetch-user-properties-includes-built-in-datetime
(let [fetch #'show-command/fetch-user-properties
call-count (atom 0)
mock-invoke (fn [_ _method _ _args]
mock-invoke (fn [_ _method _args]
(let [call-idx (swap! call-count inc)]
(p/resolved
(case call-idx
@@ -177,7 +177,7 @@
uuid-entities
linked-refs-by-root-id
parents-by-block-id]}]
(fn [_ method _ args]
(fn [_ method args]
(case method
:thread-api/pull
(let [[_repo _selector target] args]
@@ -509,7 +509,7 @@
(deftest test-execute-show-fails-when-breadcrumb-fetch-fails
(async done
(let [invoke-mock (fn [_ method _ args]
(let [invoke-mock (fn [_ method args]
(case method
:thread-api/pull
(let [[_repo _selector target] args]

View File

@@ -100,8 +100,8 @@
(-> (p/with-redefs [cli-server/ensure-server! (fn [config repo]
(swap! ensure-calls conj [config repo])
(p/resolved (assoc config :base-url "http://example")))
transport/invoke (fn [_ method direct-pass? args]
(swap! invoke-calls conj [method direct-pass? args])
transport/invoke (fn [_ method args]
(swap! invoke-calls conj [method args])
(case method
:thread-api/db-sync-status
(let [idx (swap! status-calls inc)]
@@ -131,8 +131,8 @@
worker-sync-config (atom {:ws-url nil})]
(-> (p/with-redefs [cli-server/ensure-server! (fn [config _repo]
(p/resolved (assoc config :base-url "http://example")))
transport/invoke (fn [_ method direct-pass? args]
(swap! invoke-calls conj [method direct-pass? args])
transport/invoke (fn [_ method args]
(swap! invoke-calls conj [method args])
(case method
:thread-api/set-db-sync-config
(let [cfg (first args)]
@@ -159,7 +159,7 @@
(is (= :ok (:status result)))
(is (seq set-config-calls))
(is (every? #(= "wss://api.logseq.io/sync/%s"
(get-in % [2 0 :ws-url]))
(get-in % [1 0 :ws-url]))
set-config-calls))))
(p/catch (fn [e]
(is false (str "unexpected error: " e))))
@@ -170,8 +170,8 @@
(let [invoke-calls (atom [])]
(-> (p/with-redefs [cli-server/ensure-server! (fn [config _repo]
(p/resolved (assoc config :base-url "http://example")))
transport/invoke (fn [_ method direct-pass? args]
(swap! invoke-calls conj [method direct-pass? args])
transport/invoke (fn [_ method args]
(swap! invoke-calls conj [method args])
(case method
:thread-api/get-db-sync-config (p/resolved {:auth-token "worker-token"})
:thread-api/q (p/resolved true)
@@ -191,7 +191,7 @@
:refresh-token "refresh-token"
:id-token "runtime-token"})]
(is (= :ok (:status result)))
(is (some #(= [:thread-api/verify-and-save-e2ee-password false ["refresh-token" "pw"]]
(is (some #(= [:thread-api/verify-and-save-e2ee-password ["refresh-token" "pw"]]
%)
@invoke-calls))))
(p/catch (fn [e]
@@ -203,8 +203,8 @@
(let [invoke-calls (atom [])]
(-> (p/with-redefs [cli-server/ensure-server! (fn [config _repo]
(p/resolved (assoc config :base-url "http://example")))
transport/invoke (fn [_ method direct-pass? args]
(swap! invoke-calls conj [method direct-pass? args])
transport/invoke (fn [_ method args]
(swap! invoke-calls conj [method args])
(case method
:thread-api/db-sync-status
(p/resolved {:repo "logseq_db_demo"
@@ -232,7 +232,7 @@
start-calls (atom 0)]
(-> (p/with-redefs [cli-server/ensure-server! (fn [config _repo]
(p/resolved (assoc config :base-url "http://example")))
transport/invoke (fn [_ method _direct-pass? _args]
transport/invoke (fn [_ method _args]
(case method
:thread-api/db-sync-start
(do
@@ -275,8 +275,8 @@
(-> (p/with-redefs [cli-server/ensure-server! (fn [config repo]
(swap! ensure-calls conj [config repo])
(p/resolved (assoc config :base-url "http://example")))
transport/invoke (fn [_ method direct-pass? args]
(swap! invoke-calls conj [method direct-pass? args])
transport/invoke (fn [_ method args]
(swap! invoke-calls conj [method args])
(p/resolved {:ok true}))]
(p/let [result (sync-command/execute {:type :sync-start
:repo "logseq_db_demo"}
@@ -300,8 +300,8 @@
(-> (p/with-redefs [cli-server/ensure-server! (fn [config repo]
(swap! ensure-calls conj [config repo])
(p/resolved (assoc config :base-url "http://example")))
transport/invoke (fn [_ method direct-pass? args]
(swap! invoke-calls conj [method direct-pass? args])
transport/invoke (fn [_ method args]
(swap! invoke-calls conj [method args])
(p/resolved {:ok true}))]
(p/let [result (sync-command/execute {:type :sync-upload
:repo "logseq_db_demo"}
@@ -325,8 +325,8 @@
(-> (p/with-redefs [cli-server/ensure-server! (fn [config repo]
(swap! ensure-calls conj [config repo])
(p/resolved (assoc config :base-url "http://example")))
transport/invoke (fn [_ method direct-pass? args]
(swap! invoke-calls conj [method direct-pass? args])
transport/invoke (fn [_ method args]
(swap! invoke-calls conj [method args])
(p/resolved []))]
(p/let [result (sync-command/execute {:type :sync-download
:repo "logseq_db_demo"
@@ -366,8 +366,8 @@
cli-common/unlink-graph! (fn [& args]
(swap! unlink-calls conj args)
"/tmp/unlinked-demo")
transport/invoke (fn [_ method direct-pass? args]
(swap! invoke-calls conj [method direct-pass? args])
transport/invoke (fn [_ method args]
(swap! invoke-calls conj [method args])
(case method
:thread-api/set-db-sync-config
(p/resolved nil)
@@ -421,7 +421,7 @@
cli-common/unlink-graph! (fn [& args]
(swap! unlink-calls conj args)
"/tmp/unlinked-demo")
transport/invoke (fn [_ method _direct-pass? _args]
transport/invoke (fn [_ method _args]
(case method
:thread-api/db-sync-list-remote-graphs
(p/resolved [{:graph-id "remote-graph-id"
@@ -459,8 +459,8 @@
[])
cli-server/ensure-server! (fn [config _repo]
(p/resolved (assoc config :base-url "http://example")))
transport/invoke (fn [_ method direct-pass? args]
(swap! invoke-calls conj [method direct-pass? args])
transport/invoke (fn [_ method args]
(swap! invoke-calls conj [method args])
(case method
:thread-api/db-sync-list-remote-graphs
(p/resolved [{:graph-id "remote-graph-id"
@@ -484,12 +484,12 @@
:refresh-token "refresh-token"})]
(is (= :ok (:status result)))
(is (= "remote-graph-id" (get-in result [:data :graph-id])))
(is (some #(= [:thread-api/get-e2ee-password false ["refresh-token"]]
(is (some #(= [:thread-api/get-e2ee-password ["refresh-token"]]
%)
@invoke-calls))
(is (not-any? #(= :thread-api/verify-and-save-e2ee-password (first %))
@invoke-calls))
(is (some #(= [:thread-api/db-sync-download-graph-by-id false ["logseq_db_demo" "remote-graph-id" true]]
(is (some #(= [:thread-api/db-sync-download-graph-by-id ["logseq_db_demo" "remote-graph-id" true]]
%)
@invoke-calls))))
(p/catch (fn [e]
@@ -510,7 +510,7 @@
cli-common/unlink-graph! (fn [& args]
(swap! unlink-calls conj args)
"/tmp/unlinked-demo")
transport/invoke (fn [_ method _direct-pass? _args]
transport/invoke (fn [_ method _args]
(case method
:thread-api/db-sync-list-remote-graphs
(p/resolved [{:graph-id "remote-graph-id"
@@ -543,7 +543,7 @@
(let [status-calls (atom 0)]
(-> (p/with-redefs [cli-server/ensure-server! (fn [config _repo]
(p/resolved (assoc config :base-url "http://example")))
transport/invoke (fn [_ method _direct-pass? _args]
transport/invoke (fn [_ method _args]
(case method
:thread-api/db-sync-status
(let [idx (swap! status-calls inc)]
@@ -580,8 +580,8 @@
(-> (p/with-redefs [cli-server/ensure-server! (fn [config repo]
(swap! ensure-calls conj [config repo])
(p/resolved (assoc config :base-url "http://example")))
transport/invoke (fn [_ method direct-pass? args]
(swap! invoke-calls conj [method direct-pass? args])
transport/invoke (fn [_ method args]
(swap! invoke-calls conj [method args])
(case method
:thread-api/db-sync-stop (p/resolved {:ok true})
(p/resolved nil)))]
@@ -591,9 +591,9 @@
(is (= [[{:root-dir "/tmp"}
"logseq_db_demo"]]
@ensure-calls))
(is (= [[:thread-api/set-db-sync-config false [{:ws-url nil
(is (= [[:thread-api/set-db-sync-config [{:ws-url nil
:http-base nil}]]
[:thread-api/db-sync-stop false []]]
[:thread-api/db-sync-stop []]]
@invoke-calls))))
(p/catch (fn [e]
(is false (str "unexpected error: " e))))
@@ -606,8 +606,8 @@
(-> (p/with-redefs [cli-server/ensure-server! (fn [config repo]
(swap! ensure-calls conj [config repo])
(p/resolved (assoc config :base-url "http://example")))
transport/invoke (fn [_ method direct-pass? args]
(swap! invoke-calls conj [method direct-pass? args])
transport/invoke (fn [_ method args]
(swap! invoke-calls conj [method args])
(case method
:thread-api/db-sync-status (p/resolved {:repo "logseq_db_demo"
:ws-state :open
@@ -637,8 +637,8 @@
(-> (p/with-redefs [cli-server/ensure-server! (fn [config repo]
(swap! ensure-calls conj [config repo])
(p/resolved (assoc config :base-url "http://example")))
transport/invoke (fn [_ method direct-pass? args]
(swap! invoke-calls conj [method direct-pass? args])
transport/invoke (fn [_ method args]
(swap! invoke-calls conj [method args])
(p/resolved {:ok true}))]
(p/let [_ (execute-with-runtime-auth {:type :sync-upload
:repo "logseq_db_demo"}
@@ -649,11 +649,11 @@
@ensure-calls))
(is (= :thread-api/sync-app-state (ffirst @invoke-calls)))
(is (= "runtime-token"
(get-in (first @invoke-calls) [2 0 :auth/id-token])))
(is (= [:thread-api/set-db-sync-config false [{:ws-url nil
(get-in (first @invoke-calls) [1 0 :auth/id-token])))
(is (= [:thread-api/set-db-sync-config [{:ws-url nil
:http-base nil}]]
(second @invoke-calls)))
(is (= [:thread-api/db-sync-upload-graph false ["logseq_db_demo"]]
(is (= [:thread-api/db-sync-upload-graph ["logseq_db_demo"]]
(nth @invoke-calls 2)))))
(p/catch (fn [e]
(is false (str "unexpected error: " e))))
@@ -664,8 +664,8 @@
(let [invoke-calls (atom [])]
(-> (p/with-redefs [cli-server/ensure-server! (fn [config _repo]
(p/resolved (assoc config :base-url "http://example")))
transport/invoke (fn [_ method direct-pass? args]
(swap! invoke-calls conj [method direct-pass? args])
transport/invoke (fn [_ method args]
(swap! invoke-calls conj [method args])
(case method
:thread-api/verify-and-save-e2ee-password
(p/resolved nil)
@@ -682,14 +682,14 @@
:refresh-token "refresh-token"
:id-token "runtime-token"})]
(is (= :ok (:status result)))
(is (some #(= [:thread-api/verify-and-save-e2ee-password false ["refresh-token" "pw"]]
(is (some #(= [:thread-api/verify-and-save-e2ee-password ["refresh-token" "pw"]]
%)
@invoke-calls))
(is (some #(= [:thread-api/db-sync-upload-graph false ["logseq_db_demo"]]
(is (some #(= [:thread-api/db-sync-upload-graph ["logseq_db_demo"]]
%)
@invoke-calls))
(let [method-index (fn [method]
(first (keep-indexed (fn [idx [method' _direct-pass? _args]]
(first (keep-indexed (fn [idx [method' _args]]
(when (= method method')
idx))
@invoke-calls)))]
@@ -703,7 +703,7 @@
(async done
(-> (p/with-redefs [cli-server/ensure-server! (fn [config _repo]
(p/resolved (assoc config :base-url "http://example")))
transport/invoke (fn [_ method _direct-pass? _args]
transport/invoke (fn [_ method _args]
(case method
:thread-api/set-db-sync-config
(p/resolved nil)
@@ -730,7 +730,7 @@
(async done
(-> (p/with-redefs [cli-server/ensure-server! (fn [config _repo]
(p/resolved (assoc config :base-url "http://example")))
transport/invoke (fn [_ method _direct-pass? _args]
transport/invoke (fn [_ method _args]
(case method
:thread-api/set-db-sync-config
(p/resolved nil)
@@ -759,7 +759,7 @@
(async done
(-> (p/with-redefs [cli-server/ensure-server! (fn [config _repo]
(p/resolved (assoc config :base-url "http://example")))
transport/invoke (fn [_ method _direct-pass? _args]
transport/invoke (fn [_ method _args]
(case method
:thread-api/set-db-sync-config
(p/resolved nil)
@@ -791,8 +791,8 @@
(-> (p/with-redefs [cli-server/ensure-server! (fn [config repo]
(swap! ensure-calls conj [config repo])
(p/resolved (assoc config :base-url "http://example")))
transport/invoke (fn [_ method direct-pass? args]
(swap! invoke-calls conj [method direct-pass? args])
transport/invoke (fn [_ method args]
(swap! invoke-calls conj [method args])
(case method
:thread-api/db-sync-list-remote-graphs
(p/resolved [{:graph-id "remote-graph-id"
@@ -818,24 +818,23 @@
"logseq_db_demo"]]
@ensure-calls))
(is (= :thread-api/sync-app-state (get-in @invoke-calls [0 0])))
(is (= "runtime-token" (get-in @invoke-calls [0 2 0 :auth/id-token])))
(is (= [:thread-api/set-db-sync-config false [{:ws-url nil
(is (= "runtime-token" (get-in @invoke-calls [0 1 0 :auth/id-token])))
(is (= [:thread-api/set-db-sync-config [{:ws-url nil
:http-base nil}]]
(nth @invoke-calls 1)))
(is (= [:thread-api/db-sync-list-remote-graphs false []]
(is (= [:thread-api/db-sync-list-remote-graphs []]
(nth @invoke-calls 2)))
(is (= :thread-api/sync-app-state (get-in @invoke-calls [3 0])))
(is (= "runtime-token" (get-in @invoke-calls [3 2 0 :auth/id-token])))
(is (= [:thread-api/set-db-sync-config false [{:ws-url nil
(is (= "runtime-token" (get-in @invoke-calls [3 1 0 :auth/id-token])))
(is (= [:thread-api/set-db-sync-config [{:ws-url nil
:http-base nil}]]
(nth @invoke-calls 4)))
(is (= [:thread-api/verify-and-save-e2ee-password false ["refresh-token" "pw"]]
(is (= [:thread-api/verify-and-save-e2ee-password ["refresh-token" "pw"]]
(nth @invoke-calls 5)))
(let [[method direct-pass? args] (nth @invoke-calls 6)]
(let [[method args] (nth @invoke-calls 6)]
(is (= :thread-api/q method))
(is (= false direct-pass?))
(is (= "logseq_db_demo" (first args))))
(is (= [:thread-api/db-sync-download-graph-by-id false ["logseq_db_demo" "remote-graph-id" true]]
(is (= [:thread-api/db-sync-download-graph-by-id ["logseq_db_demo" "remote-graph-id" true]]
(nth @invoke-calls 7)))))
(p/catch (fn [e]
(is false (str "unexpected error: " e))))
@@ -846,9 +845,8 @@
(let [invoke-calls (atom [])]
(-> (p/with-redefs [cli-server/ensure-server! (fn [config _repo]
(p/resolved (assoc config :base-url "http://example")))
transport/invoke (fn [cfg method direct-pass? args]
transport/invoke (fn [cfg method args]
(swap! invoke-calls conj {:method method
:direct-pass? direct-pass?
:args args
:timeout-ms (:timeout-ms cfg)})
(case method
@@ -909,7 +907,7 @@
sync-command/print-progress-line! (fn [line]
(swap! printed-lines conj line)
nil)
transport/invoke (fn [_ method _direct-pass? _args]
transport/invoke (fn [_ method _args]
(case method
:thread-api/db-sync-list-remote-graphs
(p/resolved [{:graph-id "remote-graph-id"
@@ -989,8 +987,8 @@
(-> (p/with-redefs [cli-server/ensure-server! (fn [config repo]
(swap! ensure-calls conj [config repo])
(p/resolved (assoc config :base-url "http://example")))
transport/invoke (fn [_ method direct-pass? args]
(swap! invoke-calls conj [method direct-pass? args])
transport/invoke (fn [_ method args]
(swap! invoke-calls conj [method args])
(case method
:thread-api/db-sync-list-remote-graphs
(p/resolved [{:graph-id "remote-graph-id"
@@ -1018,22 +1016,21 @@
"logseq_db_demo"]]
@ensure-calls))
(is (= :thread-api/sync-app-state (get-in @invoke-calls [0 0])))
(is (= "runtime-token" (get-in @invoke-calls [0 2 0 :auth/id-token])))
(is (= [:thread-api/set-db-sync-config false [{:ws-url nil
(is (= "runtime-token" (get-in @invoke-calls [0 1 0 :auth/id-token])))
(is (= [:thread-api/set-db-sync-config [{:ws-url nil
:http-base nil}]]
(nth @invoke-calls 1)))
(is (= [:thread-api/db-sync-list-remote-graphs false []]
(is (= [:thread-api/db-sync-list-remote-graphs []]
(nth @invoke-calls 2)))
(is (= :thread-api/sync-app-state (get-in @invoke-calls [3 0])))
(is (= "runtime-token" (get-in @invoke-calls [3 2 0 :auth/id-token])))
(is (= [:thread-api/set-db-sync-config false [{:ws-url nil
(is (= "runtime-token" (get-in @invoke-calls [3 1 0 :auth/id-token])))
(is (= [:thread-api/set-db-sync-config [{:ws-url nil
:http-base nil}]]
(nth @invoke-calls 4)))
(let [[method direct-pass? args] (nth @invoke-calls 5)]
(let [[method args] (nth @invoke-calls 5)]
(is (= :thread-api/q method))
(is (= false direct-pass?))
(is (= "logseq_db_demo" (first args))))
(is (= [:thread-api/db-sync-download-graph-by-id false ["logseq_db_demo" "remote-graph-id" false]]
(is (= [:thread-api/db-sync-download-graph-by-id ["logseq_db_demo" "remote-graph-id" false]]
(nth @invoke-calls 6)))))
(p/catch (fn [e]
(is false (str "unexpected error: " e))))
@@ -1044,8 +1041,8 @@
(let [invoke-calls (atom [])]
(-> (p/with-redefs [cli-server/ensure-server! (fn [config _repo]
(p/resolved (assoc config :base-url "http://example")))
transport/invoke (fn [_ method direct-pass? args]
(swap! invoke-calls conj [method direct-pass? args])
transport/invoke (fn [_ method args]
(swap! invoke-calls conj [method args])
(case method
:thread-api/db-sync-list-remote-graphs
(p/resolved [{:graph-id "other-id"
@@ -1061,11 +1058,11 @@
(is (= :error (:status result)))
(is (= :remote-graph-not-found (get-in result [:error :code])))
(is (= :thread-api/sync-app-state (get-in @invoke-calls [0 0])))
(is (= "runtime-token" (get-in @invoke-calls [0 2 0 :auth/id-token])))
(is (= [:thread-api/set-db-sync-config false [{:ws-url nil
(is (= "runtime-token" (get-in @invoke-calls [0 1 0 :auth/id-token])))
(is (= [:thread-api/set-db-sync-config [{:ws-url nil
:http-base nil}]]
(nth @invoke-calls 1)))
(is (= [:thread-api/db-sync-list-remote-graphs false []]
(is (= [:thread-api/db-sync-list-remote-graphs []]
(nth @invoke-calls 2)))))
(p/catch (fn [e]
(is false (str "unexpected error: " e))))
@@ -1075,7 +1072,7 @@
(async done
(-> (p/with-redefs [cli-server/ensure-server! (fn [config _repo]
(p/resolved (assoc config :base-url "http://example")))
transport/invoke (fn [_ method _direct-pass? _args]
transport/invoke (fn [_ method _args]
(case method
:thread-api/db-sync-list-remote-graphs
(p/resolved [{:graph-id "remote-graph-id"
@@ -1109,8 +1106,8 @@
(p/resolved (assoc config
:repo repo
:base-url "http://example")))
transport/invoke (fn [_ method direct-pass? args]
(swap! invoke-calls conj [method direct-pass? args])
transport/invoke (fn [_ method args]
(swap! invoke-calls conj [method args])
(case method
:thread-api/db-sync-list-remote-graphs
(p/resolved [{:graph-id "remote-graph-id"
@@ -1151,8 +1148,8 @@
cli-server/ensure-server! (fn [config repo]
(swap! ensure-calls conj [config repo])
(p/resolved (assoc config :base-url "http://example")))
transport/invoke (fn [_ method direct-pass? args]
(swap! invoke-calls conj [method direct-pass? args])
transport/invoke (fn [_ method args]
(swap! invoke-calls conj [method args])
(p/resolved []))]
(p/let [_ (sync-command/execute {:type :sync-remote-graphs}
{:base-url "http://example"
@@ -1168,11 +1165,11 @@
:root-dir "/tmp"}]
@auth-calls))
(is (= :thread-api/sync-app-state (get-in @invoke-calls [0 0])))
(is (= "resolved-token" (get-in @invoke-calls [0 2 0 :auth/id-token])))
(is (= [:thread-api/set-db-sync-config false [{:ws-url "wss://sync.example.com/sync/%s"
(is (= "resolved-token" (get-in @invoke-calls [0 1 0 :auth/id-token])))
(is (= [:thread-api/set-db-sync-config [{:ws-url "wss://sync.example.com/sync/%s"
:http-base "https://sync.example.com"}]]
(nth @invoke-calls 1)))
(is (= [:thread-api/db-sync-list-remote-graphs false []]
(is (= [:thread-api/db-sync-list-remote-graphs []]
(nth @invoke-calls 2)))))
(p/catch (fn [e]
(is false (str "unexpected error: " e))))
@@ -1185,8 +1182,8 @@
(p/rejected (ex-info "missing auth"
{:code :missing-auth
:hint "Run logseq login first."})))
transport/invoke (fn [_ method direct-pass? args]
(swap! invoke-calls conj [method direct-pass? args])
transport/invoke (fn [_ method args]
(swap! invoke-calls conj [method args])
(p/resolved []))]
(p/let [result (sync-command/execute {:type :sync-remote-graphs}
{:base-url "http://example"
@@ -1206,19 +1203,19 @@
(-> (p/with-redefs [cli-server/ensure-server! (fn [config repo]
(swap! ensure-calls conj [config repo])
(p/resolved (assoc config :base-url "http://example")))
transport/invoke (fn [_ method direct-pass? args]
(swap! invoke-calls conj [method direct-pass? args])
transport/invoke (fn [_ method args]
(swap! invoke-calls conj [method args])
(p/resolved {:ok true}))]
(p/let [_ (execute-with-runtime-auth {:type :sync-ensure-keys}
{:base-url "http://example"
:root-dir "/tmp"})]
(is (= [] @ensure-calls))
(is (= :thread-api/sync-app-state (get-in @invoke-calls [0 0])))
(is (= "runtime-token" (get-in @invoke-calls [0 2 0 :auth/id-token])))
(is (= [:thread-api/set-db-sync-config false [{:ws-url nil
(is (= "runtime-token" (get-in @invoke-calls [0 1 0 :auth/id-token])))
(is (= [:thread-api/set-db-sync-config [{:ws-url nil
:http-base nil}]]
(nth @invoke-calls 1)))
(is (= [:thread-api/db-sync-ensure-user-rsa-keys false []]
(is (= [:thread-api/db-sync-ensure-user-rsa-keys []]
(nth @invoke-calls 2)))))
(p/catch (fn [e]
(is false (str "unexpected error: " e))))
@@ -1227,8 +1224,8 @@
(deftest test-execute-sync-ensure-keys-verifies-and-persists-e2ee-password-when-provided
(async done
(let [invoke-calls (atom [])]
(-> (p/with-redefs [transport/invoke (fn [_ method direct-pass? args]
(swap! invoke-calls conj [method direct-pass? args])
(-> (p/with-redefs [transport/invoke (fn [_ method args]
(swap! invoke-calls conj [method args])
(p/resolved {:ok true}))]
(p/let [_ (sync-command/execute {:type :sync-ensure-keys
:e2ee-password "pw"}
@@ -1243,7 +1240,7 @@
:thread-api/set-db-sync-config
:thread-api/db-sync-ensure-user-rsa-keys]
(mapv first @invoke-calls)))
(is (some #(= [:thread-api/verify-and-save-e2ee-password false ["refresh-token" "pw"]]
(is (some #(= [:thread-api/verify-and-save-e2ee-password ["refresh-token" "pw"]]
%)
@invoke-calls))))
(p/catch (fn [e]
@@ -1253,8 +1250,8 @@
(deftest test-execute-sync-ensure-keys-upload-keys-enables-server-upload-flow
(async done
(let [invoke-calls (atom [])]
(-> (p/with-redefs [transport/invoke (fn [_ method direct-pass? args]
(swap! invoke-calls conj [method direct-pass? args])
(-> (p/with-redefs [transport/invoke (fn [_ method args]
(swap! invoke-calls conj [method args])
(p/resolved {:ok true}))]
(p/let [_ (sync-command/execute {:type :sync-ensure-keys
:upload-keys true
@@ -1270,11 +1267,11 @@
:thread-api/set-db-sync-config
:thread-api/verify-and-save-e2ee-password]
(mapv first @invoke-calls)))
(is (some #(= [:thread-api/db-sync-ensure-user-rsa-keys false [{:ensure-server? true
(is (some #(= [:thread-api/db-sync-ensure-user-rsa-keys [{:ensure-server? true
:password "pw"}]]
%)
@invoke-calls))
(is (some #(= [:thread-api/verify-and-save-e2ee-password false ["refresh-token" "pw"]]
(is (some #(= [:thread-api/verify-and-save-e2ee-password ["refresh-token" "pw"]]
%)
@invoke-calls))))
(p/catch (fn [e]
@@ -1288,8 +1285,8 @@
(-> (p/with-redefs [cli-server/ensure-server! (fn [config repo]
(swap! ensure-calls conj [config repo])
(p/resolved (assoc config :base-url "http://example")))
transport/invoke (fn [_ method direct-pass? args]
(swap! invoke-calls conj [method direct-pass? args])
transport/invoke (fn [_ method args]
(swap! invoke-calls conj [method args])
(p/resolved {:ok true}))]
(p/let [result (sync-command/execute {:type :sync-grant-access
:repo "logseq_db_demo"
@@ -1315,8 +1312,8 @@
(-> (p/with-redefs [cli-server/ensure-server! (fn [config repo]
(swap! ensure-calls conj [config repo])
(p/resolved (assoc config :base-url "http://example")))
transport/invoke (fn [_ method direct-pass? args]
(swap! invoke-calls conj [method direct-pass? args])
transport/invoke (fn [_ method args]
(swap! invoke-calls conj [method args])
(p/resolved {:ok true}))]
(p/let [_ (execute-with-runtime-auth {:type :sync-grant-access
:repo "logseq_db_demo"
@@ -1328,11 +1325,11 @@
"logseq_db_demo"]]
@ensure-calls))
(is (= :thread-api/sync-app-state (get-in @invoke-calls [0 0])))
(is (= "runtime-token" (get-in @invoke-calls [0 2 0 :auth/id-token])))
(is (= [:thread-api/set-db-sync-config false [{:ws-url nil
(is (= "runtime-token" (get-in @invoke-calls [0 1 0 :auth/id-token])))
(is (= [:thread-api/set-db-sync-config [{:ws-url nil
:http-base nil}]]
(nth @invoke-calls 1)))
(is (= [:thread-api/db-sync-grant-graph-access false ["logseq_db_demo" "graph-uuid" "user@example.com"]]
(is (= [:thread-api/db-sync-grant-graph-access ["logseq_db_demo" "graph-uuid" "user@example.com"]]
(nth @invoke-calls 2)))))
(p/catch (fn [e]
(is false (str "unexpected error: " e))))
@@ -1345,8 +1342,8 @@
(-> (p/with-redefs [cli-server/ensure-server! (fn [config repo]
(swap! ensure-calls conj [config repo])
(p/resolved (assoc config :base-url "http://example")))
transport/invoke (fn [_ method direct-pass? args]
(swap! invoke-calls conj [method direct-pass? args])
transport/invoke (fn [_ method args]
(swap! invoke-calls conj [method args])
(p/resolved {:ok true}))]
(p/let [_ (sync-command/execute {:type :sync-config-get
:config-key :ws-url}
@@ -1363,8 +1360,8 @@
(async done
(let [invoke-calls (atom [])
update-calls (atom [])]
(-> (p/with-redefs [transport/invoke (fn [_ method direct-pass? args]
(swap! invoke-calls conj [method direct-pass? args])
(-> (p/with-redefs [transport/invoke (fn [_ method args]
(swap! invoke-calls conj [method args])
(p/resolved nil))
cli-config/update-config! (fn [config updates]
(swap! update-calls conj [config updates])
@@ -1389,8 +1386,8 @@
(async done
(let [invoke-calls (atom [])
update-calls (atom [])]
(-> (p/with-redefs [transport/invoke (fn [_ method direct-pass? args]
(swap! invoke-calls conj [method direct-pass? args])
(-> (p/with-redefs [transport/invoke (fn [_ method args]
(swap! invoke-calls conj [method args])
(p/resolved nil))
cli-config/update-config! (fn [config updates]
(swap! update-calls conj [config updates])

View File

@@ -19,7 +19,7 @@
:name "TagOne"}]
(-> (p/with-redefs [cli-server/ensure-server! (fn [config _repo]
(p/resolved (assoc config :base-url "http://example")))
transport/invoke (fn [_ method _ args]
transport/invoke (fn [_ method args]
(case method
:thread-api/q
(let [[_ [query _]] args
@@ -97,7 +97,7 @@
(swap! add-actions* conj add-action)
(p/resolved {:status :ok
:data {:result [101]}}))
transport/invoke (fn [_ method _ args]
transport/invoke (fn [_ method args]
(case method
:thread-api/pull
(let [[_ _ lookup] args]
@@ -146,7 +146,7 @@
update-command/execute-update (fn [update-action _]
(swap! update-calls* conj update-action)
(p/resolved {:status :ok :data {:result nil}}))
transport/invoke (fn [_ method _ args]
transport/invoke (fn [_ method args]
(case method
:thread-api/pull
(let [[_ _ lookup] args]
@@ -178,7 +178,7 @@
:id 42}]
(-> (p/with-redefs [cli-server/ensure-server! (fn [config _repo]
(p/resolved (assoc config :base-url "http://example")))
transport/invoke (fn [_ method _ args]
transport/invoke (fn [_ method args]
(case method
:thread-api/pull
(let [[_ _ lookup] args]
@@ -213,7 +213,7 @@
:pos "last-child"}]
(-> (p/with-redefs [cli-server/ensure-server! (fn [config _repo]
(p/resolved (assoc config :base-url "http://example")))
transport/invoke (fn [_ method _ args]
transport/invoke (fn [_ method args]
(case method
;; resolve-tags queries for the tag by name
:thread-api/q
@@ -323,7 +323,7 @@
:status-input "invalid-status"}]
(-> (p/with-redefs [cli-server/ensure-server! (fn [config _repo]
(p/resolved (assoc config :base-url "http://example")))
transport/invoke (fn [_ method _ _]
transport/invoke (fn [_ method _]
(swap! calls* conj method)
(case method
:thread-api/q
@@ -362,7 +362,7 @@
:deadline deadline-ms}]
(-> (p/with-redefs [cli-server/ensure-server! (fn [config _repo]
(p/resolved (assoc config :base-url "http://example")))
transport/invoke (fn [_ method _ args]
transport/invoke (fn [_ method args]
(case method
:thread-api/q
(let [[_ [_query input]] args]
@@ -430,7 +430,7 @@
:logseq.property/deadline deadline-ms}}]
(-> (p/with-redefs [cli-server/ensure-server! (fn [config _repo]
(p/resolved (assoc config :base-url "http://example")))
transport/invoke (fn [_ method _ args]
transport/invoke (fn [_ method args]
(case method
:thread-api/q
(let [[_ [_query input]] args]
@@ -495,7 +495,7 @@
:logseq.property/deadline]}]
(-> (p/with-redefs [cli-server/ensure-server! (fn [config _repo]
(p/resolved (assoc config :base-url "http://example")))
transport/invoke (fn [_ method _ args]
transport/invoke (fn [_ method args]
(case method
:thread-api/q
(let [[_ [_query input]] args]
@@ -558,7 +558,7 @@
:priority :logseq.property/priority.high}]
(-> (p/with-redefs [cli-server/ensure-server! (fn [config _repo]
(p/resolved (assoc config :base-url "http://example")))
transport/invoke (fn [_ method _ args]
transport/invoke (fn [_ method args]
(case method
:thread-api/q
(p/resolved [:logseq.property/status.todo
@@ -616,7 +616,7 @@
(p/resolved (assoc config :base-url "http://example")))
add-command/resolve-tags (fn [_ _ _]
(p/resolved [{:db/id 100}]))
add-command/resolve-properties (fn [_ _ _ _]
add-command/resolve-properties (fn [_ _ _]
(p/rejected (ex-info "property not found"
{:code :property-not-found
:property :missing-prop})))
@@ -652,11 +652,11 @@
(if (seq tags)
(p/resolved [{:db/id 100}])
(p/resolved nil)))
add-command/resolve-properties (fn [_ _ _ _]
add-command/resolve-properties (fn [_ _ _]
(p/rejected (ex-info "property not found"
{:code :property-not-found
:property :missing-prop})))
transport/invoke (fn [_ method _ _]
transport/invoke (fn [_ method _]
(when (= :thread-api/apply-outliner-ops method)
(reset! mutation-called?* true))
(throw (ex-info "unexpected invoke"
@@ -685,7 +685,7 @@
:priority :logseq.property/priority.high}]
(-> (p/with-redefs [cli-server/ensure-server! (fn [config _repo]
(p/resolved (assoc config :base-url "http://example")))
transport/invoke (fn [_ method _ _]
transport/invoke (fn [_ method _]
(swap! calls* conj method)
(case method
:thread-api/q

View File

@@ -956,7 +956,7 @@
(async done
(let [selectors (atom [])]
(-> (p/with-redefs [cli-server/ensure-server! (fn [config _] config)
transport/invoke (fn [_ method _ args]
transport/invoke (fn [_ method args]
(case method
:thread-api/pull (let [[_ selector _] args]
(swap! selectors conj selector)
@@ -1003,7 +1003,7 @@
(async done
(let [method-calls (atom [])]
(-> (p/with-redefs [cli-server/ensure-server! (fn [config _] config)
transport/invoke (fn [_ method _ _]
transport/invoke (fn [_ method _]
(swap! method-calls conj method)
(case method
:thread-api/pull (p/resolved {:db/id 1
@@ -1027,7 +1027,7 @@
(async done
(let [method-calls (atom [])]
(-> (p/with-redefs [cli-server/ensure-server! (fn [config _] config)
transport/invoke (fn [_ method _ _]
transport/invoke (fn [_ method _]
(swap! method-calls conj method)
(case method
:thread-api/pull (p/resolved {:db/id 1
@@ -1050,7 +1050,7 @@
(deftest test-show-id-only-entity-is-not-found
(async done
(-> (p/with-redefs [cli-server/ensure-server! (fn [config _] config)
transport/invoke (fn [_ method _ _]
transport/invoke (fn [_ method _]
(case method
:thread-api/pull (p/resolved {:db/id 212})
:thread-api/q (p/resolved [])
@@ -1355,7 +1355,7 @@
(deftest test-list-execute-default-sort-updated-at
(async done
(-> (p/with-redefs [cli-server/ensure-server! (fn [_ _] {:base-url "http://example"})
transport/invoke (fn [_ method _ _]
transport/invoke (fn [_ method _]
(case method
:thread-api/cli-list-pages [{:db/id 11 :block/title "Page C" :block/updated-at 30}
{:db/id 7 :block/title "Page B" :block/updated-at 10}
@@ -1385,7 +1385,7 @@
(deftest test-list-execute-default-limit-returns-newest-records
(async done
(-> (p/with-redefs [cli-server/ensure-server! (fn [_ _] {:base-url "http://example"})
transport/invoke (fn [_ method _ _]
transport/invoke (fn [_ method _]
(case method
:thread-api/cli-list-pages (mapv (fn [id]
{:db/id id
@@ -1402,7 +1402,7 @@
(deftest test-list-execute-default-sort-respects-order-and-explicit-sort
(async done
(-> (p/with-redefs [cli-server/ensure-server! (fn [_ _] {:base-url "http://example"})
transport/invoke (fn [_ method _ _]
transport/invoke (fn [_ method _]
(case method
:thread-api/cli-list-pages [{:db/id 3 :block/title "Beta" :block/updated-at 20}
{:db/id 2 :block/title "Gamma" :block/updated-at 5}
@@ -1421,7 +1421,7 @@
(deftest test-list-property-execute-supports-cardinality-sort-and-fields
(async done
(-> (p/with-redefs [cli-server/ensure-server! (fn [_ _] {:base-url "http://example"})
transport/invoke (fn [_ method _ _]
transport/invoke (fn [_ method _]
(case method
:thread-api/cli-list-properties [{:db/id 30
:block/title "Gamma"
@@ -1452,7 +1452,7 @@
(async done
(let [calls* (atom [])]
(-> (p/with-redefs [cli-server/ensure-server! (fn [_ _] {:base-url "http://example"})
transport/invoke (fn [_ method _ args]
transport/invoke (fn [_ method args]
(swap! calls* conj {:method method :args args})
(case method
:thread-api/pull
@@ -1487,7 +1487,7 @@
(let [list-calls* (atom [])
upsert-calls* (atom [])]
(-> (p/with-redefs [cli-server/ensure-server! (fn [_ _] {:base-url "http://example"})
transport/invoke (fn [_ method _ args]
transport/invoke (fn [_ method args]
(let [repo (first args)]
(cond
(= method :thread-api/q)
@@ -3066,7 +3066,7 @@
:name "Quote"}]
(-> (p/with-redefs [cli-server/list-graphs (fn [_] ["demo"])
cli-server/ensure-server! (fn [_ _] {:base-url "http://example"})
transport/invoke (fn [_ method _ args]
transport/invoke (fn [_ method args]
(case method
:thread-api/q (if @created?*
[{:db/id 4242
@@ -3096,7 +3096,7 @@
:name "Home"}]
(-> (p/with-redefs [cli-server/list-graphs (fn [_] ["demo"])
cli-server/ensure-server! (fn [_ _] {:base-url "http://example"})
transport/invoke (fn [_ method _ _args]
transport/invoke (fn [_ method _args]
(case method
;; pull-tag-by-name finds no tag (only a page exists)
:thread-api/q (if @created?*
@@ -3124,7 +3124,7 @@
:name "Quote"}]
(-> (p/with-redefs [cli-server/list-graphs (fn [_] ["demo"])
cli-server/ensure-server! (fn [_ _] {:base-url "http://example"})
transport/invoke (fn [_ method _ args]
transport/invoke (fn [_ method args]
(case method
:thread-api/q [{:db/id 4242
:block/name "quote"
@@ -3153,7 +3153,7 @@
:db/cardinality :db.cardinality/many}}]
(-> (p/with-redefs [cli-server/list-graphs (fn [_] ["demo"])
cli-server/ensure-server! (fn [_ _] {:base-url "http://example"})
transport/invoke (fn [_ method _ args]
transport/invoke (fn [_ method args]
(case method
:thread-api/q (if @created?*
[{:db/id 654
@@ -3187,7 +3187,7 @@
:id 4242}]
(-> (p/with-redefs [cli-server/list-graphs (fn [_] ["demo"])
cli-server/ensure-server! (fn [_ _] {:base-url "http://example"})
transport/invoke (fn [_ method _ args]
transport/invoke (fn [_ method args]
(case method
:thread-api/pull (let [[_ _ lookup] args]
(if (= lookup 4242)
@@ -3220,7 +3220,7 @@
tag-uuid (uuid "00000000-0000-0000-0000-000000004242")]
(-> (p/with-redefs [cli-server/list-graphs (fn [_] ["demo"])
cli-server/ensure-server! (fn [_ _] {:base-url "http://example"})
transport/invoke (fn [_ method _ args]
transport/invoke (fn [_ method args]
(case method
:thread-api/pull (let [[_ _ lookup] args]
(if (= lookup 4242)
@@ -3257,7 +3257,7 @@
:name " #QUOTE "}]
(-> (p/with-redefs [cli-server/list-graphs (fn [_] ["demo"])
cli-server/ensure-server! (fn [_ _] {:base-url "http://example"})
transport/invoke (fn [_ method _ args]
transport/invoke (fn [_ method args]
(case method
:thread-api/pull (let [[_ _ lookup] args]
(if (= lookup 4242)
@@ -3294,7 +3294,7 @@
:name "Project Renamed"}]
(-> (p/with-redefs [cli-server/list-graphs (fn [_] ["demo"])
cli-server/ensure-server! (fn [_ _] {:base-url "http://example"})
transport/invoke (fn [_ method _ args]
transport/invoke (fn [_ method args]
(case method
:thread-api/pull (let [[_ _ lookup] args]
(if (= lookup 4242)
@@ -3328,7 +3328,7 @@
:name "Project Renamed"}]
(-> (p/with-redefs [cli-server/list-graphs (fn [_] ["demo"])
cli-server/ensure-server! (fn [_ _] {:base-url "http://example"})
transport/invoke (fn [_ method _ args]
transport/invoke (fn [_ method args]
(case method
:thread-api/pull (let [[_ _ lookup] args]
(if (= lookup 4242)
@@ -3360,7 +3360,7 @@
(async done
(-> (p/with-redefs [cli-server/list-graphs (fn [_] ["demo"])
cli-server/ensure-server! (fn [_ _] {:base-url "http://example"})
transport/invoke (fn [_ method _ args]
transport/invoke (fn [_ method args]
(case method
:thread-api/pull (let [[_ _ lookup] args]
(case lookup
@@ -3418,7 +3418,7 @@
(p/resolved (cond (= tags [:tag/new]) [{:db/id 101}]
:else nil)))
add-command/resolve-properties (fn [_ _ properties & _] (p/resolved properties))
transport/invoke (fn [_ method _ args]
transport/invoke (fn [_ method args]
(case method
:thread-api/pull (let [[_ _ lookup] args]
(swap! property-lookups* conj lookup)
@@ -3460,7 +3460,7 @@
:else nil)))
add-command/resolve-properties (fn [_ _ properties & _] (p/resolved properties))
add-command/resolve-property-identifiers (fn [_ _ properties & _] (p/resolved properties))
transport/invoke (fn [_ method _ args]
transport/invoke (fn [_ method args]
(case method
:thread-api/q (let [[_ [_query input]] args]
(if (= input "home")
@@ -3507,7 +3507,7 @@
add-command/resolve-tags (fn [_ _ _] (p/resolved nil))
add-command/resolve-properties (fn [_ _ properties & _] (p/resolved properties))
add-command/resolve-property-identifiers (fn [_ _ properties & _] (p/resolved properties))
transport/invoke (fn [_ method _ args]
transport/invoke (fn [_ method args]
(case method
:thread-api/q (let [[_ [_query input]] args]
(if (= input "home")
@@ -3551,7 +3551,7 @@
add-command/resolve-tags (fn [_ _ _] (p/resolved nil))
add-command/resolve-properties (fn [_ _ _ & _] (p/resolved nil))
add-command/resolve-property-identifiers (fn [_ _ _ & _] (p/resolved nil))
transport/invoke (fn [_ method _ _]
transport/invoke (fn [_ method _]
(case method
:thread-api/q [{:db/id 21
:block/name "c1"
@@ -3578,7 +3578,7 @@
(let [action {:type :upsert-page :mode :update :repo "demo" :id 50}]
(-> (p/with-redefs [cli-server/list-graphs (fn [_] ["demo"])
cli-server/ensure-server! (fn [_ _] {:base-url "http://example"})
transport/invoke (fn [_ method _ _]
transport/invoke (fn [_ method _]
(case method
:thread-api/pull {:db/id 50
:block/name "home"
@@ -3601,7 +3601,7 @@
(async done
(-> (p/with-redefs [cli-server/list-graphs (fn [_] ["demo"])
cli-server/ensure-server! (fn [_ _] {:base-url "http://example"})
transport/invoke (fn [_ method _ _]
transport/invoke (fn [_ method _]
(case method
:thread-api/pull {:db/id 50
:block/uuid (uuid "00000000-0000-0000-0000-0000000000ee")
@@ -3643,7 +3643,7 @@
add-command/resolve-tags (fn [_ _ _] (p/resolved nil))
add-command/resolve-properties (fn [_ _ properties & _] (p/resolved properties))
add-command/resolve-property-identifiers (fn [_ _ properties & _] (p/resolved properties))
transport/invoke (fn [_ method _ args]
transport/invoke (fn [_ method args]
(case method
:thread-api/pull (let [[_ _ lookup] args]
(cond
@@ -3664,7 +3664,7 @@
(let [ops* (atom [])]
(-> (p/with-redefs [cli-server/list-graphs (fn [_] ["demo"])
cli-server/ensure-server! (fn [_ _] {:base-url "http://example"})
transport/invoke (fn [_ method _ args]
transport/invoke (fn [_ method args]
(case method
:thread-api/cli-list-tags [{:db/id 1 :block/title "Quote"}]
:thread-api/cli-list-properties [{:db/id 2 :block/title "owner"}]
@@ -3694,7 +3694,7 @@
(async done
(-> (p/with-redefs [cli-server/list-graphs (fn [_] ["demo"])
cli-server/ensure-server! (fn [_ _] {:base-url "http://example"})
transport/invoke (fn [_ method _ _]
transport/invoke (fn [_ method _]
(case method
:thread-api/q [{:db/id 11
:block/title "Recycled"
@@ -3715,7 +3715,7 @@
page-uuid (uuid "00000000-0000-0000-0000-00000000abcd")]
(-> (p/with-redefs [cli-server/list-graphs (fn [_] ["demo"])
cli-server/ensure-server! (fn [_ _] {:base-url "http://example"})
transport/invoke (fn [_ method _ args]
transport/invoke (fn [_ method args]
(case method
:thread-api/q (let [[_ [_query input]] args]
(if (= input "home")
@@ -3743,7 +3743,7 @@
(async done
(-> (p/with-redefs [cli-server/list-graphs (fn [_] ["demo"])
cli-server/ensure-server! (fn [_ _] {:base-url "http://example"})
transport/invoke (fn [_ method _ _]
transport/invoke (fn [_ method _]
(case method
:thread-api/q [{:db/id 21
:block/name "c1"
@@ -3771,7 +3771,7 @@
page-uuid (uuid "00000000-0000-0000-0000-00000000abce")]
(-> (p/with-redefs [cli-server/list-graphs (fn [_] ["demo"])
cli-server/ensure-server! (fn [_ _] {:base-url "http://example"})
transport/invoke (fn [_ method _ args]
transport/invoke (fn [_ method args]
(case method
:thread-api/pull (let [[_ _ lookup] args]
(if (= lookup 10)
@@ -3796,7 +3796,7 @@
(async done
(-> (p/with-redefs [cli-server/list-graphs (fn [_] ["demo"])
cli-server/ensure-server! (fn [_ _] {:base-url "http://example"})
transport/invoke (fn [_ method _ _]
transport/invoke (fn [_ method _]
(case method
:thread-api/cli-list-tags [{:db/id 1 :block/title "Quote"}
{:db/id 2 :block/title "QUOTE"}]
@@ -3827,7 +3827,7 @@
:else nil)))
add-command/resolve-properties (fn [_ _ properties & _] (p/resolved properties))
add-command/resolve-property-identifiers (fn [_ _ properties & _] (p/resolved properties))
transport/invoke (fn [_ method _ args]
transport/invoke (fn [_ method args]
(swap! calls* conj {:method method :args args})
(case method
:thread-api/pull (let [[_ _ lookup] args]
@@ -3871,7 +3871,7 @@
(async done
(-> (p/with-redefs [cli-server/list-graphs (fn [_] ["demo"])
cli-server/ensure-server! (fn [_ _] {:base-url "http://example"})
transport/invoke (fn [_ method _ [repo [query-text query-input]]]
transport/invoke (fn [_ method [repo [query-text query-input]]]
(is (= :thread-api/q method))
(is (= "logseq_db_demo" repo))
(is (= "quote" query-input))
@@ -3982,7 +3982,7 @@
cli-server/restart-server! (fn [_ _] (p/resolved {:ok? true}))
cli-server/ensure-server! (fn [config _] (assoc config :base-url "http://example"))
transport/read-input (fn [_] {:page "Test"})
transport/invoke (fn [_ _ _ _] {:ok true})]
transport/invoke (fn [_ _ _] {:ok true})]
(p/let [result (commands/execute action {})]
(is (= :ok (:status result))
"edn import into existing graph should succeed")))
@@ -4032,8 +4032,8 @@
(-> (p/with-redefs [cli-server/list-graphs (fn [_] ["demo"])
cli-server/ensure-server! (fn [config _]
(assoc config :base-url "http://127.0.0.1:9999"))
transport/invoke (fn [_ method direct-pass? args]
(swap! invoke-calls conj [method direct-pass? args])
transport/invoke (fn [_ method args]
(swap! invoke-calls conj [method args])
(if (= method :thread-api/export-db-base64)
"c3FsaXRl"
{:exported true}))
@@ -4062,11 +4062,11 @@
(is (= "/tmp/export.edn" (get-in edn-result [:context :file])))
(is (= "sqlite" (get-in sqlite-result [:context :export-type])))
(is (= "/tmp/export.sqlite" (get-in sqlite-result [:context :file])))
(is (= [[:thread-api/export-edn false ["logseq_db_demo" {:export-type :graph
(is (= [[:thread-api/export-edn ["logseq_db_demo" {:export-type :graph
:graph-options {:include-timestamps? true
:exclude-built-in-pages? true
:exclude-namespaces #{:user :project}}}]]
[:thread-api/backup-db-sqlite true ["logseq_db_demo" "/tmp/export.sqlite"]]]
[:thread-api/backup-db-sqlite ["logseq_db_demo" "/tmp/export.sqlite"]]]
@invoke-calls))
(is (= 1 (count @write-calls)))
(is (= {:format :edn
@@ -4091,7 +4091,7 @@
(if (= format :edn)
{:page "Import Page"}
(js/Buffer.from "sqlite" "utf8")))
transport/invoke (fn [_ method _ args]
transport/invoke (fn [_ method args]
(swap! invoke-calls conj [method args])
{:ok true})]
(p/let [edn-result (commands/execute {:type :graph-import :repo "logseq_db_demo" :graph "demo" :import-type "edn" :input "/tmp/import.edn" :allow-missing-graph true} {})
@@ -4211,7 +4211,7 @@
"test-repo" config)]
(is (true? (:ok? action-result)))
(-> (p/with-redefs [cli-server/ensure-server! (fn [config _] config)
transport/invoke (fn [_ _method _ args]
transport/invoke (fn [_ _method args]
(reset! captured-args (second args))
(p/resolved []))]
(query-command/execute-query (:action action-result) config))

View File

@@ -166,8 +166,8 @@
["demo"])
cli-server/ensure-server! (fn [config _repo]
(p/resolved (assoc config :base-url "http://example")))
transport/invoke (fn [_ method direct-pass? args]
(swap! invoke-calls conj [method direct-pass? args])
transport/invoke (fn [_ method args]
(swap! invoke-calls conj [method args])
(case method
:thread-api/set-db-sync-config
(p/resolved nil)
@@ -180,7 +180,7 @@
(is (= 0 (:exit-code result)))
(is (= "ok" (:status payload)))
(is (= :thread-api/sync-app-state (ffirst @invoke-calls)))
(is (= "fresh-token" (get-in (nth @invoke-calls 0) [2 0 :auth/id-token])))
(is (= "fresh-token" (get-in (nth @invoke-calls 0) [1 0 :auth/id-token])))
(is (= "fresh-token" (:id-token stored)))
(is (= "fresh-access-token" (:access-token stored)))))]
(-> promise
@@ -210,7 +210,7 @@
:refresh-token "refresh-token"}))
cli-server/ensure-server! (fn [config _repo]
(p/resolved (assoc config :base-url "http://example")))
transport/invoke (fn [_ method _direct-pass? args]
transport/invoke (fn [_ method args]
(swap! invoke-calls conj [method args])
(case method
:thread-api/set-db-sync-config
@@ -280,8 +280,8 @@
_ (p/with-redefs [cli-auth/resolve-auth! (fn [_config]
(p/resolved {:id-token "runtime-token"
:refresh-token "refresh-token"}))
transport/invoke (fn [_ method direct-pass? args]
(swap! invoke-calls conj [method direct-pass? args])
transport/invoke (fn [_ method args]
(swap! invoke-calls conj [method args])
(case method
:thread-api/set-db-sync-config
(p/resolved nil)
@@ -359,7 +359,7 @@
(p/resolved {:id-token "runtime-token"}))
cli-server/ensure-server! (fn [config _repo]
(p/resolved (assoc config :base-url "http://example")))
transport/invoke (fn [_ method _direct-pass? args]
transport/invoke (fn [_ method args]
(swap! invoke-calls conj [method args])
(case method
:thread-api/set-db-sync-config
@@ -403,7 +403,7 @@
(p/resolved {:id-token "runtime-token"}))
cli-server/ensure-server! (fn [config _repo]
(p/resolved (assoc config :base-url "http://example")))
transport/invoke (fn [_ method _direct-pass? args]
transport/invoke (fn [_ method args]
(swap! invoke-calls conj [method args])
(case method
:thread-api/set-db-sync-config

View File

@@ -218,11 +218,11 @@
payload (js/JSON.parse (.toString buf "utf8"))]
(reset! received (js->clj payload :keywordize-keys true))
(.writeHead res 200 #js {"Content-Type" "application/json"})
(.end res (js/JSON.stringify #js {:result "ok"}))))))))]
(p/let [result (transport/invoke {:base-url url} :thread-api/pull true ["repo" [:block/title]])]
(.end res (js/JSON.stringify #js {:resultTransit (ldb/write-transit-str "ok")}))))))))]
(p/let [result (transport/invoke {:base-url url} :thread-api/pull ["repo" [:block/title]])]
(is (= "ok" result))
(is (= "thread-api/pull" (:method @received)))
(is (= true (:directPass @received)))
(is (string? (:argsTransit @received)))
(p/let [_ (stop!)] true)))
(p/then (fn [_] (done)))
(p/catch (fn [e]
@@ -231,13 +231,12 @@
(deftest test-invoke-requires-explicit-base-url-and-method
(testing "invoke fails fast when base-url is missing"
(let [message (capture-throw-message #(transport/invoke {} :thread-api/q true []))]
(let [message (capture-throw-message #(transport/invoke {} :thread-api/q []))]
(is (re-find #"base-url is required" (or message "")))))
(testing "invoke fails fast when method is missing"
(let [message (capture-throw-message #(transport/invoke {:base-url "http://127.0.0.1:8123"}
nil
true
[]))]
(is (re-find #"invoke method is required" (or message ""))))))
@@ -258,11 +257,10 @@
(let [headers (.-headers req)]
(reset! auth-header (aget headers "authorization")))
(.writeHead res 200 #js {"Content-Type" "application/json"})
(.end res (js/JSON.stringify #js {:result "ok"}))))]
(.end res (js/JSON.stringify #js {:resultTransit (ldb/write-transit-str "ok")}))))]
(p/let [result (transport/invoke {:base-url url
:auth-token "secret"}
:thread-api/pull
true
["repo" [:block/title]])]
(is (= "ok" result))
(is (nil? @auth-header))
@@ -278,16 +276,14 @@
(-> (p/let [{:keys [url stop!]} (start-server
(fn [_req ^js res]
(.writeHead res 200 #js {"Content-Type" "application/json"})
(.end res (js/JSON.stringify #js {:result "ok"}))))
(.end res (js/JSON.stringify #js {:resultTransit (ldb/write-transit-str "ok")}))))
_ (transport/invoke {:base-url url
:profile-session session}
:thread-api/q
true
["repo" [:block/title]])
_ (transport/invoke {:base-url url
:profile-session session}
:thread-api/q
true
["repo" [:block/title]])
report (profile/report session {:command "query"
:status :ok})