diff --git a/CHANGELOG.md b/CHANGELOG.md index d1e8117..0cd3176 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,16 @@ ## [Unreleased] +## [0.5.0] - 2021-03-19 +### Changed +- When building entities temp-ids no longer map newly allocated nodes for entities without an id back to themselves. + +### Removed +- No longer reading or writing JSON entities. This should be done outside of Zuko. Affected functions are: + * `zuko.entity.reader/graph->str` + * `zuko.entity.writer/stream->triples` +- No more dependency on Cheshire. + ## [0.4.6] - 2021-03-12 ### Added - Lookup refs in entity values. @@ -92,7 +102,8 @@ ### Added - Extracted from Asami/Naga -[Unreleased]: https://github.com/threatgrid/zuko/compare/0.4.6...HEAD +[Unreleased]: https://github.com/threatgrid/zuko/compare/0.5.0...HEAD +[0.5.0]: https://github.com/threatgrid/zuko/compare/0.4.6...0.5.0 [0.4.6]: https://github.com/threatgrid/zuko/compare/0.4.5...0.4.6 [0.4.5]: https://github.com/threatgrid/zuko/compare/0.4.4...0.4.5 [0.4.3]: https://github.com/threatgrid/zuko/compare/0.4.3...0.4.4 diff --git a/README.md b/README.md index bba99d4..6df7302 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ Include a dependency to this library. In Leiningen: ```clojure -[org.clojars.quoll/zuko "0.4.6"] +[org.clojars.quoll/zuko "0.5.0"] ``` In `deps.edn`: @@ -28,7 +28,7 @@ In `deps.edn`: ```clojure { :deps { - org.clojars.quoll/zuko {:mvn/version "0.4.6"} + org.clojars.quoll/zuko {:mvn/version "0.5.0"} } } ``` diff --git a/project.clj b/project.clj index f1116c6..9b7fdf9 100644 --- a/project.clj +++ b/project.clj @@ -1,12 +1,11 @@ -(defproject org.clojars.quoll/zuko "0.4.7" +(defproject org.clojars.quoll/zuko "0.5.0" :description "Threatgrid library for common graph database functionality" :url "https://github.com/threatgrid/zuko" :license {:name "EPL-2.0 OR GPL-2.0-or-later WITH Classpath-exception-2.0" :url "https://www.eclipse.org/legal/epl-2.0/"} :dependencies [[org.clojure/clojure "1.10.3"] [org.clojars.quoll/naga-store "0.5.2"] - [prismatic/schema "1.1.12"] - [cheshire "5.10.0"]] + [prismatic/schema "1.1.12"]] :plugins [[lein-cljsbuild "1.1.8"]] :profiles { :dev { diff --git a/src/zuko/entity/reader.cljc b/src/zuko/entity/reader.cljc index 451c388..627cc81 100644 --- a/src/zuko/entity/reader.cljc +++ b/src/zuko/entity/reader.cljc @@ -4,8 +4,7 @@ (:require [zuko.entity.general :as general :refer [tg-ns KeyValue EntityMap GraphType]] [zuko.node :as node] [schema.core :as s :refer [=>]] - [clojure.string :as string] - #?(:clj [cheshire.core :as j]))) + [clojure.string :as string])) (def MapOrList (s/cond-pre EntityMap [s/Any])) @@ -179,27 +178,3 @@ (->> (node/find-triple graph '[?e :tg/entity true]) (map first) (map #(ref->entity graph % nested? exclusions))))) - -#?(:clj - (defn json-generate-string - ([data] (j/generate-string data)) - ([data indent] - (j/generate-string - data - (assoc j/default-pretty-print-options - :indentation (apply str (repeat indent \space)))))) - - :cljs - (defn json-generate-string - ([data] (.stringify js/JSON (clj->js data))) - ([data indent] (.stringify js/JSON (clj->js data) nil indent)))) - - -(s/defn graph->str :- s/Str - "Reads a store into JSON strings" - ([graph :- GraphType] - (json-generate-string (graph->entities graph false))) - ([graph :- GraphType, nested? :- s/Bool] - (json-generate-string (graph->entities graph nested?))) - ([graph :- GraphType, nested? :- s/Bool, indent :- s/Num] - (json-generate-string (graph->entities graph nested?) indent))) diff --git a/src/zuko/entity/writer.cljc b/src/zuko/entity/writer.cljc index 6c1ff66..26223dd 100644 --- a/src/zuko/entity/writer.cljc +++ b/src/zuko/entity/writer.cljc @@ -5,27 +5,7 @@ [zuko.entity.reader :as reader] [zuko.node :as node] [schema.core :as s :refer [=>]] - [clojure.string :as string] - #?(:clj [clojure.java.io :as io]) - #?(:clj [cheshire.core :as j])) - #?(:clj (:import [java.util Map List]))) - -#?(:clj (def parse-json-string #(j/parse-string % true)) - :cljs (def parse-json-string #(js->clj (.parse js/JSON %) :keywordize-keys true))) - -#?(:clj - (defn json-generate-string - ([data] (j/generate-string data)) - ([data indent] - (j/generate-string - data - (assoc j/default-pretty-print-options - :indentation (apply str (repeat indent \space)))))) - - :cljs - (defn json-generate-string - ([data] (.stringify js/JSON (clj->js data))) - ([data indent] (.stringify js/JSON (clj->js data) nil indent)))) + [clojure.string :as string])) (def ^:dynamic *current-graph* nil) @@ -186,27 +166,6 @@ @*triples*))) -#?(:clj - (s/defn stream->triples :- [Triple] - "Converts a stream to triples" - [graph :- GraphType - io] - (with-open [r (io/reader io)] - (let [data (j/parse-stream r true)] - (entities->triples graph data)))) - - :cljs - (s/defn stream->triples :- [Triple] - [graph io] - (throw (ex-info "Unsupported IO" {:io io})))) - -(s/defn string->triples :- [Triple] - "Converts a string to triples" - [graph :- GraphType - s :- s/Str] - (entities->triples graph (parse-json-string s))) - - ;; updating the store (s/defn existing-triples diff --git a/test/zuko/test_entity.cljc b/test/zuko/test_entity.cljc index 70a0142..c0d43d5 100644 --- a/test/zuko/test_entity.cljc +++ b/test/zuko/test_entity.cljc @@ -1,5 +1,6 @@ (ns zuko.test-entity - (:require [zuko.entity.writer :refer [string->triples entities->triples entity-update->triples ident-map->triples]] + #?(:clj (:refer-clojure :exclude [read-string])) + (:require [zuko.entity.writer :refer [entities->triples entity-update->triples ident-map->triples]] [zuko.entity.reader :refer [graph->entities ref->entity]] [zuko.helper-stub :as test-helper] [asami.graph :refer [graph-transact]] @@ -7,6 +8,8 @@ [asami.memory :refer [empty-graph]] [asami.core :refer [q]] [qtest.core :refer [with-fresh-gen]] + #?(:clj [clojure.edn :refer [read-string]] + :cljs [cljs.reader :refer [read-string]]) #?(:clj [schema.test :as st :refer [deftest]] :cljs [schema.test :as st :refer-macros [deftest]]) #?(:clj [clojure.test :as t :refer [is]] @@ -29,20 +32,21 @@ (graph-transact graph 0 nil data)) (defn string->graph-set [s] - (set (string->triples (test-helper/new-graph) s))) + (let [d (read-string s)] + (set (entities->triples (test-helper/new-graph) d)))) (deftest test-encode-from-string - (let [m1 (string->graph-set "[{\"prop\": \"val\"}]") - m2 (string->graph-set "[{\"prop\": \"val\", \"p2\": 2}]") - m3 (string->graph-set (str "[{\"prop\": \"val\"," - " \"p2\": 22," - " \"p3\": [42, 54]}]")) - m4 (string->graph-set (str "[{\"prop\": \"val\"}," - " {\"prop\": \"val2\"}]")) - m5 (string->graph-set (str "[{\"prop\": \"val\"," - " \"arr\": [" - " {\"a\": 1}," - " {\"a\": 2}," + (let [m1 (string->graph-set "[{:prop \"val\"}]") + m2 (string->graph-set "[{:prop \"val\", :p2 2}]") + m3 (string->graph-set (str "[{:prop \"val\"," + " :p2 22," + " :p3 [42, 54]}]")) + m4 (string->graph-set (str "[{:prop \"val\"}," + " {:prop \"val2\"}]")) + m5 (string->graph-set (str "[{:prop \"val\"," + " :arr [" + " {:a 1}," + " {:a 2}," " [\"nested\"]" "]}]"))] (is (= #{[:test/n1 :db/ident :test/n1]