99 [me.tonsky.persistent-sorted-set :as set]
1010 [me.tonsky.persistent-sorted-set.arrays :as arrays])
1111 #? (:clj (:import clojure.lang.IFn$OOL))
12- #? (:cljs (:require-macros [datascript.db :refer [case-tree combine-cmp declare+ defn+ defcomp defrecord-updatable int-compare validate-attr validate-val]]))
12+ #? (:cljs (:require-macros [datascript.db :refer [case-tree combine-cmp defn+ defcomp defrecord-updatable int-compare validate-attr validate-val]]))
1313 (:refer-clojure :exclude [seqable? #?(:clj update)]))
1414
1515#?(:clj (set! *warn-on-reflection* true ))
8080 'number (assoc meta :tag clojure.core$long)
8181 meta))))
8282
83- #?(:clj
84- (defmacro declare+
85- " Same idea as `declare`, but allows to declare type hints and arglists.
86- This allows CLJS to generate more efficient code when calling this fn
87- before it’s declared"
88- [name & arglists]
89- (let [name' (vary-meta name patch-tag (cljs-env? &env))
90- bodies (map #(list % `(throw (ex-info (str " Not implemented: (" ~name (clojure.string/join " " ~%)) {}))) arglists)]
91- `(defn ~name' ~@bodies))))
92-
9383#?(:clj
9484 (defmacro defn+
95- " Version of `defn` that works with `declare+`. CLJS really don’t like
96- :declared metadata on vars (generates less efficient code), but it
97- needs it to skip warnings. So we redefine first with ^:declared
98- and empty implementation, and then immediately redefine again without ^:declared.
99- This way both `declare+`-d and `defn+`-d versions have no ^:declared meta,
100- thus allowing CLJS to generate direct invocations and see type hints."
85+ " CLJS really don’t like :declared metadata on vars (generates less
86+ efficient code), but it needs it to skip warnings. So we redefine
87+ first with ^:declared and empty implementation, and then immediately
88+ redefine again without ^:declared. This way both `declare` and `defn+`
89+ versions have no ^:declared meta, thus allowing CLJS to generate direct
90+ invocations and see type hints."
10191 [name & rest]
10292 (let [name' (vary-meta name patch-tag (cljs-env? &env))
10393 arglists (if (vector? (first rest))
163153
164154; ; ----------------------------------------------------------------------------
165155
166- (declare+ ^number hash-datom [d])
156+ #?(:clj (declare hash-datom )
157+ :cljs (defn ^number hash-datom [d]))
167158
168- (declare+ ^boolean equiv-datom [d o])
159+ #?(:clj (declare equiv-datom )
160+ :cljs (defn ^boolean equiv-datom [d o]))
169161
170- (declare+ seq-datom [d])
162+ #?(:clj (declare seq-datom )
163+ :cljs (defn seq-datom [d]))
171164
172- (declare+ nth-datom [d i] [d i not-found])
165+ #?(:clj (declare nth-datom )
166+ :cljs (defn nth-datom ([d i]) ([d i not-found])))
173167
174- (declare+ assoc-datom [d k v])
168+ #?(:clj (declare assoc-datom )
169+ :cljs (defn assoc-datom [d k v]))
175170
176- (declare+ val-at-datom [d k not-found])
171+ #?(:clj (declare val-at-datom )
172+ :cljs (defn val-at-datom [d k not-found]))
177173
178174(defprotocol IDatom
179175 (datom-tx [this])
409405 #? (:clj (. clojure.lang.Util (hasheq x))
410406 :cljs (hash x)))
411407
412- (declare+ ^number value-compare [x y])
408+ #?(:clj (declare value-compare )
409+ :cljs (defn ^number value-compare [x y]))
413410
414411(defn- seq-compare [xs ys]
415412 (let [cx (count xs)
584581
585582; ; ----------------------------------------------------------------------------
586583
587- (declare+ ^number hash-db [db])
584+ #?(:clj (declare hash-db )
585+ :cljs (defn ^number hash-db [db]))
588586
589- (declare+ ^number hash-fdb [db])
587+ #?(:clj (declare hash-fdb )
588+ :cljs (defn ^number hash-fdb [db]))
590589
591- (declare+ ^boolean equiv-db [db other])
590+ #?(:clj (declare equiv-db )
591+ :cljs (defn ^boolean equiv-db [db other]))
592592
593- (declare+ restore-db [keys])
593+ #?(:clj (declare restore-db )
594+ :cljs (defn restore-db [keys]))
594595
595- (declare+ ^boolean indexing? [db attr])
596+ #?(:clj (declare indexing? )
597+ :cljs (defn ^boolean indexing? [db attr]))
596598
597- #?(:cljs
598- (declare+ pr-db [db w opts]))
599+ #?(:cljs (defn pr-db [db w opts]))
599600
600- (declare+ resolve-datom [db e a v t default-e default-tx ])
601+ #?(:clj (declare resolve-datom )
602+ :cljs (defn resolve-datom [db e a v t default-e default-tx ]))
601603
602- (declare+ components->pattern [db index c0 c1 c2 c3 default-e default-tx ])
604+ #?(:clj (declare components->pattern )
605+ :cljs (defn components->pattern [db index c0 c1 c2 c3 default-e default-tx ]))
603606
604607; ;;;;;;;;; Fast validation
605608
11221125
11231126; ; ----------------------------------------------------------------------------
11241127
1125- (declare+ ^number entid-strict [db eid])
1128+ #?(:clj (declare entid-strict )
1129+ :cljs (defn ^number entid-strict [db eid]))
11261130
1127- (declare+ ^boolean ref? [db attr])
1131+ #?(:clj (declare ref? )
1132+ :cljs (defn ^boolean ref? [db attr]))
11281133
11291134(defn+ resolve-datom [db e a v t default-e default-tx ]
11301135 (when (some? a)
16191624 (filter (fn [^Datom d] (component? db (.-a d))))
16201625 (map (fn [^Datom d] [:db.fn/retractEntity (.-v d)]))) datoms))
16211626
1622- (declare+ transact-tx-data-impl [initial-report initial-es])
1627+ #?(:clj (declare transact-tx-data-impl )
1628+ :cljs (defn transact-tx-data-impl [initial-report initial-es]))
16231629
16241630(defn- retry-with-tempid [initial-report report es tempid upserted-eid]
16251631 (if-some [eid (get (::upserted-tempids initial-report) tempid)]
19231929 (util/raise " Bad transaction data " es " , expected sequential collection"
19241930 {:error :transact/syntax , :tx-data es}))
19251931 (let [es' (assoc-auto-tempids (:db-before report) es)]
1926- (transact-tx-data-impl report es')))
1932+ (transact-tx-data-impl report es')))
0 commit comments