Skip to content

Commit

Permalink
0.5.0 release
Browse files Browse the repository at this point in the history
  • Loading branch information
Paula Gearon committed Mar 20, 2021
1 parent 3bb499b commit ed9b29a
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 87 deletions.
13 changes: 12 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ 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`:

```clojure
{
:deps {
org.clojars.quoll/zuko {:mvn/version "0.4.6"}
org.clojars.quoll/zuko {:mvn/version "0.5.0"}
}
}
```
Expand Down
5 changes: 2 additions & 3 deletions project.clj
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
27 changes: 1 addition & 26 deletions src/zuko/entity/reader.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -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]))
Expand Down Expand Up @@ -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)))
43 changes: 1 addition & 42 deletions src/zuko/entity/writer.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand Down
30 changes: 17 additions & 13 deletions test/zuko/test_entity.cljc
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
(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]]
[asami.multi-graph]
[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]]
Expand All @@ -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]
Expand Down

0 comments on commit ed9b29a

Please sign in to comment.