forked from babashka/nbb
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add datascript and datascript-transit features (babashka#160)
- Loading branch information
1 parent
3f4e801
commit c72d8fd
Showing
20 changed files
with
236 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
{:deps | ||
{datascript-transit/datascript-transit {:mvn/version "0.3.0"}}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{:modules | ||
{:nbb_datascript_transit {:init-fn nbb.impl.datascript-transit/init | ||
:depends-on #{:nbb_core :nbb_datascript :nbb_transit}}}} |
18 changes: 18 additions & 0 deletions
18
features/datascript-transit/src/nbb/impl/datascript_transit.cljs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
(ns nbb.impl.datascript-transit | ||
{:no-doc true} | ||
(:require [datascript.transit :as dt] | ||
[nbb.core :as nbb] | ||
[sci.core :as sci :refer [copy-var]])) | ||
|
||
(def transit-ns (sci/create-ns 'datascript.transit nil)) | ||
|
||
(def transit-namespace | ||
{'read-handlers (copy-var dt/read-handlers transit-ns) | ||
'write-handlers (copy-var dt/write-handlers transit-ns) | ||
'read-transit-str (copy-var dt/read-transit-str transit-ns) | ||
'write-transit-str (copy-var dt/write-transit-str transit-ns)}) | ||
|
||
(defn init [] | ||
(nbb/register-plugin! | ||
::datascript-transit | ||
{:namespaces {'datascript.transit transit-namespace}})) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[{:name logseq/datascript-transit | ||
:namespaces [datascript.transit] | ||
:js "./nbb_datascript_transit.js"}] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
{:deps | ||
{datascript/datascript {:mvn/version "1.3.12"}}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{:compiler-options {:externs ["datascript/externs.js"]} | ||
:modules | ||
{:nbb_datascript {:init-fn nbb.impl.datascript/init | ||
;; From https://github.com/tonsky/datascript/issues/298#issuecomment-813790783 | ||
:prepend "if (global) { global.datascript = datascript } else if (window) { window.datascript = datascript } else { var datascript = {}}" | ||
:depends-on #{:nbb_core}}}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
(ns nbb.impl.datascript | ||
{:no-doc true} | ||
(:require [datascript.core :as d] | ||
[datascript.db :as db] | ||
[nbb.core :as nbb] | ||
[sci.core :as sci :refer [copy-var]])) | ||
|
||
(def core-ns (sci/create-ns 'datascript.core nil)) | ||
(def db-ns (sci/create-ns 'datascript.db nil)) | ||
|
||
(def core-namespace | ||
{'q (copy-var d/q core-ns) | ||
'empty-db (copy-var d/empty-db core-ns) | ||
'db-with (copy-var d/db-with core-ns) | ||
'filter (copy-var d/filter core-ns) | ||
'init-db (copy-var d/init-db core-ns) | ||
'datom (copy-var d/datom core-ns) | ||
'datoms (copy-var d/datoms core-ns) | ||
'pull (copy-var d/pull core-ns) | ||
'pull-many (copy-var d/pull-many core-ns) | ||
'entity (copy-var d/entity core-ns) | ||
'tx0 (copy-var d/tx0 core-ns) | ||
'db (copy-var d/db core-ns) | ||
'with (copy-var d/with core-ns) | ||
'touch (copy-var d/touch core-ns) | ||
'index-range (copy-var d/index-range core-ns) | ||
'listen! (copy-var d/listen! core-ns) | ||
'conn-from-db (copy-var d/conn-from-db core-ns) | ||
'conn-from-datoms (copy-var d/conn-from-datoms core-ns) | ||
'transact! (copy-var d/transact! core-ns) | ||
'create-conn (copy-var d/create-conn core-ns) | ||
'reset-conn! (copy-var d/reset-conn! core-ns) | ||
'from-serializable (copy-var d/from-serializable core-ns) | ||
'serializable (copy-var d/serializable core-ns)}) | ||
|
||
(def db-namespace | ||
{'db-from-reader (copy-var db/db-from-reader db-ns) | ||
'datom-from-reader (copy-var db/datom-from-reader db-ns) | ||
'datom-added (copy-var db/datom-added db-ns) | ||
'datom-tx (copy-var db/datom-tx db-ns) | ||
'datom (copy-var db/datom db-ns) | ||
'DB (copy-var db/DB db-ns) | ||
'Datom (copy-var db/Datom db-ns)}) | ||
|
||
(defn init [] | ||
(nbb/register-plugin! | ||
::datascript | ||
{:namespaces {'datascript.core core-namespace | ||
'datascript.db db-namespace}})) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[{:name logseq/datascript | ||
:namespaces [datascript.core datascript.db] | ||
:js "./nbb_datascript.js"}] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
;; This is a stub file which is only populated when nbb is built with features | ||
{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
(ns nbb.impl.transit | ||
(:require [cognitect.transit :as transit] | ||
[nbb.core :as nbb] | ||
[sci.core :as sci :refer [copy-var]])) | ||
|
||
(def transit-ns (sci/create-ns 'cognitect.transit nil)) | ||
|
||
(def transit-namespace | ||
{'write (copy-var transit/write transit-ns) | ||
'writer (copy-var transit/writer transit-ns) | ||
'write-handler (copy-var transit/write-handler transit-ns) | ||
'write-meta (copy-var transit/write-meta transit-ns) | ||
'read (copy-var transit/read transit-ns) | ||
'reader (copy-var transit/reader transit-ns) | ||
'read-handler (copy-var transit/read-handler transit-ns) | ||
'tagged-value (copy-var transit/tagged-value transit-ns) | ||
'ListHandler (copy-var transit/ListHandler transit-ns)}) | ||
|
||
(defn init [] | ||
(nbb/register-plugin! | ||
::transit | ||
{:namespaces {'cognitect.transit transit-namespace}})) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.