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,274 @@
1
+ package datahike.java;
2
+
3
+ import java.util.HashMap;
4
+ import java.util.Map;
5
+ import java.util.UUID;
6
+
7
+ /**
8
+ * Fluent builder for Datahike database configurations.
9
+ *
10
+ * <p>Provides a convenient, type-safe way to construct database configurations
11
+ * with method chaining. Supports both simple factory methods for common use cases
12
+ * and detailed configuration through builder methods.</p>
13
+ *
14
+ * <h2>Quick Start</h2>
15
+ * <pre>{@code
16
+ * // In-memory database
17
+ * Map<String, Object> config = Database.memory(UUID.randomUUID())
18
+ * .keepHistory(true)
19
+ * .build();
20
+ *
21
+ * // File-based database
22
+ * Map<String, Object> config = Database.file("/tmp/mydb")
23
+ * .schemaFlexibility(SchemaFlexibility.READ)
24
+ * .build();
25
+ * }</pre>
26
+ *
27
+ * <h2>Configuration Options</h2>
28
+ * <ul>
29
+ * <li>{@link #keepHistory(boolean)} - Enable/disable transaction history (default: true)</li>
30
+ * <li>{@link #schemaFlexibility(SchemaFlexibility)} - Control schema enforcement</li>
31
+ * <li>{@link #initialTx(Object)} - Set initial transaction data (e.g., schema)</li>
32
+ * <li>{@link #name(String)} - Set database name for logging/metrics</li>
33
+ * </ul>
34
+ *
35
+ * @see Datahike
36
+ * @see SchemaFlexibility
37
+ */
38
+ public class Database {
39
+ private final Map<String, Object> store;
40
+ private final Map<String, Object> config;
41
+
42
+ /**
43
+ * Private constructor - use factory methods like {@link #memory(UUID)} or {@link #file(String)}.
44
+ */
45
+ private Database(Map<String, Object> store) {
46
+ this.store = new HashMap<>(store);
47
+ this.config = new HashMap<>();
48
+ }
49
+
50
+ // =========================================================================
51
+ // Factory Methods
52
+ // =========================================================================
53
+
54
+ /**
55
+ * Creates an in-memory database configuration.
56
+ *
57
+ * <p><strong>Important:</strong> Memory backend requires a UUID identifier.
58
+ * This is required by the konserve store and is essential for distributed
59
+ * database tracking.</p>
60
+ *
61
+ * <p>Example:</p>
62
+ * <pre>{@code
63
+ * UUID id = UUID.randomUUID();
64
+ * Map<String, Object> config = Database.memory(id).build();
65
+ * Datahike.createDatabase(config);
66
+ * }</pre>
67
+ *
68
+ * @param id unique UUID identifier for the database
69
+ * @return Database builder for method chaining
70
+ */
71
+ public static Database memory(UUID id) {
72
+ Map<String, Object> store = new HashMap<>();
73
+ store.put("backend", ":memory");
74
+ store.put("id", id);
75
+ return new Database(store);
76
+ }
77
+
78
+ /**
79
+ * Creates an in-memory database configuration from a UUID string.
80
+ *
81
+ * <p>Convenience overload that accepts a string representation of a UUID.
82
+ * The string will be parsed into a UUID object.</p>
83
+ *
84
+ * <p>Example:</p>
85
+ * <pre>{@code
86
+ * String id = UUID.randomUUID().toString();
87
+ * Map<String, Object> config = Database.memory(id).build();
88
+ * }</pre>
89
+ *
90
+ * @param id UUID string (e.g., "550e8400-e29b-41d4-a716-446655440000")
91
+ * @return Database builder for method chaining
92
+ * @throws IllegalArgumentException if the string is not a valid UUID
93
+ */
94
+ public static Database memory(String id) {
95
+ return memory(UUID.fromString(id));
96
+ }
97
+
98
+ /**
99
+ * Creates a file-based database configuration.
100
+ *
101
+ * <p>The file backend persists data to the local filesystem. The path
102
+ * should be a directory where Datahike will store database files.</p>
103
+ *
104
+ * <p>Example:</p>
105
+ * <pre>{@code
106
+ * Map<String, Object> config = Database.file("/var/lib/mydb")
107
+ * .keepHistory(true)
108
+ * .build();
109
+ * Datahike.createDatabase(config);
110
+ * }</pre>
111
+ *
112
+ * @param path filesystem path where database files will be stored
113
+ * @return Database builder for method chaining
114
+ */
115
+ public static Database file(String path) {
116
+ Map<String, Object> store = new HashMap<>();
117
+ store.put("backend", ":file");
118
+ store.put("path", path);
119
+ return new Database(store);
120
+ }
121
+
122
+ /**
123
+ * Creates a custom backend configuration.
124
+ *
125
+ * <p>Use this for backends not covered by the convenience methods,
126
+ * such as PostgreSQL, S3, or custom storage implementations.</p>
127
+ *
128
+ * <p>Example:</p>
129
+ * <pre>{@code
130
+ * Map<String, Object> storeConfig = Map.of(
131
+ * "backend", ":pg",
132
+ * "host", "localhost",
133
+ * "port", 5432,
134
+ * "username", "user",
135
+ * "password", "pass"
136
+ * );
137
+ * Map<String, Object> config = Database.custom(storeConfig).build();
138
+ * }</pre>
139
+ *
140
+ * @param storeConfig map containing backend-specific configuration
141
+ * @return Database builder for method chaining
142
+ */
143
+ public static Database custom(Map<String, Object> storeConfig) {
144
+ return new Database(storeConfig);
145
+ }
146
+
147
+ // =========================================================================
148
+ // Builder Methods
149
+ // =========================================================================
150
+
151
+ /**
152
+ * Sets whether to keep transaction history.
153
+ *
154
+ * <p>When enabled (default), Datahike maintains a full history of all
155
+ * transactions, enabling time-travel queries with {@code asOf} and {@code since}.</p>
156
+ *
157
+ * <p>Disable this for write-heavy workloads where history is not needed,
158
+ * as it reduces storage requirements and improves write performance.</p>
159
+ *
160
+ * @param keep true to keep history (default), false to disable
161
+ * @return this builder for method chaining
162
+ */
163
+ public Database keepHistory(boolean keep) {
164
+ config.put("keep-history?", keep);
165
+ return this;
166
+ }
167
+
168
+ /**
169
+ * Sets the schema flexibility mode.
170
+ *
171
+ * <p>Controls how the database handles attributes not defined in the schema:</p>
172
+ * <ul>
173
+ * <li>{@link SchemaFlexibility#READ} - Allow reading undefined attributes, reject writes</li>
174
+ * <li>{@link SchemaFlexibility#WRITE} - Allow both reading and writing undefined attributes</li>
175
+ * </ul>
176
+ *
177
+ * <p>If not set, the database enforces strict schema validation by default.</p>
178
+ *
179
+ * @param mode the schema flexibility mode
180
+ * @return this builder for method chaining
181
+ */
182
+ public Database schemaFlexibility(SchemaFlexibility mode) {
183
+ config.put("schema-flexibility", mode.toEDNString());
184
+ return this;
185
+ }
186
+
187
+ /**
188
+ * Sets the initial transaction to be applied when creating the database.
189
+ *
190
+ * <p>This is typically used to define the schema before any data is added.
191
+ * The transaction can be provided as:</p>
192
+ * <ul>
193
+ * <li>A Clojure data structure (using {@link Util#vec} and {@link Util#map})</li>
194
+ * <li>An EDN string (parsed with {@link Util#ednFromString})</li>
195
+ * </ul>
196
+ *
197
+ * <p>Example:</p>
198
+ * <pre>{@code
199
+ * import static datahike.java.Util.*;
200
+ * import static datahike.java.Keywords.*;
201
+ *
202
+ * Object schema = vec(
203
+ * map(DB_IDENT, kwd(":person/name"),
204
+ * DB_VALUE_TYPE, STRING,
205
+ * DB_CARDINALITY, ONE)
206
+ * );
207
+ *
208
+ * Map<String, Object> config = Database.memory(UUID.randomUUID())
209
+ * .initialTx(schema)
210
+ * .build();
211
+ * }</pre>
212
+ *
213
+ * @param tx the initial transaction data
214
+ * @return this builder for method chaining
215
+ */
216
+ public Database initialTx(Object tx) {
217
+ config.put("initial-tx", tx);
218
+ return this;
219
+ }
220
+
221
+ /**
222
+ * Sets the database name for logging and metrics.
223
+ *
224
+ * <p>This is optional and used for identifying the database in logs,
225
+ * error messages, and monitoring systems.</p>
226
+ *
227
+ * @param name the database name
228
+ * @return this builder for method chaining
229
+ */
230
+ public Database name(String name) {
231
+ config.put("name", name);
232
+ return this;
233
+ }
234
+
235
+ /**
236
+ * Adds a custom configuration option.
237
+ *
238
+ * <p>Use this for configuration options not covered by the builder methods.
239
+ * Keys are automatically converted to keywords when passed to Datahike.</p>
240
+ *
241
+ * <p>Example:</p>
242
+ * <pre>{@code
243
+ * Map<String, Object> config = Database.file("/tmp/db")
244
+ * .option("attribute-refs?", true)
245
+ * .option("temporal-index", true)
246
+ * .build();
247
+ * }</pre>
248
+ *
249
+ * @param key configuration key (will be keywordized)
250
+ * @param value configuration value
251
+ * @return this builder for method chaining
252
+ */
253
+ public Database option(String key, Object value) {
254
+ config.put(key, value);
255
+ return this;
256
+ }
257
+
258
+ /**
259
+ * Builds and returns the configuration map.
260
+ *
261
+ * <p>The returned map can be passed directly to Datahike API methods like
262
+ * {@link Datahike#createDatabase(Object)}, {@link Datahike#connect(Object)}, etc.</p>
263
+ *
264
+ * <p>The map format matches Datahike's expected configuration structure with
265
+ * keys automatically converted to keywords.</p>
266
+ *
267
+ * @return configuration map ready for use with Datahike API
268
+ */
269
+ public Map<String, Object> build() {
270
+ Map<String, Object> result = new HashMap<>(config);
271
+ result.put("store", store);
272
+ return result;
273
+ }
274
+ }
@@ -0,0 +1,281 @@
1
+ package datahike.java;
2
+
3
+ import clojure.java.api.Clojure;
4
+ import clojure.lang.IFn;
5
+ import clojure.lang.Keyword;
6
+ import clojure.lang.RT;
7
+
8
+ import java.util.*;
9
+
10
+ import static datahike.java.Util.derefFn;
11
+
12
+ /**
13
+ * Public API for Datahike database operations.
14
+ *
15
+ * <p>This class extends DatahikeGenerated to expose all auto-generated API methods
16
+ * from the Datahike specification. Additional convenience methods for Java ergonomics
17
+ * are defined here.</p>
18
+ *
19
+ * <p>Configuration can be constructed using:</p>
20
+ * <ul>
21
+ * <li>{@link #memoryConfig(String)} - In-memory database configuration</li>
22
+ * <li>{@link #fileConfig(String)} - File-based database configuration</li>
23
+ * <li>{@link Util#ednFromString(String)} - Parse EDN configuration strings</li>
24
+ * <li>{@link Util#map(Object...)} and {@link Util#kwd(String)} - Build maps programmatically</li>
25
+ * <li>Java {@code Map<String, Object>} - Direct Java maps (keys auto-converted to keywords)</li>
26
+ * </ul>
27
+ *
28
+ * <p>Example:</p>
29
+ * <pre>{@code
30
+ * // Simple memory database
31
+ * Map<String, Object> config = Datahike.memoryConfig("mydb");
32
+ * Datahike.createDatabase(config);
33
+ * Object conn = Datahike.connect(config);
34
+ *
35
+ * // Or with custom configuration
36
+ * Map<String, Object> customConfig = Map.of(
37
+ * "store", Map.of("backend", ":memory", "id", "mydb"),
38
+ * "schema-flexibility", ":read",
39
+ * "keep-history?", true
40
+ * );
41
+ * Datahike.createDatabase(customConfig);
42
+ * }</pre>
43
+ *
44
+ * @see <a href="https://github.com/replikativ/datahike">Datahike Documentation</a>
45
+ */
46
+ public class Datahike extends DatahikeGenerated {
47
+
48
+ private static final IFn qFn = Clojure.var("datahike.api", "q");
49
+ private static final IFn pullFn = Clojure.var("datahike.api", "pull");
50
+ private static final IFn pullManyFn = Clojure.var("datahike.api", "pull-many");
51
+ private static final IFn seekDatomsFn = Clojure.var("datahike.api", "seek-datoms");
52
+
53
+ /**
54
+ * Forbids instance creation.
55
+ */
56
+ private Datahike() {}
57
+
58
+ // =========================================================================
59
+ // Configuration Helpers
60
+ // =========================================================================
61
+
62
+ /**
63
+ * Creates an in-memory database configuration.
64
+ *
65
+ * <p>Example:</p>
66
+ * <pre>{@code
67
+ * Map<String, Object> config = Datahike.memoryConfig("mydb");
68
+ * Datahike.createDatabase(config);
69
+ * }</pre>
70
+ *
71
+ * @param id unique identifier for the database
72
+ * @return configuration map for in-memory database
73
+ */
74
+ public static Map<String, Object> memoryConfig(String id) {
75
+ Map<String, Object> store = new HashMap<>();
76
+ store.put("backend", ":memory");
77
+ store.put("id", id);
78
+
79
+ Map<String, Object> config = new HashMap<>();
80
+ config.put("store", store);
81
+ return config;
82
+ }
83
+
84
+ /**
85
+ * Creates an in-memory database configuration with additional options.
86
+ *
87
+ * <p>Example:</p>
88
+ * <pre>{@code
89
+ * Map<String, Object> options = new HashMap<>();
90
+ * options.put("schema-flexibility", ":read");
91
+ * options.put("keep-history?", true);
92
+ * Map<String, Object> config = Datahike.memoryConfig("mydb", options);
93
+ * }</pre>
94
+ *
95
+ * @param id unique identifier for the database
96
+ * @param options additional configuration options
97
+ * @return configuration map for in-memory database with options
98
+ */
99
+ public static Map<String, Object> memoryConfig(String id, Map<String, Object> options) {
100
+ Map<String, Object> config = new HashMap<>(options);
101
+
102
+ Map<String, Object> store = new HashMap<>();
103
+ store.put("backend", ":memory");
104
+ store.put("id", id);
105
+ config.put("store", store);
106
+
107
+ return config;
108
+ }
109
+
110
+ /**
111
+ * Creates a file-based database configuration.
112
+ *
113
+ * <p>Example:</p>
114
+ * <pre>{@code
115
+ * Map<String, Object> config = Datahike.fileConfig("/tmp/mydb");
116
+ * Datahike.createDatabase(config);
117
+ * }</pre>
118
+ *
119
+ * @param path file system path for database storage
120
+ * @return configuration map for file-based database
121
+ */
122
+ public static Map<String, Object> fileConfig(String path) {
123
+ Map<String, Object> store = new HashMap<>();
124
+ store.put("backend", ":file");
125
+ store.put("path", path);
126
+
127
+ Map<String, Object> config = new HashMap<>();
128
+ config.put("store", store);
129
+ return config;
130
+ }
131
+
132
+ /**
133
+ * Creates a file-based database configuration with additional options.
134
+ *
135
+ * <p>Example:</p>
136
+ * <pre>{@code
137
+ * Map<String, Object> options = new HashMap<>();
138
+ * options.put("schema-flexibility", ":write");
139
+ * Map<String, Object> config = Datahike.fileConfig("/tmp/mydb", options);
140
+ * }</pre>
141
+ *
142
+ * @param path file system path for database storage
143
+ * @param options additional configuration options
144
+ * @return configuration map for file-based database with options
145
+ */
146
+ public static Map<String, Object> fileConfig(String path, Map<String, Object> options) {
147
+ Map<String, Object> config = new HashMap<>(options);
148
+
149
+ Map<String, Object> store = new HashMap<>();
150
+ store.put("backend", ":file");
151
+ store.put("path", path);
152
+ config.put("store", store);
153
+
154
+ return config;
155
+ }
156
+
157
+ // =========================================================================
158
+ // Convenience Methods
159
+ // =========================================================================
160
+
161
+ /**
162
+ * Dereferences a connection to get the current database value.
163
+ * Equivalent to {@code @conn} in Clojure.
164
+ *
165
+ * @param conn a connection to the database
166
+ * @return the current immutable database value
167
+ */
168
+ public static Object deref(Object conn) {
169
+ return derefFn.invoke(conn);
170
+ }
171
+
172
+ /**
173
+ * Executes a datalog query with automatic query string parsing.
174
+ * This is a convenience method that automatically parses the query string.
175
+ *
176
+ * <p>Example:</p>
177
+ * <pre>{@code
178
+ * Set results = (Set) Datahike.q("[:find ?name :where [?e :name ?name]]", db);
179
+ * }</pre>
180
+ *
181
+ * @param query query string in EDN format
182
+ * @param inputs the database and optional input arguments
183
+ * @return query results (typically a Set of tuples or a scalar value)
184
+ */
185
+ public static Object q(String query, Object... inputs) {
186
+ List<Object> args = new ArrayList<>(Arrays.asList(inputs));
187
+ args.add(0, Clojure.read(query));
188
+ return qFn.applyTo(RT.seq(args));
189
+ }
190
+
191
+ /**
192
+ * Pull pattern query with automatic pattern string parsing.
193
+ * Convenience method that parses the pull pattern from a string.
194
+ *
195
+ * <p>Example:</p>
196
+ * <pre>{@code
197
+ * Map result = Datahike.pull(db, "[:db/id :name :age]", entityId);
198
+ * }</pre>
199
+ *
200
+ * @param db the database
201
+ * @param pattern pull pattern as EDN string
202
+ * @param eid entity id
203
+ * @return map of pulled attributes
204
+ */
205
+ public static Map<?, ?> pull(Object db, String pattern, Object eid) {
206
+ return (Map<?, ?>) pullFn.invoke(db, Clojure.read(pattern), eid);
207
+ }
208
+
209
+ /**
210
+ * Pull many entities with automatic pattern string parsing.
211
+ * Convenience method that parses the pull pattern from a string.
212
+ *
213
+ * <p>Example:</p>
214
+ * <pre>{@code
215
+ * List results = Datahike.pullMany(db, "[:db/id :name]", Arrays.asList(1, 2, 3));
216
+ * }</pre>
217
+ *
218
+ * @param db the database
219
+ * @param pattern pull pattern as EDN string
220
+ * @param eids collection of entity ids
221
+ * @return list of maps with pulled attributes
222
+ */
223
+ public static List<?> pullMany(Object db, String pattern, Iterable<?> eids) {
224
+ return (List<?>) pullManyFn.invoke(db, Clojure.read(pattern), eids);
225
+ }
226
+
227
+ /**
228
+ * Seek datoms with individual component arguments (Java-friendly API).
229
+ * More ergonomic than the map-based API for simple seeks.
230
+ *
231
+ * @param db the database
232
+ * @param index index keyword (e.g., {@code kwd(":eavt")})
233
+ * @param c1 first component (entity id)
234
+ * @return iterable of datoms
235
+ */
236
+ public static Iterable<?> seekdatoms(Object db, Keyword index, Object c1) {
237
+ return (Iterable<?>) seekDatomsFn.invoke(db, index, c1);
238
+ }
239
+
240
+ /**
241
+ * Seek datoms with two component arguments.
242
+ *
243
+ * @param db the database
244
+ * @param index index keyword (e.g., {@code kwd(":eavt")})
245
+ * @param c1 first component (entity id)
246
+ * @param c2 second component (attribute)
247
+ * @return iterable of datoms
248
+ */
249
+ public static Iterable<?> seekdatoms(Object db, Keyword index, Object c1, Object c2) {
250
+ return (Iterable<?>) seekDatomsFn.invoke(db, index, c1, c2);
251
+ }
252
+
253
+ /**
254
+ * Seek datoms with three component arguments.
255
+ *
256
+ * @param db the database
257
+ * @param index index keyword (e.g., {@code kwd(":eavt")})
258
+ * @param c1 first component (entity id)
259
+ * @param c2 second component (attribute)
260
+ * @param c3 third component (value)
261
+ * @return iterable of datoms
262
+ */
263
+ public static Iterable<?> seekdatoms(Object db, Keyword index, Object c1, Object c2, Object c3) {
264
+ return (Iterable<?>) seekDatomsFn.invoke(db, index, c1, c2, c3);
265
+ }
266
+
267
+ /**
268
+ * Seek datoms with four component arguments.
269
+ *
270
+ * @param db the database
271
+ * @param index index keyword (e.g., {@code kwd(":eavt")})
272
+ * @param c1 first component (entity id)
273
+ * @param c2 second component (attribute)
274
+ * @param c3 third component (value)
275
+ * @param c4 fourth component (transaction id)
276
+ * @return iterable of datoms
277
+ */
278
+ public static Iterable<?> seekdatoms(Object db, Keyword index, Object c1, Object c2, Object c3, Object c4) {
279
+ return (Iterable<?>) seekDatomsFn.invoke(db, index, c1, c2, c3, c4);
280
+ }
281
+ }