remove tx api, use tx/batch instead

This commit is contained in:
Tienson Qin
2026-01-09 20:49:19 +08:00
parent a217cdede6
commit cb032ea148
3 changed files with 1 additions and 32 deletions

View File

@@ -291,14 +291,6 @@
{:type "tx/ok"
:t new-t}))))
(defn- handle-tx! [^js self sender tx-data t-before]
(let [current-t (t-now self)]
(if (and (number? t-before) (not= t-before current-t))
{:type "tx/reject"
:reason "stale"
:t current-t}
(apply-tx! self sender tx-data))))
(defn- handle-tx-batch! [^js self sender txs t-before]
(let [current-t (t-now self)]
(if (and (number? t-before) (not= t-before current-t))
@@ -340,13 +332,6 @@
;; "snapshot"
;; (send! ws (snapshot-response self))
"tx"
(let [tx-data (protocol/transit->tx (:tx message))
t-before (parse-int (:t_before message))]
(if (sequential? tx-data)
(send! ws (handle-tx! self ws tx-data t-before))
(send! ws {:type "tx/reject" :reason "invalid tx"})))
"tx/batch"
(let [txs (:txs message)
t-before (parse-int (:t_before message))]
@@ -424,17 +409,6 @@
(storage/init-schema! (.-sql self))
(common/json-response {:ok true}))
(and (= method "POST") (= path "/tx"))
(.then (common/read-json request)
(fn [result]
(if (nil? result)
(common/bad-request "missing body")
(let [tx-data (protocol/transit->tx (aget result "tx"))
t-before (parse-int (aget result "t_before"))]
(if (sequential? tx-data)
(common/json-response (handle-tx! self nil tx-data t-before))
(common/bad-request "invalid tx"))))))
(and (= method "POST") (= path "/tx/batch"))
(.then (common/read-json request)
(fn [result]

View File

@@ -38,7 +38,7 @@ Client -> Server:
Server -> Client:
- `{ "type": "hello", "t": 1 }`
- `{ "type": "tx/ok", "t": 2 }`
- `{ "type": "tx/batch/ok", "t": 2 }`
- `{ "type": "tx/reject", "reason": "cycle", "server_values": "<transit>" }`
- `{ "type": "pull/ok", "t": 2, "txs": [{"t": 1, "tx": "<transit>"}] }`
- `{ "type": "snapshot/ok", "t": 2, "datoms": "<transit>" }`

View File

@@ -179,11 +179,6 @@
(enqueue-asset-sync! repo client)
(enqueue-asset-initial-download! repo client)
(flush-pending! repo client))
"tx/ok" (do
(update-server-t! client (:t message))
(remove-pending-txs! repo @(:inflight client))
(reset! (:inflight client) [])
(flush-pending! repo client))
"tx/batch/ok" (do
(update-server-t! client (:t message))
(remove-pending-txs! repo @(:inflight client))