From 17ae997013f58ca851ab62cefbc062cd12ff5569 Mon Sep 17 00:00:00 2001 From: rcmerci Date: Sun, 3 May 2026 20:00:41 +0800 Subject: [PATCH] enhance(db-worker): remove direct-pass in thread-api calling --- src/electron/electron/db.cljs | 1 - src/main/frontend/common/thread_api.cljc | 9 +- src/main/frontend/db/async.cljs | 6 +- .../frontend/handler/common/developer.cljs | 22 +- src/main/frontend/persist_db.cljs | 2 +- src/main/frontend/persist_db/browser.cljs | 18 +- src/main/frontend/persist_db/remote.cljs | 39 ++-- src/main/frontend/state.cljs | 18 +- src/main/frontend/util.cljc | 17 ++ src/main/frontend/worker/db_core.cljs | 36 +-- src/main/frontend/worker/db_worker.cljs | 11 +- src/main/frontend/worker/db_worker_node.cljs | 42 ++-- src/main/frontend/worker/platform.cljs | 6 - src/main/frontend/worker/state.cljs | 2 +- src/main/logseq/cli/command/add.cljs | 26 +-- src/main/logseq/cli/command/debug.cljs | 2 +- src/main/logseq/cli/command/graph.cljs | 11 +- src/main/logseq/cli/command/list.cljs | 16 +- src/main/logseq/cli/command/query.cljs | 2 +- src/main/logseq/cli/command/remove.cljs | 16 +- src/main/logseq/cli/command/search.cljs | 2 +- src/main/logseq/cli/command/show.cljs | 30 +-- src/main/logseq/cli/command/sync.cljs | 28 +-- src/main/logseq/cli/command/update.cljs | 12 +- src/main/logseq/cli/command/upsert.cljs | 30 +-- src/main/logseq/cli/transport.cljs | 55 ++--- src/main/logseq/cli/uuid_refs.cljs | 2 +- src/test/frontend/persist_db/remote_test.cljs | 50 +++- src/test/frontend/persist_db_test.cljs | 49 ++-- src/test/frontend/worker/db_core_test.cljs | 132 ++++++----- src/test/frontend/worker/db_sync_test.cljs | 4 +- .../frontend/worker/db_worker_node_test.cljs | 73 +++--- src/test/frontend/worker/db_worker_test.cljs | 13 +- src/test/frontend/worker/node_sync_test.cljs | 2 +- .../frontend/worker/shared_service_test.cljs | 7 +- src/test/logseq/cli/command/add_test.cljs | 10 +- src/test/logseq/cli/command/debug_test.cljs | 4 +- src/test/logseq/cli/command/graph_test.cljs | 12 +- src/test/logseq/cli/command/list_test.cljs | 4 +- src/test/logseq/cli/command/remove_test.cljs | 8 +- src/test/logseq/cli/command/search_test.cljs | 8 +- src/test/logseq/cli/command/show_test.cljs | 8 +- src/test/logseq/cli/command/sync_test.cljs | 215 +++++++++--------- src/test/logseq/cli/command/upsert_test.cljs | 28 +-- src/test/logseq/cli/commands_test.cljs | 84 +++---- src/test/logseq/cli/integration_test.cljs | 16 +- src/test/logseq/cli/transport_test.cljs | 16 +- 47 files changed, 598 insertions(+), 606 deletions(-) diff --git a/src/electron/electron/db.cljs b/src/electron/electron/db.cljs index e5a118510a..5dfa4f480a 100644 --- a/src/electron/electron/db.cljs +++ b/src/electron/electron/db.cljs @@ -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 diff --git a/src/main/frontend/common/thread_api.cljc b/src/main/frontend/common/thread_api.cljc index 1fb109a206..525369a0e5 100644 --- a/src/main/frontend/common/thread_api.cljc +++ b/src/main/frontend/common/thread_api.cljc @@ -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) {})))))) diff --git a/src/main/frontend/db/async.cljs b/src/main/frontend/db/async.cljs index 1502028376..c4d8536c8a 100644 --- a/src/main/frontend/db/async.cljs +++ b/src/main/frontend/db/async.cljs @@ -61,9 +61,9 @@ (defn- result-transit-str ldb/read-transit-str))) (defonce ^:private *get-blocks-batch-enabled? (atom true)) diff --git a/src/main/frontend/handler/common/developer.cljs b/src/main/frontend/handler/common/developer.cljs index 435e119d52..5708bfb639 100644 --- a/src/main/frontend/handler/common/developer.cljs +++ b/src/main/frontend/handler/common/developer.cljs @@ -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- (state/ (state/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") diff --git a/src/main/frontend/persist_db.cljs b/src/main/frontend/persist_db.cljs index cbc9e42634..0d8a395ce3 100644 --- a/src/main/frontend/persist_db.cljs +++ b/src/main/frontend/persist_db.cljs @@ -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))) _ ( (p/let [data (state/ (p/let [base64 (state/ base64 util/base64string-to-unit8array)] (when data (if (:return-data? opts) data @@ -230,8 +226,8 @@ ( - (p/let [result-str (state/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 ( base64 util/base64string-to-unit8array))) ( - (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) diff --git a/src/main/frontend/state.cljs b/src/main/frontend/state.cljs index 8b9cf09da3..c6778612b7 100644 --- a/src/main/frontend/state.cljs +++ b/src/main/frontend/state.cljs @@ -64,24 +64,14 @@ (->> (m/watch *db-worker) (m/eduction (map some?)))) -(defn- (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)] - ( ( ( (p/let [body (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 ( (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}}))) diff --git a/src/main/logseq/cli/command/debug.cljs b/src/main/logseq/cli/command/debug.cljs index d6f3d47997..8f4bbe13e3 100644 --- a/src/main/logseq/cli/command/debug.cljs +++ b/src/main/logseq/cli/command/debug.cljs @@ -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 diff --git a/src/main/logseq/cli/command/graph.cljs b/src/main/logseq/cli/command/graph.cljs index bef107d304..2a3f5751a7 100644 --- a/src/main/logseq/cli/command/graph.cljs +++ b/src/main/logseq/cli/command/graph.cljs @@ -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? diff --git a/src/main/logseq/cli/command/list.cljs b/src/main/logseq/cli/command/list.cljs index db0eca0f1f..60823da2f6 100644 --- a/src/main/logseq/cli/command/list.cljs +++ b/src/main/logseq/cli/command/list.cljs @@ -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") diff --git a/src/main/logseq/cli/command/query.cljs b/src/main/logseq/cli/command/query.cljs index a7c69ab060..82f2e65d8d 100644 --- a/src/main/logseq/cli/command/query.cljs +++ b/src/main/logseq/cli/command/query.cljs @@ -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}})))) diff --git a/src/main/logseq/cli/command/remove.cljs b/src/main/logseq/cli/command/remove.cljs index 880d4ba86e..0a9fd7edf0 100644 --- a/src/main/logseq/cli/command/remove.cljs +++ b/src/main/logseq/cli/command/remove.cljs @@ -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) diff --git a/src/main/logseq/cli/command/search.cljs b/src/main/logseq/cli/command/search.cljs index 947a3e3ee4..510bb2c080 100644 --- a/src/main/logseq/cli/command/search.cljs +++ b/src/main/logseq/cli/command/search.cljs @@ -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 diff --git a/src/main/logseq/cli/command/show.cljs b/src/main/logseq/cli/command/show.cljs index a55338b36d..cad38324ac 100644 --- a/src/main/logseq/cli/command/show.cljs +++ b/src/main/logseq/cli/command/show.cljs @@ -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]} diff --git a/src/main/logseq/cli/command/sync.cljs b/src/main/logseq/cli/command/sync.cljs index ee76a3a0cb..44ad966d15 100644 --- a/src/main/logseq/cli/command/sync.cljs +++ b/src/main/logseq/cli/command/sync.cljs @@ -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) _ ( graphs first core/resolve-repo))) @@ -492,7 +492,7 @@ (p/rejected (ex-info "graph name is required" {:code :missing-graph}))) _ ( (p/let [cfg (cli-server/ensure-server! config (:repo action)) _ ( (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)) _ ( {} (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) diff --git a/src/main/logseq/cli/transport.cljs b/src/main/logseq/cli/transport.cljs index fa7167729c..50adbd902c 100644 --- a/src/main/logseq/cli/transport.cljs +++ b/src/main/logseq/cli/transport.cljs @@ -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]}] diff --git a/src/main/logseq/cli/uuid_refs.cljs b/src/main/logseq/cli/uuid_refs.cljs index ba054fe747..e4b52cbf6f 100644 --- a/src/main/logseq/cli/uuid_refs.cljs +++ b/src/main/logseq/cli/uuid_refs.cljs @@ -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))] diff --git a/src/test/frontend/persist_db/remote_test.cljs b/src/test/frontend/persist_db/remote_test.cljs index 20eb48c9cd..58b6058c7c 100644 --- a/src/test/frontend/persist_db/remote_test.cljs +++ b/src/test/frontend/persist_db/remote_test.cljs @@ -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/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/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/ (protocol/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/ (protocol/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/ (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 diff --git a/src/test/frontend/worker/db_sync_test.cljs b/src/test/frontend/worker/db_sync_test.cljs index e1f86aa7ae..7a191e61a5 100644 --- a/src/test/frontend/worker/db_sync_test.cljs +++ b/src/test/frontend/worker/db_sync_test.cljs @@ -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"}))) diff --git a/src/test/frontend/worker/db_worker_node_test.cljs b/src/test/frontend/worker/db_worker_node_test.cljs index 621e7beed4..dfcb08ec42 100644 --- a/src/test/frontend/worker/db_worker_node_test.cljs +++ b/src/test/frontend/worker/db_worker_node_test.cljs @@ -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) diff --git a/src/test/frontend/worker/db_worker_test.cljs b/src/test/frontend/worker/db_worker_test.cljs index c71ef78e23..e5e1de366d 100644 --- a/src/test/frontend/worker/db_worker_test.cljs +++ b/src/test/frontend/worker/db_worker_test.cljs @@ -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)) diff --git a/src/test/frontend/worker/node_sync_test.cljs b/src/test/frontend/worker/node_sync_test.cljs index b781441a22..79c179fb4a 100644 --- a/src/test/frontend/worker/node_sync_test.cljs +++ b/src/test/frontend/worker/node_sync_test.cljs @@ -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"}))) diff --git a/src/test/frontend/worker/shared_service_test.cljs b/src/test/frontend/worker/shared_service_test.cljs index 0b74b9117e..3636b24fec 100644 --- a/src/test/frontend/worker/shared_service_test.cljs +++ b/src/test/frontend/worker/shared_service_test.cljs @@ -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)))) diff --git a/src/test/logseq/cli/command/add_test.cljs b/src/test/logseq/cli/command/add_test.cljs index af53b204d3..8f1af61f4b 100644 --- a/src/test/logseq/cli/command/add_test.cljs +++ b/src/test/logseq/cli/command/add_test.cljs @@ -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] diff --git a/src/test/logseq/cli/command/debug_test.cljs b/src/test/logseq/cli/command/debug_test.cljs index 6631b7a4ab..128a491054 100644 --- a/src/test/logseq/cli/command/debug_test.cljs +++ b/src/test/logseq/cli/command/debug_test.cljs @@ -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))) diff --git a/src/test/logseq/cli/command/graph_test.cljs b/src/test/logseq/cli/command/graph_test.cljs index 54d73dd406..601dd93679 100644 --- a/src/test/logseq/cli/command/graph_test.cljs +++ b/src/test/logseq/cli/command/graph_test.cljs @@ -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] diff --git a/src/test/logseq/cli/command/list_test.cljs b/src/test/logseq/cli/command/list_test.cljs index 445a15aecd..116a334e12 100644 --- a/src/test/logseq/cli/command/list_test.cljs +++ b/src/test/logseq/cli/command/list_test.cljs @@ -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 diff --git a/src/test/logseq/cli/command/remove_test.cljs b/src/test/logseq/cli/command/remove_test.cljs index 8aea7c6c14..fb6b6899a8 100644 --- a/src/test/logseq/cli/command/remove_test.cljs +++ b/src/test/logseq/cli/command/remove_test.cljs @@ -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) diff --git a/src/test/logseq/cli/command/search_test.cljs b/src/test/logseq/cli/command/search_test.cljs index 27cc066f25..78511f9c20 100644 --- a/src/test/logseq/cli/command/search_test.cljs +++ b/src/test/logseq/cli/command/search_test.cljs @@ -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} diff --git a/src/test/logseq/cli/command/show_test.cljs b/src/test/logseq/cli/command/show_test.cljs index bfe6cd47a2..0b076e85f7 100644 --- a/src/test/logseq/cli/command/show_test.cljs +++ b/src/test/logseq/cli/command/show_test.cljs @@ -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] diff --git a/src/test/logseq/cli/command/sync_test.cljs b/src/test/logseq/cli/command/sync_test.cljs index ead623fc16..c1043bcfbd 100644 --- a/src/test/logseq/cli/command/sync_test.cljs +++ b/src/test/logseq/cli/command/sync_test.cljs @@ -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]) diff --git a/src/test/logseq/cli/command/upsert_test.cljs b/src/test/logseq/cli/command/upsert_test.cljs index c33637aa30..d9c2fce593 100644 --- a/src/test/logseq/cli/command/upsert_test.cljs +++ b/src/test/logseq/cli/command/upsert_test.cljs @@ -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 diff --git a/src/test/logseq/cli/commands_test.cljs b/src/test/logseq/cli/commands_test.cljs index b933042379..25be7fec99 100644 --- a/src/test/logseq/cli/commands_test.cljs +++ b/src/test/logseq/cli/commands_test.cljs @@ -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)) diff --git a/src/test/logseq/cli/integration_test.cljs b/src/test/logseq/cli/integration_test.cljs index dfe42f88b0..d9fa4ed444 100644 --- a/src/test/logseq/cli/integration_test.cljs +++ b/src/test/logseq/cli/integration_test.cljs @@ -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 diff --git a/src/test/logseq/cli/transport_test.cljs b/src/test/logseq/cli/transport_test.cljs index 95e8a427e9..ea06d28ece 100644 --- a/src/test/logseq/cli/transport_test.cljs +++ b/src/test/logseq/cli/transport_test.cljs @@ -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})