Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into refactor/config-parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
zonotope committed Feb 25, 2025
2 parents 7a9ca1e + ec5667e commit 177af46
Show file tree
Hide file tree
Showing 14 changed files with 123 additions and 202 deletions.
9 changes: 2 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: all compile deps jar install deploy nodejs browser webworker cljtest \
.PHONY: all deps jar install deploy nodejs browser webworker cljtest \
cljs-browser-test cljs-node-test cljstest test eastwood ci clean \
js-packages sync-package-json publish-nodejs publish-browser \
publish-webworker publish-js pending-tests pt
Expand All @@ -15,11 +15,6 @@ ALL_SOURCES := $(SOURCES) $(BROWSER_SOURCES) $(WEBWORKER_SOURCES) $(NODEJS_SOURC

all: jar browser nodejs webworker js-packages docs

target/classes:
clojure -T:build compile

compile: target/classes

target/fluree-db.jar: out node_modules src/clj/deps.cljs $(ALL_SOURCES) $(RESOURCES)
clojure -T:build jar

Expand Down Expand Up @@ -113,7 +108,7 @@ browser-test: out/fluree-browser-sdk.js

cljstest: cljs-browser-test cljs-node-test

cljtest: target/classes
cljtest:
clojure -X:dev:cljtest

pending-tests:
Expand Down
8 changes: 0 additions & 8 deletions build.clj
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
(ns build
(:refer-clojure :exclude [compile])
(:require [clojure.tools.build.api :as b]
[deps-deploy.deps-deploy :as dd]))

Expand All @@ -12,17 +11,10 @@

(def source-uri "https://github.com/fluree/db")

(defn compile [_]
(b/javac {:src-dirs ["src/java"]
:class-dir class-dir
:basis basis
:javac-opts ["--release" "11"]}))

(defn clean [_]
(b/delete {:path "target"}))

(defn jar [_]
(compile nil)
(b/write-pom {:class-dir class-dir
:lib lib
:version version
Expand Down
4 changes: 0 additions & 4 deletions deps.edn
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,6 @@

:paths ["src/clj" "resources" "target/classes"]

:deps/prep-lib {:alias :build
:fn compile
:ensure "target/classes"}

:aliases
{:build
{:deps {io.github.clojure/tools.build {:git/tag "v0.10.5"
Expand Down
2 changes: 1 addition & 1 deletion src/clj/fluree/db/datatype.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

#?(:clj (set! *warn-on-reflection* true))

(time-literals/print-time-literals-clj!)
#?(:clj (time-literals/print-time-literals-clj!))

(def default-data-types
{const/iri-id const/$id
Expand Down
11 changes: 2 additions & 9 deletions src/clj/fluree/db/flake.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,10 @@
[fluree.db.util.core :as util]
[fluree.db.json-ld.iri :as iri]
#?(:clj [clojure.pprint :as pprint]))
#?(:clj (:import (fluree.db SID)))
#?(:cljs (:require-macros [fluree.db.flake :refer [combine-cmp]])))

#?(:clj (set! *warn-on-reflection* true))

;; maximum number of subject indexes within a given collection. 44 bits - 17,592,186,044,415
;; javascript, 44 bits - 1
(def ^:const MAX-COLL-SUBJECTS #?(:clj 2r11111111111111111111111111111111111111111111
:cljs (- 2r11111111111111111111111111111111111111111111 1)))

(declare equiv-flake assoc-flake get-flake-val nth-flake)

(def min-s iri/min-sid)
Expand Down Expand Up @@ -300,10 +294,9 @@
0))

(defn cmp-sid
[^SID sid1 ^SID sid2]
[sid1 sid2]
(if (and sid1 sid2)
#?(:clj (SID/compare sid1 sid2)
:cljs (compare sid1 sid2))
(compare sid1 sid2)
0))

(defn cmp-subj
Expand Down
7 changes: 5 additions & 2 deletions src/clj/fluree/db/flake/index/novelty.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,10 @@
:garbage (:address garbage-res))]
(log/info "Index refresh complete:" end-stats)
;; kick off automatic garbage collection
(async/thread
(garbage/clean-garbage indexed-db max-old-indexes))
#?(:clj
(async/thread
(garbage/clean-garbage indexed-db max-old-indexes))
:cljs
(<? (garbage/clean-garbage indexed-db max-old-indexes)))
indexed-db)))))
db))))
160 changes: 94 additions & 66 deletions src/clj/fluree/db/json_ld/iri.cljc
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
(ns fluree.db.json-ld.iri
(:require [fluree.db.util.core :as util]
[fluree.db.util.bytes :as bytes]
[fluree.db.util.log :as log]
[clojure.string :as str]
[clojure.set :refer [map-invert]]
[nano-id.core :refer [nano-id]]
#?(:cljs [fluree.db.sid :refer [SID]]))
#?(:clj (:import (fluree.db SID))))
[nano-id.core :refer [nano-id]]))

#?(:clj (set! *warn-on-reflection* true))

Expand Down Expand Up @@ -70,6 +68,98 @@
"_:" 24
f-idx-ns 25})

(declare compare-SIDs sid-equiv?)

;; TODO - verify sort order is same!!
;;
(deftype SID #?(:clj [^int namespace-code name]
:cljs [^number namespace-code name])
#?@(:clj [Object
(equals [this sid]
(sid-equiv? this sid))
(hashCode [_]
(clojure.lang.Util/hashCombine namespace-code (hash name)))

clojure.lang.IHashEq
(hasheq [_]
(clojure.lang.Util/hashCombine namespace-code (hash name)))

java.lang.Comparable
(compareTo [this other] (compare-SIDs this other))]

:cljs [IHash
(-hash [_]
(hash-combine namespace-code (hash name)))

IEquiv
(-equiv [this sid] (sid-equiv? this sid))

IComparable
(-compare [this other] (compare-SIDs this other))

IPrintWithWriter
(-pr-writer [^SID sid writer opts]
(pr-sequential-writer writer pr-writer
"#fluree/SID [" " " "]"
opts [(.-namespace-code sid) (.-name sid)]))]))

(defn sid-equiv?
[^SID sid ^SID other]
(and (instance? SID other)
(= (.-namespace-code sid) (.-namespace-code other))
(= (.-name sid) (.-name other))))

(defn ^SID ->sid
[ns-code nme]
(->SID #?(:clj (int ns-code) :cljs ns-code) nme))

(defn get-ns-code
[^SID sid]
(.-namespace-code sid))

(defn get-name
[^SID sid]
(.-name sid))

(defn deserialize-sid
[[ns-code nme]]
(->sid ns-code nme))

(defn measure-sid
"Returns the size of an SID."
[sid]
(+ 12 ; 12 bytes for object header
4 ; 4 bytes for namespace code
(* 2 (count (get-name sid)))))

(def serialize-sid
(juxt get-ns-code get-name))

#?(:clj (defmethod print-method SID [^SID sid ^java.io.Writer w]
(doto w
(.write "#fluree/SID ")
(.write (-> sid serialize-sid pr-str)))))

; TODO - verify we don't need this
;#?(:clj (defmethod print-dup SID
; [^SID sid ^java.io.Writer w]
; (let [ns-code (get-ns-code sid)
; nme (get-name sid)]
; (.write w (str "#=" `(->sid ~ns-code ~nme))))))

(defn compare-SIDs
[sid1 sid2]
(when-not (instance? SID sid2)
(throw (ex-info "Can't compare an SID to another type"
{:status 500 :error :db/unexpected-error})))
(let [ns-cmp (compare (get-ns-code sid1) (get-ns-code sid2))]
(if-not (zero? ns-cmp)
ns-cmp
(compare (get-name sid1) (get-name sid2)))))

(defn sid?
[x]
(instance? SID x))

(def default-namespace-codes
(map-invert default-namespaces))
Expand Down Expand Up @@ -106,82 +196,20 @@
(decompose-by-char iri* \: length)
["" iri*]))))

(def name-code-xf
(comp (partition-all 8)
(map bytes/UTF8->long)))

#?(:clj (defn name->codes
[nme]
(->> nme
bytes/string->UTF8
(into [] name-code-xf))))

#?(:clj (defn codes->name
[nme-codes]
(->> nme-codes
(mapcat bytes/long->UTF8)
bytes/UTF8->string)))

(defn ->sid
[ns-code nme]
(let [ns-int (int ns-code)
nme* #?(:clj (-> nme name->codes long-array)
:cljs nme)]
(SID. ns-int nme*)))

(defn get-ns-code
[^SID sid]
#?(:clj (.getNamespaceCode sid)
:cljs (:namespace-code sid)))

(defn get-namespace
([sid]
(get-namespace sid default-namespace-codes))
([sid namespace-codes]
(let [ns-code (get-ns-code sid)]
(get namespace-codes ns-code))))

(defn get-name
[^SID sid]
#?(:clj (->> sid .getNameCodes codes->name)
:cljs (:name sid)))

(defn deserialize-sid
[[ns-code nme]]
(->sid ns-code nme))

(defn measure-sid
"Returns the size of an SID."
[sid]
(+ 12 ; 12 bytes for object header
4 ; 4 bytes for namespace code
(* 2 (count (get-name sid)))))

(def serialize-sid
(juxt get-ns-code get-name))

(defn serialized-sid?
[x]
(and (vector? x)
(= (count x) 2)
(number? (nth x 0))
(string? (nth x 1))))

#?(:clj (defmethod print-method SID [^SID sid ^java.io.Writer w]
(doto w
(.write "#fluree/SID ")
(.write (-> sid serialize-sid pr-str)))))

#?(:clj (defmethod print-dup SID
[^SID sid ^java.io.Writer w]
(let [ns-code (get-ns-code sid)
nme (get-name sid)]
(.write w (str "#=" `(->sid ~ns-code ~nme))))))

(defn sid?
[x]
(instance? SID x))

(defn blank-node-sid?
[x]
(and (sid? x)
Expand Down
12 changes: 7 additions & 5 deletions src/clj/fluree/db/query/exec/eval.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@
(and (contains? comparable-time-datatypes dt-a)
(contains? comparable-time-datatypes dt-b))
#?(:clj (compare (->offset-date-time val-a) (->offset-date-time val-b))
:cljs (comapre val-a val-b))
:cljs (compare val-a val-b))

;; same types compare
(= dt-a dt-b)
Expand Down Expand Up @@ -382,6 +382,7 @@
:cljs (js/Date.))
const/iri-xsd-dateTime))

;; TODO - date functions below all look incorrect for CLJS - should (string? datetime) be (map? datetime)?
(defn year
[datetime]
(where/->typed-val
Expand Down Expand Up @@ -418,7 +419,7 @@
:cljs
(.getHours (if (string? x)
(datatype/coerce (:value x) (:datatype-iri x))
datetime)))))
x)))))

(defn minutes
[x]
Expand All @@ -444,6 +445,7 @@
(datatype/coerce (:value x) (:datatype-iri x))
x)))))

;; TODO - CLJS datetime is not a variable present in the function
(defn tz
[x]
(where/->typed-val
Expand All @@ -452,9 +454,9 @@
(.toString (.getOffset ^OffsetDateTime (->offset-date-time (:value x))))
#{const/iri-xsd-time}
(.toString (.getOffset ^OffsetTime (->offset-time (:value x)))))
:cljs (.getTimeZoneOffset ^js/Date (if (string? datetime)
(datatype/coerce (:value datetime) (:datatype-iri datetime))
datetime)))))
:cljs (.getTimeZoneOffset ^js/Date (if (string? x)
(datatype/coerce (:value x) (:datatype-iri x))
x)))))

(defn sha256
[{x :value}]
Expand Down
12 changes: 0 additions & 12 deletions src/clj/fluree/db/sid.cljs

This file was deleted.

3 changes: 2 additions & 1 deletion src/clj/fluree/db/storage.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@
(defn split-address
"Splits `address` into the fully qualified storage method and local path."
[address]
(str/split address #":(?!.*:)" 2))
(let [i (str/last-index-of address ":")]
[(subs address 0 i) (subs address (inc i))]))

(defn valid-identifier?
[x]
Expand Down
2 changes: 1 addition & 1 deletion src/clj/fluree/db/virtual_graph/parse.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
[fluree.db.query.exec.update :as exec.update]
[fluree.db.query.exec.where :as where]
[fluree.db.query.exec.where :as exec.where]
#?(:cljs fluree.db.query.exec.select :refer [SubgraphSelector])
#?(:cljs [fluree.db.query.exec.select :refer [SubgraphSelector]])
[fluree.db.query.fql.parse :as q-parse])
#?(:clj (:import (fluree.db.query.exec.select SubgraphSelector))))

Expand Down
Loading

0 comments on commit 177af46

Please sign in to comment.