Skip to content

Commit

Permalink
Version 1.3.11
Browse files Browse the repository at this point in the history
  • Loading branch information
tonsky committed Mar 9, 2022
1 parent 6049e9a commit 642275d
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 23 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 1.3.11

- Fixed serializable/from-serializable for JS interop #429

# 1.3.10

- Allow symbols as data #425 #426 via @zoren
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ The intention with DataScript is to be a basic building block in client-side app
## Latest version [![Build Status](https://travis-ci.org/tonsky/datascript.svg?branch=master)](https://travis-ci.org/tonsky/datascript)

```clj
[datascript "1.3.10"]
[datascript "1.3.11"]
```

## Support us
Expand Down Expand Up @@ -166,7 +166,7 @@ For more examples, see [our acceptance test suite](test/datascript/test/).
DataScript can be used from any JS engine without additional dependencies:

```html
<script src="https://github.com/tonsky/datascript/releases/download/1.3.10/datascript-1.3.10.min.js"></script>
<script src="https://github.com/tonsky/datascript/releases/download/1.3.11/datascript-1.3.11.min.js"></script>
```

or as a CommonJS module ([npm page](https://www.npmjs.org/package/datascript)):
Expand Down
10 changes: 1 addition & 9 deletions project.clj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(def version "1.3.10")
(def version "1.3.11")

(defproject datascript (str version (System/getenv "DATASCRIPT_CLASSIFIER"))
:description "An implementation of Datomic in-memory database and Datalog query engine in ClojureScript"
Expand All @@ -22,14 +22,6 @@
;; *unchecked-math* :warn-on-boxed
}
:jvm-opts ["-Xmx2g" "-server"]

:aliases {"test-clj" ["with-profile" "test" "run" "-m" "datascript.test/test-clj"]
"test-cljs" ["with-profile" "test" "do"
["cljsbuild" "once" "release" "advanced"]
["run" "-m" "datascript.test/test-node" "--all"]]
"node-repl" ["run" "-m" "user/node-repl"]
"browser-repl" ["run" "-m" "user/browser-repl"]
"test-all" ["do" ["clean"] ["with-profile" "test" "test-clj"] ["test-cljs"]]}

:cljsbuild {
:builds [
Expand Down
2 changes: 1 addition & 1 deletion release-js/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "datascript",
"version": "1.3.10",
"version": "1.3.11",
"description": "Immutable in-memory triplestore with Datalog queries",
"homepage": "https://github.com/tonsky/datascript",
"author": "Nikita Prokopov (https://github.com/tonsky)",
Expand Down
2 changes: 1 addition & 1 deletion release-js/wrapper.prefix
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Datascript v1.3.10
* Datascript v1.3.11
*
* Copyright 2014-2021 Nikita Prokopov
*
Expand Down
7 changes: 4 additions & 3 deletions src/datascript/js.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
[cljs.reader]
[goog.object :as go]
[clojure.walk :as walk]
[datascript.core :as d]))
[datascript.core :as d]
[datascript.serialize :as serialize]))

;; Conversions

Expand Down Expand Up @@ -79,8 +80,8 @@
(defn ^:export init_db [datoms & [schema]]
(d/init-db (map js->Datom datoms) (schema->clj schema)))

(def ^:export serializable d/serializable)
(def ^:export from_serializable d/from-serializable)
(def ^:export serializable #(serialize/serializable % {:freeze-kw identity}))
(def ^:export from_serializable #(serialize/from-serializable % {:thaw-kw identity}))

(defn ^:export q [query & sources]
(let [query (cljs.reader/read-string query)
Expand Down
10 changes: 6 additions & 4 deletions src/datascript/serialize.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,9 @@
dtx :: tx - tx0
aevt :: [<index in eavt> ...]
avet :: [<index in eavt> ...]"
[db {:keys [freeze-fn]
:or {freeze-fn pr-str}}]
[db {:keys [freeze-fn freeze-kw]
:or {freeze-fn pr-str
freeze-kw freeze-kw}}]
(let [attrs (all-attrs db)
attrs-map (into {} (map vector attrs (range)))
*kws (volatile! (transient []))
Expand Down Expand Up @@ -183,8 +184,9 @@
(defn from-serializable
([from]
(from-serializable from {}))
([from {:keys [thaw-fn]
:or {thaw-fn edn/read-string}}]
([from {:keys [thaw-fn thaw-kw]
:or {thaw-fn edn/read-string
thaw-kw thaw-kw}}]
(let [tx0 (dict-get from "tx0")
schema (thaw-fn (dict-get from "schema"))
_ (#'db/validate-schema schema)
Expand Down
35 changes: 33 additions & 2 deletions test/js/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,6 @@ function test_upsert() {
}
};
var conn = d.create_conn(schema);

d.transact(conn, [{
":my/tid": "5x",
":my/name": "Terin"
Expand All @@ -507,6 +506,37 @@ function test_upsert() {
assert_eq_set([["Charlie"]], names);
}

function test_serialize() {
var schema = {
":my/tid": {
":db/unique": ":db.unique/identity"
}
};
var conn = d.create_conn(schema);
d.transact(conn, [{":my/email": "a", ":my/name": "A"}]);
d.transact(conn, [{":my/email": "b", ":my/name": "B"}]);
var db = d.db(conn);

assert_eq_set(
[[1, ":my/email", "a"], [1, ":my/name", "A"], [2, ":my/email", "b"], [2, ":my/name", "B"]],
d.q('[:find ?e ?a ?v :where [?e ?a ?v]]', db)
);

var json = JSON.stringify(d.serializable(db));
var db2 = d.from_serializable(JSON.parse(json));

assert_eq_set(
[[1, ":my/email", "a"], [1, ":my/name", "A"], [2, ":my/email", "b"], [2, ":my/name", "B"]],
d.q('[:find ?e ?a ?v :where [?e ?a ?v]]', db2)
);

assert_eq_set(
[[1, "A"], [2, "B"]],
d.q('[:find ?e ?v :where [?e ":my/name" ?v]]', db2)
);
}


function test_datascript_js() {
return test_fns([ test_db_with,
test_nested_maps,
Expand All @@ -528,7 +558,8 @@ function test_datascript_js() {
test_find_specs,
test_datoms,
test_filter,
test_upsert
test_upsert,
test_serialize,
]);
}

Expand Down
4 changes: 3 additions & 1 deletion test_node.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ if (fs.existsSync("./target/none")) {
nodeGlobalRequire('./target/none/cljs_deps.js');
goog.require('datascript.test');
goog.require('datascript.js');
} else {
} else if ("--cljs" === process.argv[2]) {
nodeGlobalRequire('./target/datascript.js');
} else {
nodeGlobalRequire('./release-js/datascript.js');
}

function merge(m1, m2) {
Expand Down

0 comments on commit 642275d

Please sign in to comment.