datahike-browser-tests 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (324) hide show
  1. package/.circleci/config.yml +405 -0
  2. package/.circleci/scripts/gen_ci.clj +194 -0
  3. package/.cirrus.yml +60 -0
  4. package/.clj-kondo/babashka/sci/config.edn +1 -0
  5. package/.clj-kondo/babashka/sci/sci/core.clj +9 -0
  6. package/.clj-kondo/config.edn +95 -0
  7. package/.dir-locals.el +2 -0
  8. package/.github/FUNDING.yml +3 -0
  9. package/.github/ISSUE_TEMPLATE/1-bug-report.yml +68 -0
  10. package/.github/ISSUE_TEMPLATE/2-feature-request.yml +28 -0
  11. package/.github/ISSUE_TEMPLATE/config.yml +6 -0
  12. package/.github/pull_request_template.md +24 -0
  13. package/.github/workflows/native-image.yml +84 -0
  14. package/LICENSE +203 -0
  15. package/README.md +273 -0
  16. package/bb/deps.edn +9 -0
  17. package/bb/resources/github-fingerprints +3 -0
  18. package/bb/resources/native-image-tests/run-bb-pod-tests.clj +162 -0
  19. package/bb/resources/native-image-tests/run-libdatahike-tests +12 -0
  20. package/bb/resources/native-image-tests/run-native-image-tests +74 -0
  21. package/bb/resources/native-image-tests/run-python-tests +22 -0
  22. package/bb/resources/native-image-tests/testconfig.attr-refs.edn +6 -0
  23. package/bb/resources/native-image-tests/testconfig.edn +5 -0
  24. package/bb/resources/template/.settings/org.eclipse.jdt.apt.core.prefs +2 -0
  25. package/bb/resources/template/.settings/org.eclipse.jdt.core.prefs +9 -0
  26. package/bb/resources/template/.settings/org.eclipse.m2e.core.prefs +4 -0
  27. package/bb/resources/template/pom.xml +22 -0
  28. package/bb/src/tools/build.clj +132 -0
  29. package/bb/src/tools/clj_kondo.clj +32 -0
  30. package/bb/src/tools/deploy.clj +26 -0
  31. package/bb/src/tools/examples.clj +19 -0
  32. package/bb/src/tools/npm.clj +100 -0
  33. package/bb/src/tools/python.clj +14 -0
  34. package/bb/src/tools/release.clj +94 -0
  35. package/bb/src/tools/test.clj +148 -0
  36. package/bb/src/tools/version.clj +47 -0
  37. package/bb.edn +269 -0
  38. package/benchmark/src/benchmark/cli.clj +195 -0
  39. package/benchmark/src/benchmark/compare.clj +157 -0
  40. package/benchmark/src/benchmark/config.clj +316 -0
  41. package/benchmark/src/benchmark/measure.clj +187 -0
  42. package/benchmark/src/benchmark/store.clj +190 -0
  43. package/benchmark/test/benchmark/measure_test.clj +156 -0
  44. package/build.clj +30 -0
  45. package/config.edn +49 -0
  46. package/deps.edn +138 -0
  47. package/dev/sandbox.clj +82 -0
  48. package/dev/sandbox.cljs +127 -0
  49. package/dev/sandbox_benchmarks.clj +27 -0
  50. package/dev/sandbox_client.clj +87 -0
  51. package/dev/sandbox_transact_bench.clj +109 -0
  52. package/dev/user.clj +79 -0
  53. package/doc/README.md +96 -0
  54. package/doc/adl/README.md +6 -0
  55. package/doc/adl/adr-000-adr.org +28 -0
  56. package/doc/adl/adr-001-attribute-references.org +15 -0
  57. package/doc/adl/adr-002-build-tooling.org +54 -0
  58. package/doc/adl/adr-003-db-meta-data.md +52 -0
  59. package/doc/adl/adr-004-github-flow.md +40 -0
  60. package/doc/adl/adr-XYZ-template.md +30 -0
  61. package/doc/adl/index.org +3 -0
  62. package/doc/assets/datahike-logo.svg +3 -0
  63. package/doc/assets/datahiking-invoice.org +85 -0
  64. package/doc/assets/hhtree2.png +0 -0
  65. package/doc/assets/network_topology.svg +624 -0
  66. package/doc/assets/perf.png +0 -0
  67. package/doc/assets/schema_mindmap.mm +132 -0
  68. package/doc/assets/schema_mindmap.svg +970 -0
  69. package/doc/assets/temporal_index.mm +74 -0
  70. package/doc/backend-development.md +78 -0
  71. package/doc/bb-pod.md +89 -0
  72. package/doc/benchmarking.md +360 -0
  73. package/doc/bindings/edn-conversion.md +383 -0
  74. package/doc/cli.md +162 -0
  75. package/doc/cljdoc.edn +27 -0
  76. package/doc/cljs-support.md +133 -0
  77. package/doc/config.md +406 -0
  78. package/doc/contributing.md +114 -0
  79. package/doc/datalog-vs-sql.md +210 -0
  80. package/doc/datomic_differences.md +109 -0
  81. package/doc/development/pull-api-ns.md +186 -0
  82. package/doc/development/pull-frame-state-diagram.jpg +0 -0
  83. package/doc/distributed.md +566 -0
  84. package/doc/entity_spec.md +92 -0
  85. package/doc/gc.md +273 -0
  86. package/doc/java-api.md +808 -0
  87. package/doc/javascript-api.md +421 -0
  88. package/doc/libdatahike.md +86 -0
  89. package/doc/logging_and_error_handling.md +43 -0
  90. package/doc/norms.md +66 -0
  91. package/doc/schema-migration.md +85 -0
  92. package/doc/schema.md +287 -0
  93. package/doc/storage-backends.md +363 -0
  94. package/doc/store-id-refactoring.md +596 -0
  95. package/doc/time_variance.md +325 -0
  96. package/doc/unstructured.md +167 -0
  97. package/doc/versioning.md +261 -0
  98. package/examples/basic/README.md +19 -0
  99. package/examples/basic/deps.edn +6 -0
  100. package/examples/basic/docker-compose.yml +13 -0
  101. package/examples/basic/src/examples/core.clj +60 -0
  102. package/examples/basic/src/examples/schema.clj +155 -0
  103. package/examples/basic/src/examples/store.clj +60 -0
  104. package/examples/basic/src/examples/time_travel.clj +185 -0
  105. package/examples/java/.settings/org.eclipse.core.resources.prefs +3 -0
  106. package/examples/java/.settings/org.eclipse.jdt.apt.core.prefs +2 -0
  107. package/examples/java/.settings/org.eclipse.jdt.core.prefs +9 -0
  108. package/examples/java/.settings/org.eclipse.m2e.core.prefs +4 -0
  109. package/examples/java/README.md +162 -0
  110. package/examples/java/pom.xml +62 -0
  111. package/examples/java/src/main/java/examples/QuickStart.java +115 -0
  112. package/examples/java/src/main/java/examples/SchemaExample.java +148 -0
  113. package/examples/java/src/main/java/examples/TimeTravelExample.java +121 -0
  114. package/flake.lock +27 -0
  115. package/flake.nix +27 -0
  116. package/http-server/datahike/http/middleware.clj +75 -0
  117. package/http-server/datahike/http/server.clj +269 -0
  118. package/java/src/datahike/java/Database.java +274 -0
  119. package/java/src/datahike/java/Datahike.java +281 -0
  120. package/java/src/datahike/java/DatahikeGeneratedTest.java +349 -0
  121. package/java/src/datahike/java/DatahikeTest.java +370 -0
  122. package/java/src/datahike/java/EDN.java +170 -0
  123. package/java/src/datahike/java/IEntity.java +11 -0
  124. package/java/src/datahike/java/Keywords.java +161 -0
  125. package/java/src/datahike/java/SchemaFlexibility.java +52 -0
  126. package/java/src/datahike/java/Util.java +219 -0
  127. package/karma.conf.js +19 -0
  128. package/libdatahike/compile-cpp +7 -0
  129. package/libdatahike/src/datahike/impl/LibDatahikeBase.java +203 -0
  130. package/libdatahike/src/datahike/impl/libdatahike.clj +59 -0
  131. package/libdatahike/src/test_cpp.cpp +61 -0
  132. package/npm-package/PUBLISHING.md +140 -0
  133. package/npm-package/README.md +226 -0
  134. package/npm-package/package.template.json +34 -0
  135. package/npm-package/test-isomorphic.ts +281 -0
  136. package/npm-package/test.js +557 -0
  137. package/npm-package/typescript-test.ts +70 -0
  138. package/package.json +16 -0
  139. package/pydatahike/README.md +569 -0
  140. package/pydatahike/pyproject.toml +91 -0
  141. package/pydatahike/setup.py +42 -0
  142. package/pydatahike/src/datahike/__init__.py +134 -0
  143. package/pydatahike/src/datahike/_native.py +250 -0
  144. package/pydatahike/src/datahike/_version.py +2 -0
  145. package/pydatahike/src/datahike/database.py +722 -0
  146. package/pydatahike/src/datahike/edn.py +311 -0
  147. package/pydatahike/src/datahike/py.typed +0 -0
  148. package/pydatahike/tests/conftest.py +17 -0
  149. package/pydatahike/tests/test_basic.py +170 -0
  150. package/pydatahike/tests/test_database.py +51 -0
  151. package/pydatahike/tests/test_edn_conversion.py +299 -0
  152. package/pydatahike/tests/test_query.py +99 -0
  153. package/pydatahike/tests/test_schema.py +55 -0
  154. package/resources/clj-kondo.exports/io.replikativ/datahike/config.edn +5 -0
  155. package/resources/example_server.edn +4 -0
  156. package/shadow-cljs.edn +56 -0
  157. package/src/data_readers.clj +7 -0
  158. package/src/datahike/api/impl.cljc +176 -0
  159. package/src/datahike/api/specification.cljc +633 -0
  160. package/src/datahike/api/types.cljc +261 -0
  161. package/src/datahike/api.cljc +41 -0
  162. package/src/datahike/array.cljc +99 -0
  163. package/src/datahike/cli.clj +166 -0
  164. package/src/datahike/cljs.cljs +6 -0
  165. package/src/datahike/codegen/cli.clj +406 -0
  166. package/src/datahike/codegen/clj_kondo.clj +291 -0
  167. package/src/datahike/codegen/java.clj +403 -0
  168. package/src/datahike/codegen/naming.cljc +33 -0
  169. package/src/datahike/codegen/native.clj +559 -0
  170. package/src/datahike/codegen/pod.clj +488 -0
  171. package/src/datahike/codegen/python.clj +838 -0
  172. package/src/datahike/codegen/report.clj +55 -0
  173. package/src/datahike/codegen/typescript.clj +262 -0
  174. package/src/datahike/codegen/validation.clj +145 -0
  175. package/src/datahike/config.cljc +294 -0
  176. package/src/datahike/connections.cljc +16 -0
  177. package/src/datahike/connector.cljc +265 -0
  178. package/src/datahike/constants.cljc +142 -0
  179. package/src/datahike/core.cljc +297 -0
  180. package/src/datahike/datom.cljc +459 -0
  181. package/src/datahike/db/interface.cljc +119 -0
  182. package/src/datahike/db/search.cljc +305 -0
  183. package/src/datahike/db/transaction.cljc +937 -0
  184. package/src/datahike/db/utils.cljc +338 -0
  185. package/src/datahike/db.cljc +956 -0
  186. package/src/datahike/experimental/unstructured.cljc +126 -0
  187. package/src/datahike/experimental/versioning.cljc +172 -0
  188. package/src/datahike/externs.js +31 -0
  189. package/src/datahike/gc.cljc +69 -0
  190. package/src/datahike/http/client.clj +188 -0
  191. package/src/datahike/http/writer.clj +79 -0
  192. package/src/datahike/impl/entity.cljc +218 -0
  193. package/src/datahike/index/interface.cljc +93 -0
  194. package/src/datahike/index/persistent_set.cljc +469 -0
  195. package/src/datahike/index/utils.cljc +44 -0
  196. package/src/datahike/index.cljc +32 -0
  197. package/src/datahike/js/api.cljs +172 -0
  198. package/src/datahike/js/api_macros.clj +22 -0
  199. package/src/datahike/js.cljs +163 -0
  200. package/src/datahike/json.cljc +209 -0
  201. package/src/datahike/lru.cljc +146 -0
  202. package/src/datahike/migrate.clj +39 -0
  203. package/src/datahike/norm/norm.clj +245 -0
  204. package/src/datahike/online_gc.cljc +252 -0
  205. package/src/datahike/pod.clj +155 -0
  206. package/src/datahike/pull_api.cljc +325 -0
  207. package/src/datahike/query.cljc +1945 -0
  208. package/src/datahike/query_stats.cljc +88 -0
  209. package/src/datahike/readers.cljc +62 -0
  210. package/src/datahike/remote.cljc +218 -0
  211. package/src/datahike/schema.cljc +228 -0
  212. package/src/datahike/schema_cache.cljc +42 -0
  213. package/src/datahike/spec.cljc +101 -0
  214. package/src/datahike/store.cljc +80 -0
  215. package/src/datahike/tools.cljc +308 -0
  216. package/src/datahike/transit.cljc +80 -0
  217. package/src/datahike/writer.cljc +239 -0
  218. package/src/datahike/writing.cljc +362 -0
  219. package/src/deps.cljs +1 -0
  220. package/src-hitchhiker-tree/datahike/index/hitchhiker_tree/insert.cljc +76 -0
  221. package/src-hitchhiker-tree/datahike/index/hitchhiker_tree/upsert.cljc +128 -0
  222. package/src-hitchhiker-tree/datahike/index/hitchhiker_tree.cljc +213 -0
  223. package/test/datahike/backward_compatibility_test/src/backward_test.clj +37 -0
  224. package/test/datahike/integration_test/config_record_file_test.clj +14 -0
  225. package/test/datahike/integration_test/config_record_test.clj +14 -0
  226. package/test/datahike/integration_test/depr_config_uri_test.clj +15 -0
  227. package/test/datahike/integration_test/return_map_test.clj +62 -0
  228. package/test/datahike/integration_test.cljc +67 -0
  229. package/test/datahike/norm/norm_test.clj +124 -0
  230. package/test/datahike/norm/resources/naming-and-sorting-test/001-a1-example.edn +5 -0
  231. package/test/datahike/norm/resources/naming-and-sorting-test/002-a2-example.edn +5 -0
  232. package/test/datahike/norm/resources/naming-and-sorting-test/003-tx-fn-test.edn +1 -0
  233. package/test/datahike/norm/resources/naming-and-sorting-test/004-tx-data-and-tx-fn-test.edn +5 -0
  234. package/test/datahike/norm/resources/naming-and-sorting-test/01-transact-basic-characters.edn +2 -0
  235. package/test/datahike/norm/resources/naming-and-sorting-test/02 add occupation.edn +5 -0
  236. package/test/datahike/norm/resources/naming-and-sorting-test/checksums.edn +12 -0
  237. package/test/datahike/norm/resources/simple-test/001-a1-example.edn +5 -0
  238. package/test/datahike/norm/resources/simple-test/002-a2-example.edn +5 -0
  239. package/test/datahike/norm/resources/simple-test/checksums.edn +4 -0
  240. package/test/datahike/norm/resources/tx-data-and-tx-fn-test/first/001-a1-example.edn +5 -0
  241. package/test/datahike/norm/resources/tx-data-and-tx-fn-test/first/002-a2-example.edn +5 -0
  242. package/test/datahike/norm/resources/tx-data-and-tx-fn-test/first/003-tx-fn-test.edn +1 -0
  243. package/test/datahike/norm/resources/tx-data-and-tx-fn-test/first/checksums.edn +6 -0
  244. package/test/datahike/norm/resources/tx-data-and-tx-fn-test/second/004-tx-data-and-tx-fn-test.edn +5 -0
  245. package/test/datahike/norm/resources/tx-data-and-tx-fn-test/second/checksums.edn +2 -0
  246. package/test/datahike/norm/resources/tx-fn-test/first/001-a1-example.edn +5 -0
  247. package/test/datahike/norm/resources/tx-fn-test/first/002-a2-example.edn +5 -0
  248. package/test/datahike/norm/resources/tx-fn-test/first/checksums.edn +4 -0
  249. package/test/datahike/norm/resources/tx-fn-test/second/003-tx-fn-test.edn +1 -0
  250. package/test/datahike/norm/resources/tx-fn-test/second/checksums.edn +2 -0
  251. package/test/datahike/test/api_test.cljc +895 -0
  252. package/test/datahike/test/array_test.cljc +40 -0
  253. package/test/datahike/test/attribute_refs/datoms_test.cljc +140 -0
  254. package/test/datahike/test/attribute_refs/db_test.cljc +42 -0
  255. package/test/datahike/test/attribute_refs/differences_test.cljc +515 -0
  256. package/test/datahike/test/attribute_refs/entity_test.cljc +89 -0
  257. package/test/datahike/test/attribute_refs/pull_api_test.cljc +320 -0
  258. package/test/datahike/test/attribute_refs/query_find_specs_test.cljc +59 -0
  259. package/test/datahike/test/attribute_refs/query_fns_test.cljc +130 -0
  260. package/test/datahike/test/attribute_refs/query_interop_test.cljc +47 -0
  261. package/test/datahike/test/attribute_refs/query_not_test.cljc +193 -0
  262. package/test/datahike/test/attribute_refs/query_or_test.cljc +137 -0
  263. package/test/datahike/test/attribute_refs/query_pull_test.cljc +156 -0
  264. package/test/datahike/test/attribute_refs/query_rules_test.cljc +176 -0
  265. package/test/datahike/test/attribute_refs/query_test.cljc +241 -0
  266. package/test/datahike/test/attribute_refs/temporal_search.cljc +22 -0
  267. package/test/datahike/test/attribute_refs/transact_test.cljc +220 -0
  268. package/test/datahike/test/attribute_refs/utils.cljc +128 -0
  269. package/test/datahike/test/cache_test.cljc +38 -0
  270. package/test/datahike/test/components_test.cljc +92 -0
  271. package/test/datahike/test/config_test.cljc +158 -0
  272. package/test/datahike/test/core_test.cljc +105 -0
  273. package/test/datahike/test/datom_test.cljc +44 -0
  274. package/test/datahike/test/db_test.cljc +54 -0
  275. package/test/datahike/test/entity_spec_test.cljc +159 -0
  276. package/test/datahike/test/entity_test.cljc +103 -0
  277. package/test/datahike/test/explode_test.cljc +143 -0
  278. package/test/datahike/test/filter_test.cljc +75 -0
  279. package/test/datahike/test/gc_test.cljc +159 -0
  280. package/test/datahike/test/http/server_test.clj +192 -0
  281. package/test/datahike/test/http/writer_test.clj +86 -0
  282. package/test/datahike/test/ident_test.cljc +32 -0
  283. package/test/datahike/test/index_test.cljc +345 -0
  284. package/test/datahike/test/insert.cljc +125 -0
  285. package/test/datahike/test/java_bindings_test.clj +6 -0
  286. package/test/datahike/test/listen_test.cljc +41 -0
  287. package/test/datahike/test/lookup_refs_test.cljc +266 -0
  288. package/test/datahike/test/lru_test.cljc +27 -0
  289. package/test/datahike/test/migrate_test.clj +297 -0
  290. package/test/datahike/test/model/core.cljc +376 -0
  291. package/test/datahike/test/model/invariant.cljc +142 -0
  292. package/test/datahike/test/model/rng.cljc +82 -0
  293. package/test/datahike/test/model_test.clj +217 -0
  294. package/test/datahike/test/nodejs_test.cljs +262 -0
  295. package/test/datahike/test/online_gc_test.cljc +475 -0
  296. package/test/datahike/test/pod_test.clj +369 -0
  297. package/test/datahike/test/pull_api_test.cljc +474 -0
  298. package/test/datahike/test/purge_test.cljc +144 -0
  299. package/test/datahike/test/query_aggregates_test.cljc +101 -0
  300. package/test/datahike/test/query_find_specs_test.cljc +52 -0
  301. package/test/datahike/test/query_fns_test.cljc +523 -0
  302. package/test/datahike/test/query_interop_test.cljc +47 -0
  303. package/test/datahike/test/query_not_test.cljc +189 -0
  304. package/test/datahike/test/query_or_test.cljc +158 -0
  305. package/test/datahike/test/query_pull_test.cljc +147 -0
  306. package/test/datahike/test/query_rules_test.cljc +248 -0
  307. package/test/datahike/test/query_stats_test.cljc +218 -0
  308. package/test/datahike/test/query_test.cljc +984 -0
  309. package/test/datahike/test/schema_test.cljc +424 -0
  310. package/test/datahike/test/specification_test.cljc +30 -0
  311. package/test/datahike/test/store_test.cljc +78 -0
  312. package/test/datahike/test/stress_test.cljc +57 -0
  313. package/test/datahike/test/time_variance_test.cljc +518 -0
  314. package/test/datahike/test/tools_test.clj +134 -0
  315. package/test/datahike/test/transact_test.cljc +518 -0
  316. package/test/datahike/test/tuples_test.cljc +564 -0
  317. package/test/datahike/test/unstructured_test.cljc +291 -0
  318. package/test/datahike/test/upsert_impl_test.cljc +205 -0
  319. package/test/datahike/test/upsert_test.cljc +363 -0
  320. package/test/datahike/test/utils.cljc +110 -0
  321. package/test/datahike/test/validation_test.cljc +48 -0
  322. package/test/datahike/test/versioning_test.cljc +56 -0
  323. package/test/datahike/test.cljc +66 -0
  324. package/tests.edn +24 -0
@@ -0,0 +1,59 @@
1
+ (ns datahike.impl.libdatahike
2
+ (:require [clojure.edn :as edn]
3
+ [jsonista.core :as j]
4
+ [datahike.json :as json]
5
+ [clj-cbor.core :as cbor]
6
+ [taoensso.timbre :as timbre])
7
+ (:import [datahike.datom Datom]
8
+ [datahike.connector Connection])
9
+ (:gen-class
10
+ :methods [^{:static true} [parseJSON [String] Object]
11
+ ^{:static true} [parseEdn [String] Object]
12
+ ^{:static true} [parseCBOR [bytes] Object]
13
+ ^{:static true} [toEdnString [Object] String]
14
+ ^{:static true} [toJSONString [Object] String]
15
+ ^{:static true} [toCBOR [Object] bytes]
16
+ ^{:static true} [datomsToVecs [Iterable] Iterable]
17
+ ^{:static true} [intoMap [Object] Object]
18
+ ^{:static true} [transformJSONForTx [Object Object] Object]]))
19
+
20
+ (timbre/set-level! :warn)
21
+
22
+ (defn -parseJSON [s]
23
+ (j/read-value s json/mapper))
24
+
25
+ (defn -toJSONString [obj]
26
+ (j/write-value-as-string obj json/mapper))
27
+
28
+ (defn -parseEdn [s]
29
+ (edn/read-string s))
30
+
31
+ (defn -toEdnString [obj]
32
+ (pr-str obj))
33
+
34
+ (defn -parseCBOR [^bytes b]
35
+ (cbor/decode b))
36
+
37
+ (defn ^bytes -toCBOR [edn]
38
+ (cbor/encode edn))
39
+
40
+ (defn -datomsToVecs [datoms]
41
+ (mapv #(vec (seq ^Datom %)) datoms))
42
+
43
+ (defn -intoMap [edn]
44
+ (into {} edn))
45
+
46
+ (defn -transformJSONForTx [tx-data db-or-conn]
47
+ "Transform JSON transaction data based on schema.
48
+ Converts values to appropriate types (e.g., Integer → Long for :db.type/long attributes).
49
+
50
+ Args:
51
+ tx-data: Java List from parseJSON containing transaction data
52
+ db-or-conn: Connection or DB value
53
+
54
+ Returns:
55
+ Transformed tx-data with schema-aware type conversions"
56
+ (let [db (if (instance? Connection db-or-conn)
57
+ @db-or-conn
58
+ db-or-conn)]
59
+ (json/xf-data-for-tx tx-data db)))
@@ -0,0 +1,61 @@
1
+ #include <iostream>
2
+ #include <libdatahike.h>
3
+ #include <assert.h>
4
+
5
+ const char* config_str = "{:store {:backend :file :path \"/tmp/libdatahike-test\" :id #uuid \"f11e0000-0000-0000-0000-000000000001\"} :schema-flexibility :write}";
6
+ const char* schema_str = "[{:db/ident :name :db/valueType :db.type/string :db/cardinality :db.cardinality/one}]";
7
+ const char* tx_str = "[{:name \"Alice\"}]";
8
+ const char* query_str = "[:find ?e ?v :where [?e :name ?v]]";
9
+
10
+ void default_reader(char* edn) {
11
+ std::cout << "result: " << edn << std::endl;
12
+ }
13
+
14
+ void database_exists_reader(char* database_exists_result_edn) {
15
+ std::cout << "database exists result: " << database_exists_result_edn << std::endl;
16
+ std::string true_str = "true";
17
+ assert(true_str.compare(database_exists_result_edn) == 0);
18
+ }
19
+
20
+ void transact_reader(char* transact_result_edn) {
21
+ std::cout << "transact result: " << transact_result_edn << std::endl;
22
+ }
23
+
24
+ void query_reader(char* query_result_edn) {
25
+ std::cout << "query result: " << query_result_edn << std::endl;
26
+ std::string expected_q_result = "#{[2 \"Alice\"]}";
27
+ assert(expected_q_result.compare(query_result_edn) == 0);
28
+ }
29
+
30
+
31
+ int main(int argc, char* argv[]) {
32
+ graal_isolate_t *isolate = NULL;
33
+ graal_isolatethread_t *thread = NULL;
34
+
35
+ if (graal_create_isolate(NULL, &isolate, &thread) != 0) {
36
+ fprintf(stderr, "Initialization error.\n");
37
+ return 1;
38
+ }
39
+
40
+ void (*default_reader_pointer)(char*);
41
+ default_reader_pointer = &default_reader;
42
+ create_database((long)thread, config_str, "edn", (const void*)default_reader_pointer);
43
+
44
+ void (*database_exists_reader_pointer)(char*);
45
+ database_exists_reader_pointer = &database_exists_reader;
46
+ database_exists((long)thread, config_str, "edn", (const void*)database_exists_reader_pointer);
47
+
48
+ void (*transact_reader_pointer)(char*);
49
+ transact_reader_pointer = &transact_reader;
50
+ transact((long)thread, config_str, "edn", schema_str, "edn", (const void*)transact_reader);
51
+ transact((long)thread, config_str, "edn", tx_str, "edn", (const void*)transact_reader);
52
+
53
+ long num_inputs = 1;
54
+ const char *input_format = "db";
55
+ const char *output_format = "edn";
56
+ void (*query_reader_pointer)(char*);
57
+ query_reader_pointer = &query_reader;
58
+ q((long)thread, query_str, num_inputs, &input_format, &config_str,
59
+ output_format, (const void*)query_reader_pointer);
60
+ return 0;
61
+ }
@@ -0,0 +1,140 @@
1
+ # NPM Publication Guide
2
+
3
+ This guide explains how to publish Datahike to npm.
4
+
5
+ ## Prerequisites
6
+
7
+ 1. npm account (create at https://www.npmjs.com/signup)
8
+ 2. Login to npm: `npm login`
9
+
10
+ ## Files Included in Package
11
+
12
+ The `package.json` specifies which files to include:
13
+ - All `.js` files (compiled ClojureScript)
14
+ - All `.js.map` files (source maps)
15
+ - `index.d.ts` (TypeScript definitions)
16
+ - `README.md` (documentation)
17
+ - `LICENSE` (EPL-1.0)
18
+
19
+ ## Pre-Publication Checklist
20
+
21
+ 1. **Build the npm package** (this handles version, types, and compilation)
22
+ ```bash
23
+ bb npm-build
24
+ ```
25
+
26
+ This single command will:
27
+ - Update `package.json` version from `config.edn` (major.minor.commit-count)
28
+ - Regenerate TypeScript definitions
29
+ - Compile ClojureScript with shadow-cljs
30
+
31
+ Alternatively, run individual steps:
32
+ ```bash
33
+ bb npm-version # Update package.json version only
34
+ bb codegen-ts # Generate TypeScript definitions only
35
+ npx shadow-cljs compile npm-release # Compile ClojureScript only
36
+ ```
37
+
38
+ 2. **Run tests**
39
+ ```bash
40
+ cd npm-package
41
+ node test.js
42
+ ```
43
+
44
+ 3. **Verify package contents**
45
+ ```bash
46
+ cd npm-package
47
+ npm pack --dry-run
48
+ ```
49
+
50
+ ## Publishing
51
+
52
+ ### Publish to npm
53
+
54
+ ```bash
55
+ cd npm-package
56
+ npm publish
57
+ ```
58
+
59
+ ### Tag a release
60
+
61
+ After publishing, tag the git commit:
62
+ ```bash
63
+ git tag v0.7.0-alpha1
64
+ git push --tags
65
+ ```
66
+
67
+ ## Post-Publication
68
+
69
+ 1. Verify the package on npm: https://www.npmjs.com/package/datahike
70
+ 2. Test installation: `npm install datahike@latest`
71
+ 3. Create GitHub release with changelog
72
+
73
+ ## Testing the Package Locally
74
+
75
+ Before publishing, test the package locally:
76
+
77
+ ```bash
78
+ # In npm-package directory
79
+ npm pack
80
+
81
+ # This creates datahike-0.7.0-alpha1.tgz
82
+ # In another project:
83
+ npm install /path/to/datahike/npm-package/datahike-0.7.0-alpha1.tgz
84
+ ```
85
+
86
+ ## Version Strategy
87
+
88
+ Datahike uses a **centralized version management** system:
89
+ - **Source of truth**: `config.edn` contains `{:version {:major X :minor Y}}`
90
+ - **Full version**: Automatically calculated as `major.minor.commit-count` (e.g., `0.6.1634`)
91
+ - **Synchronized**: Same version used for JVM (Maven/Clojars), ClojureScript, and npm
92
+
93
+ To increment the version:
94
+ ```bash
95
+ bb inc major # Increment major version (breaking changes)
96
+ bb inc minor # Increment minor version (new features)
97
+ ```
98
+
99
+ The `bb npm-build` command automatically syncs the current version to `package.json`.
100
+
101
+ ## Troubleshooting
102
+
103
+ ### "Module not found" errors
104
+ Check that `package.json` `main` field points to the correct entry file:
105
+ ```json
106
+ "main": "datahike.js.api.js"
107
+ ```
108
+
109
+ ### TypeScript types not recognized
110
+ Ensure `types` field in `package.json` is correct:
111
+ ```json
112
+ "types": "index.d.ts"
113
+ ```
114
+
115
+ ### Missing dependencies
116
+ Datahike is compiled to standalone JavaScript - no runtime dependencies needed.
117
+
118
+ ## Updating the Package
119
+
120
+ 1. Make code changes in ClojureScript source
121
+ 2. Build package: `bb npm-build` (handles compilation, types, and version)
122
+ 3. Update CHANGELOG.md if needed
123
+ 4. Run tests: `node test.js`
124
+ 5. Publish: `npm publish`
125
+
126
+ ## Quick Release Checklist
127
+
128
+ 1. Ensure all changes are committed
129
+ 2. Increment version if needed: `bb inc [major|minor]`
130
+ 3. Build package: `bb npm-build`
131
+ 4. Test: `cd npm-package && node test.js`
132
+ 5. Verify: `npm pack --dry-run`
133
+ 6. Login: `npm login`
134
+ 7. Publish: `npm publish`
135
+
136
+ ## Links
137
+
138
+ - npm package: https://www.npmjs.com/package/datahike
139
+ - npm docs: https://docs.npmjs.com/
140
+ - TypeScript declarations: https://www.typescriptlang.org/docs/handbook/declaration-files/introduction.html
@@ -0,0 +1,226 @@
1
+ # Datahike - JavaScript API
2
+
3
+ Durable Datalog database for JavaScript and Node.js, powered by ClojureScript.
4
+
5
+ ## Features
6
+
7
+ - **Datalog Queries**: Expressive query language inspired by Datomic
8
+ - **Schema Support**: Optional schema with validation
9
+ - **Time Travel**: Access database history and temporal queries
10
+ - **Pluggable Backends**: Memory, file, or custom storage
11
+ - **Promise-based API**: Native JavaScript async/await support
12
+ - **TypeScript Support**: Complete type definitions included
13
+
14
+ ## Installation
15
+
16
+ ```bash
17
+ npm install datahike
18
+ ```
19
+
20
+ ## Quick Start
21
+
22
+ ```javascript
23
+ const d = require('datahike');
24
+ const crypto = require('crypto');
25
+
26
+ async function example() {
27
+ // Create database configuration (requires UUID for :id)
28
+ const config = {
29
+ store: {
30
+ backend: ':memory',
31
+ id: crypto.randomUUID()
32
+ }
33
+ };
34
+
35
+ // Create and connect to database
36
+ await d.createDatabase(config);
37
+ const conn = await d.connect(config);
38
+
39
+ // Define schema
40
+ // Keys: WITHOUT colon, Values: WITH colon
41
+ const schema = [
42
+ {
43
+ 'db/ident': ':name',
44
+ 'db/valueType': ':db.type/string',
45
+ 'db/cardinality': ':db.cardinality/one'
46
+ },
47
+ {
48
+ 'db/ident': ':age',
49
+ 'db/valueType': ':db.type/long',
50
+ 'db/cardinality': ':db.cardinality/one'
51
+ }
52
+ ];
53
+ await d.transact(conn, schema);
54
+
55
+ // Add data (data keys without colons)
56
+ const data = [
57
+ { name: 'Alice', age: 30 },
58
+ { name: 'Bob', age: 25 }
59
+ ];
60
+ await d.transact(conn, data);
61
+
62
+ // Query with Datalog
63
+ const db = await d.db(conn);
64
+ const results = await d.q(
65
+ '[:find ?name ?age :where [?e :name ?name] [?e :age ?age]]',
66
+ db
67
+ );
68
+
69
+ console.log(results); // [['Alice', 30], ['Bob', 25]]
70
+
71
+ // Disconnect
72
+ d.release(conn);
73
+ await d.deleteDatabase(config);
74
+ }
75
+
76
+ example();
77
+ ```
78
+
79
+ ## Documentation
80
+
81
+ ### Configuration
82
+
83
+ **⚠️ Note:** Keyword syntax may change in future versions to simplify the API.
84
+
85
+ ```javascript
86
+ const crypto = require('crypto');
87
+
88
+ const config = {
89
+ store: {
90
+ backend: ':memory', // or ':file'
91
+ id: crypto.randomUUID() // Required: UUID identifier
92
+ },
93
+ // Optional configuration:
94
+ 'keep-history': true, // default: true
95
+ 'schema-flexibility': ':write' // or ':read'
96
+ };
97
+
98
+ // File backend example (Node.js only)
99
+ const fileConfig = {
100
+ store: {
101
+ backend: ':file',
102
+ path: './data'
103
+ }
104
+ };
105
+ ```
106
+
107
+ ### Keywords
108
+
109
+ **Current keyword rules:**
110
+ - **Schema keys**: WITHOUT `:` prefix (`'db/ident'`, not `':db/ident'`)
111
+ - **Schema values**: WITH `:` prefix (`':name'`, `':db.type/string'`)
112
+ - **Data keys**: WITHOUT `:` prefix (`name`, `age`)
113
+ - **Pull patterns**: WITH `:` prefix (`[':name', ':age']`)
114
+
115
+ ### Datalog Queries
116
+
117
+ Queries use EDN string format (Datalog DSL):
118
+
119
+ ```javascript
120
+ // Find relationships
121
+ await d.q('[:find ?e ?name :where [?e :name ?name]]', db);
122
+
123
+ // Find collection
124
+ await d.q('[:find [?name ...] :where [_ :name ?name]]', db);
125
+
126
+ // With predicates
127
+ await d.q('[:find ?name :where [?e :name ?name] [?e :age ?age] [(> ?age 25)]]', db);
128
+
129
+ // Parameterized
130
+ await d.q('[:find ?e :in $ ?name :where [?e :name ?name]]', db, 'Alice');
131
+ ```
132
+
133
+ ### Pull API
134
+
135
+ Retrieve entity data by pattern:
136
+
137
+ ```javascript
138
+ // Pull single entity
139
+ await d.pull(db, ['*'], entityId);
140
+
141
+ // Pull with specific attributes
142
+ await d.pull(db, [':name', ':age'], entityId);
143
+
144
+ // Pull many entities
145
+ await d.pullMany(db, ['*'], [id1, id2, id3]);
146
+ ```
147
+
148
+ ### Transactions
149
+
150
+ Add or retract data:
151
+
152
+ ```javascript
153
+ // Entity maps (data keys without colons)
154
+ const data = [
155
+ { name: 'Charlie', age: 35 }
156
+ ];
157
+ await d.transact(conn, data);
158
+
159
+ // Tuple form
160
+ await d.transact(conn, [
161
+ [':db/add', entityId, ':age', 36]
162
+ ]);
163
+
164
+ // Retract
165
+ await d.transact(conn, [
166
+ [':db/retract', entityId, ':age', 35]
167
+ ]);
168
+ ```
169
+
170
+ ### Temporal Queries
171
+
172
+ Access database history:
173
+
174
+ ```javascript
175
+ // Database at specific time
176
+ const historicalDb = d.asOf(d.db(conn), date);
177
+
178
+ // Full history
179
+ const historyDb = d.history(d.db(conn));
180
+ ```
181
+
182
+ ## API Reference
183
+
184
+ See [TypeScript definitions](index.d.ts) for complete API documentation.
185
+
186
+ ### Core Functions
187
+
188
+ - `createDatabase(config)` - Create new database
189
+ - `deleteDatabase(config)` - Delete database
190
+ - `databaseExists(config)` - Check if database exists
191
+ - `connect(config)` - Connect to database
192
+ - `release(conn)` - Close connection
193
+ - `db(conn)` - Get current database value
194
+ - `transact(conn, txData)` - Execute transaction
195
+ - `q(query, ...args)` - Execute Datalog query
196
+ - `pull(db, pattern, entityId)` - Pull entity by pattern
197
+ - `pullMany(db, pattern, entityIds)` - Pull multiple entities
198
+ - `entity(db, entityId)` - Get entity (returns ClojureScript entity)
199
+ - `datoms(db, index, ...components)` - Access datoms directly
200
+ - `seekDatoms(db, index, ...components)` - Seek in index
201
+ - `schema(db)` - Get database schema
202
+ - `reverse_schema(db)` - Get reverse schema
203
+ - `metrics(db)` - Get database metrics
204
+
205
+ ### Temporal Functions
206
+
207
+ - `asOf(db, timePoint)` - Database at specific time
208
+ - `since(db, timePoint)` - Changes since time
209
+ - `history(db)` - Full database history
210
+
211
+ ## Known Limitations
212
+
213
+ - **Query API**: Requires EDN string format (no JavaScript object syntax)
214
+ - **Entity API**: Returns ClojureScript objects (use Pull API for plain JavaScript objects)
215
+ - **Keyword syntax**: May change in future versions for simplification
216
+ - **Advanced Datalog**: Some advanced features may have limited support
217
+
218
+ ## License
219
+
220
+ Eclipse Public License 1.0
221
+
222
+ ## Links
223
+
224
+ - [GitHub Repository](https://github.com/replikativ/datahike)
225
+ - [Documentation](https://github.com/replikativ/datahike/tree/master/doc)
226
+ - [ClojureScript API Docs](https://cljdoc.org/d/io.replikativ/datahike)
@@ -0,0 +1,34 @@
1
+ {
2
+ "description" : "Durable Datalog database for JavaScript and ClojureScript",
3
+ "engines" : {
4
+ "node" : ">=14.0.0"
5
+ },
6
+ "repository" : {
7
+ "type" : "git",
8
+ "url" : "https://github.com/replikativ/datahike.git"
9
+ },
10
+ "license" : "EPL-1.0",
11
+ "homepage" : "https://github.com/replikativ/datahike",
12
+ "name" : "datahike",
13
+ "scripts" : {
14
+ "test" : "node test.js",
15
+ "test:browser" : "karma start karma.conf.js --single-run"
16
+ },
17
+ "bugs" : {
18
+ "url" : "https://github.com/replikativ/datahike/issues"
19
+ },
20
+ "keywords" : [ "database", "datalog", "datomic", "clojurescript", "immutable", "functional" ],
21
+ "types" : "index.d.ts",
22
+ "author" : "Christian Weilbach",
23
+ "files" : [ "*.js", "*.js.map", "browser/main.js", "browser/cljs-runtime", "index.d.ts", "README.md", "LICENSE" ],
24
+ "version" : "{{VERSION}}",
25
+ "main" : "datahike.js.api.js",
26
+ "exports" : {
27
+ ".": {
28
+ "browser": "./browser/main.js",
29
+ "node": "./datahike.js.api.js",
30
+ "default": "./datahike.js.api.js"
31
+ }
32
+ },
33
+ "browser" : "./browser/main.js"
34
+ }