@lix-js/sdk 0.6.0-preview.5 → 0.6.1

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 (274) hide show
  1. package/README.md +76 -4
  2. package/dist/errors.d.ts +7 -0
  3. package/dist/errors.js +19 -0
  4. package/dist/index.d.ts +4 -5
  5. package/dist/index.js +3 -3
  6. package/dist/native.d.ts +1 -0
  7. package/dist/native.js +47 -0
  8. package/dist/open-lix.d.ts +38 -207
  9. package/dist/open-lix.js +59 -284
  10. package/dist/result.d.ts +18 -0
  11. package/dist/result.js +48 -0
  12. package/dist/types.d.ts +114 -1
  13. package/dist/value.d.ts +28 -0
  14. package/dist/value.js +245 -0
  15. package/package.json +38 -71
  16. package/SKILL.md +0 -507
  17. package/dist/builtin-schemas.d.ts +0 -1
  18. package/dist/builtin-schemas.js +0 -1
  19. package/dist/engine-wasm/index.d.ts +0 -87
  20. package/dist/engine-wasm/index.js +0 -339
  21. package/dist/engine-wasm/wasm/lix_engine.d.ts +0 -79
  22. package/dist/engine-wasm/wasm/lix_engine.js +0 -833
  23. package/dist/engine-wasm/wasm/lix_engine.wasm +0 -0
  24. package/dist/engine-wasm/wasm/lix_engine.wasm.d.ts +0 -27
  25. package/dist/generated/builtin-schemas.d.ts +0 -427
  26. package/dist/generated/builtin-schemas.js +0 -643
  27. package/dist/sqlite/index.d.ts +0 -12
  28. package/dist/sqlite/index.js +0 -359
  29. package/dist-engine-src/README.md +0 -18
  30. package/dist-engine-src/src/backend/capabilities.rs +0 -67
  31. package/dist-engine-src/src/backend/conformance/baseline.rs +0 -1127
  32. package/dist-engine-src/src/backend/conformance/factory.rs +0 -93
  33. package/dist-engine-src/src/backend/conformance/failure_tests.rs +0 -608
  34. package/dist-engine-src/src/backend/conformance/fixtures.rs +0 -26
  35. package/dist-engine-src/src/backend/conformance/mod.rs +0 -75
  36. package/dist-engine-src/src/backend/conformance/model.rs +0 -28
  37. package/dist-engine-src/src/backend/conformance/model_based.rs +0 -257
  38. package/dist-engine-src/src/backend/conformance/persistence.rs +0 -204
  39. package/dist-engine-src/src/backend/conformance/projection.rs +0 -21
  40. package/dist-engine-src/src/backend/conformance/pushdown.rs +0 -24
  41. package/dist-engine-src/src/backend/conformance/runner.rs +0 -90
  42. package/dist-engine-src/src/backend/conformance/scan.rs +0 -24
  43. package/dist-engine-src/src/backend/conformance/write.rs +0 -16
  44. package/dist-engine-src/src/backend/error.rs +0 -94
  45. package/dist-engine-src/src/backend/in_memory.rs +0 -670
  46. package/dist-engine-src/src/backend/mod.rs +0 -39
  47. package/dist-engine-src/src/backend/predicate.rs +0 -80
  48. package/dist-engine-src/src/backend/traits.rs +0 -260
  49. package/dist-engine-src/src/backend/types.rs +0 -239
  50. package/dist-engine-src/src/binary_cas/chunking.rs +0 -31
  51. package/dist-engine-src/src/binary_cas/codec.rs +0 -346
  52. package/dist-engine-src/src/binary_cas/context.rs +0 -139
  53. package/dist-engine-src/src/binary_cas/kv.rs +0 -1038
  54. package/dist-engine-src/src/binary_cas/mod.rs +0 -11
  55. package/dist-engine-src/src/binary_cas/types.rs +0 -121
  56. package/dist-engine-src/src/branch/context.rs +0 -40
  57. package/dist-engine-src/src/branch/lifecycle.rs +0 -221
  58. package/dist-engine-src/src/branch/mod.rs +0 -13
  59. package/dist-engine-src/src/branch/refs.rs +0 -321
  60. package/dist-engine-src/src/branch/stage_rows.rs +0 -67
  61. package/dist-engine-src/src/branch/types.rs +0 -21
  62. package/dist-engine-src/src/catalog/context.rs +0 -412
  63. package/dist-engine-src/src/catalog/mod.rs +0 -10
  64. package/dist-engine-src/src/catalog/schema.rs +0 -4
  65. package/dist-engine-src/src/catalog/snapshot.rs +0 -1114
  66. package/dist-engine-src/src/cel/context.rs +0 -86
  67. package/dist-engine-src/src/cel/error.rs +0 -19
  68. package/dist-engine-src/src/cel/mod.rs +0 -8
  69. package/dist-engine-src/src/cel/provider.rs +0 -9
  70. package/dist-engine-src/src/cel/runtime.rs +0 -167
  71. package/dist-engine-src/src/cel/value.rs +0 -50
  72. package/dist-engine-src/src/changelog/bench_support.rs +0 -785
  73. package/dist-engine-src/src/changelog/change.rs +0 -1
  74. package/dist-engine-src/src/changelog/codec.rs +0 -497
  75. package/dist-engine-src/src/changelog/commit.rs +0 -1
  76. package/dist-engine-src/src/changelog/context.rs +0 -1614
  77. package/dist-engine-src/src/changelog/mod.rs +0 -29
  78. package/dist-engine-src/src/changelog/store.rs +0 -163
  79. package/dist-engine-src/src/changelog/test_support.rs +0 -54
  80. package/dist-engine-src/src/changelog/types.rs +0 -213
  81. package/dist-engine-src/src/commit_graph/context.rs +0 -944
  82. package/dist-engine-src/src/commit_graph/mod.rs +0 -9
  83. package/dist-engine-src/src/commit_graph/types.rs +0 -89
  84. package/dist-engine-src/src/commit_graph/walker.rs +0 -786
  85. package/dist-engine-src/src/common/error.rs +0 -347
  86. package/dist-engine-src/src/common/fingerprint.rs +0 -3
  87. package/dist-engine-src/src/common/fs_path.rs +0 -1336
  88. package/dist-engine-src/src/common/identity.rs +0 -145
  89. package/dist-engine-src/src/common/json_pointer.rs +0 -67
  90. package/dist-engine-src/src/common/metadata.rs +0 -40
  91. package/dist-engine-src/src/common/mod.rs +0 -23
  92. package/dist-engine-src/src/common/types.rs +0 -105
  93. package/dist-engine-src/src/common/wire.rs +0 -222
  94. package/dist-engine-src/src/domain.rs +0 -320
  95. package/dist-engine-src/src/engine.rs +0 -203
  96. package/dist-engine-src/src/entity_pk.rs +0 -402
  97. package/dist-engine-src/src/functions/context.rs +0 -296
  98. package/dist-engine-src/src/functions/deterministic.rs +0 -113
  99. package/dist-engine-src/src/functions/mod.rs +0 -18
  100. package/dist-engine-src/src/functions/provider.rs +0 -130
  101. package/dist-engine-src/src/functions/state.rs +0 -335
  102. package/dist-engine-src/src/functions/types.rs +0 -37
  103. package/dist-engine-src/src/init.rs +0 -692
  104. package/dist-engine-src/src/json_store/compression.rs +0 -77
  105. package/dist-engine-src/src/json_store/context.rs +0 -172
  106. package/dist-engine-src/src/json_store/encoded.rs +0 -15
  107. package/dist-engine-src/src/json_store/mod.rs +0 -38
  108. package/dist-engine-src/src/json_store/store.rs +0 -494
  109. package/dist-engine-src/src/json_store/types.rs +0 -212
  110. package/dist-engine-src/src/lib.rs +0 -92
  111. package/dist-engine-src/src/live_state/context.rs +0 -1883
  112. package/dist-engine-src/src/live_state/mod.rs +0 -21
  113. package/dist-engine-src/src/live_state/overlay.rs +0 -75
  114. package/dist-engine-src/src/live_state/reader.rs +0 -23
  115. package/dist-engine-src/src/live_state/types.rs +0 -231
  116. package/dist-engine-src/src/live_state/visibility.rs +0 -666
  117. package/dist-engine-src/src/plugin/archive.rs +0 -438
  118. package/dist-engine-src/src/plugin/component.rs +0 -183
  119. package/dist-engine-src/src/plugin/install.rs +0 -619
  120. package/dist-engine-src/src/plugin/manifest.rs +0 -516
  121. package/dist-engine-src/src/plugin/materializer.rs +0 -202
  122. package/dist-engine-src/src/plugin/mod.rs +0 -33
  123. package/dist-engine-src/src/plugin/plugin_manifest.json +0 -119
  124. package/dist-engine-src/src/plugin/storage.rs +0 -74
  125. package/dist-engine-src/src/schema/annotations/defaults.rs +0 -275
  126. package/dist-engine-src/src/schema/annotations/mod.rs +0 -1
  127. package/dist-engine-src/src/schema/builtin/lix_account.json +0 -21
  128. package/dist-engine-src/src/schema/builtin/lix_active_account.json +0 -29
  129. package/dist-engine-src/src/schema/builtin/lix_binary_blob_ref.json +0 -29
  130. package/dist-engine-src/src/schema/builtin/lix_branch_descriptor.json +0 -34
  131. package/dist-engine-src/src/schema/builtin/lix_branch_ref.json +0 -48
  132. package/dist-engine-src/src/schema/builtin/lix_change.json +0 -63
  133. package/dist-engine-src/src/schema/builtin/lix_change_author.json +0 -45
  134. package/dist-engine-src/src/schema/builtin/lix_commit.json +0 -24
  135. package/dist-engine-src/src/schema/builtin/lix_commit_edge.json +0 -53
  136. package/dist-engine-src/src/schema/builtin/lix_directory_descriptor.json +0 -52
  137. package/dist-engine-src/src/schema/builtin/lix_file_descriptor.json +0 -52
  138. package/dist-engine-src/src/schema/builtin/lix_key_value.json +0 -40
  139. package/dist-engine-src/src/schema/builtin/lix_label.json +0 -29
  140. package/dist-engine-src/src/schema/builtin/lix_label_assignment.json +0 -74
  141. package/dist-engine-src/src/schema/builtin/lix_registered_schema.json +0 -25
  142. package/dist-engine-src/src/schema/builtin/mod.rs +0 -220
  143. package/dist-engine-src/src/schema/compatibility.rs +0 -787
  144. package/dist-engine-src/src/schema/definition.json +0 -187
  145. package/dist-engine-src/src/schema/definition.rs +0 -742
  146. package/dist-engine-src/src/schema/key.rs +0 -138
  147. package/dist-engine-src/src/schema/mod.rs +0 -20
  148. package/dist-engine-src/src/schema/seed.rs +0 -14
  149. package/dist-engine-src/src/schema/tests.rs +0 -780
  150. package/dist-engine-src/src/session/context.rs +0 -1059
  151. package/dist-engine-src/src/session/create_branch.rs +0 -94
  152. package/dist-engine-src/src/session/execute.rs +0 -681
  153. package/dist-engine-src/src/session/merge/analysis.rs +0 -108
  154. package/dist-engine-src/src/session/merge/branch.rs +0 -417
  155. package/dist-engine-src/src/session/merge/conflicts.rs +0 -63
  156. package/dist-engine-src/src/session/merge/mod.rs +0 -10
  157. package/dist-engine-src/src/session/merge/stats.rs +0 -61
  158. package/dist-engine-src/src/session/mod.rs +0 -30
  159. package/dist-engine-src/src/session/switch_branch.rs +0 -113
  160. package/dist-engine-src/src/session/transaction.rs +0 -557
  161. package/dist-engine-src/src/sql2/bind/classify.rs +0 -102
  162. package/dist-engine-src/src/sql2/bind/error.rs +0 -5
  163. package/dist-engine-src/src/sql2/bind/expr.rs +0 -29
  164. package/dist-engine-src/src/sql2/bind/mod.rs +0 -12
  165. package/dist-engine-src/src/sql2/bind/public_udf.rs +0 -306
  166. package/dist-engine-src/src/sql2/bind/read.rs +0 -65
  167. package/dist-engine-src/src/sql2/bind/statement.rs +0 -2236
  168. package/dist-engine-src/src/sql2/bind/table.rs +0 -273
  169. package/dist-engine-src/src/sql2/bind/write.rs +0 -86
  170. package/dist-engine-src/src/sql2/branch_scope.rs +0 -436
  171. package/dist-engine-src/src/sql2/catalog/capability.rs +0 -20
  172. package/dist-engine-src/src/sql2/catalog/entity_surface.rs +0 -296
  173. package/dist-engine-src/src/sql2/catalog/mod.rs +0 -15
  174. package/dist-engine-src/src/sql2/catalog/registry.rs +0 -556
  175. package/dist-engine-src/src/sql2/catalog/schema.rs +0 -88
  176. package/dist-engine-src/src/sql2/catalog/surface.rs +0 -41
  177. package/dist-engine-src/src/sql2/change_materialization.rs +0 -122
  178. package/dist-engine-src/src/sql2/context.rs +0 -317
  179. package/dist-engine-src/src/sql2/dml.rs +0 -148
  180. package/dist-engine-src/src/sql2/error.rs +0 -215
  181. package/dist-engine-src/src/sql2/exec/bound_public_write.rs +0 -1593
  182. package/dist-engine-src/src/sql2/exec/datafusion.rs +0 -5266
  183. package/dist-engine-src/src/sql2/exec/fast_write.rs +0 -82
  184. package/dist-engine-src/src/sql2/exec/mod.rs +0 -24
  185. package/dist-engine-src/src/sql2/exec/write.rs +0 -661
  186. package/dist-engine-src/src/sql2/filesystem_planner.rs +0 -1485
  187. package/dist-engine-src/src/sql2/filesystem_predicates.rs +0 -159
  188. package/dist-engine-src/src/sql2/filesystem_visibility.rs +0 -383
  189. package/dist-engine-src/src/sql2/history_projection.rs +0 -56
  190. package/dist-engine-src/src/sql2/history_route.rs +0 -661
  191. package/dist-engine-src/src/sql2/mod.rs +0 -52
  192. package/dist-engine-src/src/sql2/optimize/datafusion.rs +0 -1
  193. package/dist-engine-src/src/sql2/optimize/mod.rs +0 -2
  194. package/dist-engine-src/src/sql2/optimize/simple_write.rs +0 -116
  195. package/dist-engine-src/src/sql2/parse/mod.rs +0 -69
  196. package/dist-engine-src/src/sql2/parse/normalize.rs +0 -1
  197. package/dist-engine-src/src/sql2/plan/branch_scope.rs +0 -24
  198. package/dist-engine-src/src/sql2/plan/mod.rs +0 -5
  199. package/dist-engine-src/src/sql2/plan/predicate.rs +0 -22
  200. package/dist-engine-src/src/sql2/plan/write.rs +0 -147
  201. package/dist-engine-src/src/sql2/predicate_typecheck.rs +0 -504
  202. package/dist-engine-src/src/sql2/providers/branch.rs +0 -1206
  203. package/dist-engine-src/src/sql2/providers/change.rs +0 -445
  204. package/dist-engine-src/src/sql2/providers/directory.rs +0 -2422
  205. package/dist-engine-src/src/sql2/providers/directory_history.rs +0 -645
  206. package/dist-engine-src/src/sql2/providers/entity.rs +0 -1484
  207. package/dist-engine-src/src/sql2/providers/entity_history.rs +0 -452
  208. package/dist-engine-src/src/sql2/providers/file.rs +0 -3686
  209. package/dist-engine-src/src/sql2/providers/file_history.rs +0 -924
  210. package/dist-engine-src/src/sql2/providers/history.rs +0 -426
  211. package/dist-engine-src/src/sql2/providers/lix_state.rs +0 -2542
  212. package/dist-engine-src/src/sql2/providers/mod.rs +0 -508
  213. package/dist-engine-src/src/sql2/read_only.rs +0 -63
  214. package/dist-engine-src/src/sql2/record_batch.rs +0 -17
  215. package/dist-engine-src/src/sql2/result_metadata.rs +0 -29
  216. package/dist-engine-src/src/sql2/runtime.rs +0 -60
  217. package/dist-engine-src/src/sql2/session.rs +0 -83
  218. package/dist-engine-src/src/sql2/storage/constraints.rs +0 -1
  219. package/dist-engine-src/src/sql2/storage/mod.rs +0 -1
  220. package/dist-engine-src/src/sql2/test_support/differential.rs +0 -712
  221. package/dist-engine-src/src/sql2/test_support/generators.rs +0 -354
  222. package/dist-engine-src/src/sql2/test_support/mod.rs +0 -2
  223. package/dist-engine-src/src/sql2/udfs/common.rs +0 -295
  224. package/dist-engine-src/src/sql2/udfs/lix_active_branch_commit_id.rs +0 -53
  225. package/dist-engine-src/src/sql2/udfs/lix_empty_blob.rs +0 -47
  226. package/dist-engine-src/src/sql2/udfs/lix_json.rs +0 -100
  227. package/dist-engine-src/src/sql2/udfs/lix_json_get.rs +0 -99
  228. package/dist-engine-src/src/sql2/udfs/lix_json_get_text.rs +0 -99
  229. package/dist-engine-src/src/sql2/udfs/lix_text_decode.rs +0 -82
  230. package/dist-engine-src/src/sql2/udfs/lix_text_encode.rs +0 -85
  231. package/dist-engine-src/src/sql2/udfs/lix_timestamp.rs +0 -76
  232. package/dist-engine-src/src/sql2/udfs/lix_uuid_v7.rs +0 -76
  233. package/dist-engine-src/src/sql2/udfs/mod.rs +0 -86
  234. package/dist-engine-src/src/sql2/write_normalization.rs +0 -368
  235. package/dist-engine-src/src/storage/conformance.rs +0 -399
  236. package/dist-engine-src/src/storage/context.rs +0 -620
  237. package/dist-engine-src/src/storage/mod.rs +0 -52
  238. package/dist-engine-src/src/storage/point.rs +0 -440
  239. package/dist-engine-src/src/storage/read_scope.rs +0 -67
  240. package/dist-engine-src/src/storage/reader.rs +0 -867
  241. package/dist-engine-src/src/storage/scan.rs +0 -784
  242. package/dist-engine-src/src/storage/spaces.rs +0 -236
  243. package/dist-engine-src/src/storage/stats.rs +0 -80
  244. package/dist-engine-src/src/storage/write_set.rs +0 -962
  245. package/dist-engine-src/src/storage_bench.rs +0 -171
  246. package/dist-engine-src/src/test_support.rs +0 -450
  247. package/dist-engine-src/src/tracked_state/bench_support.rs +0 -394
  248. package/dist-engine-src/src/tracked_state/codec.rs +0 -1183
  249. package/dist-engine-src/src/tracked_state/commit_root_rebuild.rs +0 -358
  250. package/dist-engine-src/src/tracked_state/context.rs +0 -2801
  251. package/dist-engine-src/src/tracked_state/diff.rs +0 -2140
  252. package/dist-engine-src/src/tracked_state/merge.rs +0 -478
  253. package/dist-engine-src/src/tracked_state/mod.rs +0 -35
  254. package/dist-engine-src/src/tracked_state/row_materialization.rs +0 -275
  255. package/dist-engine-src/src/tracked_state/storage.rs +0 -427
  256. package/dist-engine-src/src/tracked_state/tree.rs +0 -3063
  257. package/dist-engine-src/src/tracked_state/types.rs +0 -238
  258. package/dist-engine-src/src/transaction/bench_support.rs +0 -407
  259. package/dist-engine-src/src/transaction/commit.rs +0 -1592
  260. package/dist-engine-src/src/transaction/context.rs +0 -1653
  261. package/dist-engine-src/src/transaction/mod.rs +0 -24
  262. package/dist-engine-src/src/transaction/normalization.rs +0 -877
  263. package/dist-engine-src/src/transaction/prep.rs +0 -37
  264. package/dist-engine-src/src/transaction/schema_resolver.rs +0 -163
  265. package/dist-engine-src/src/transaction/staging.rs +0 -1525
  266. package/dist-engine-src/src/transaction/types.rs +0 -403
  267. package/dist-engine-src/src/transaction/validation.rs +0 -5766
  268. package/dist-engine-src/src/untracked_state/codec.rs +0 -615
  269. package/dist-engine-src/src/untracked_state/context.rs +0 -98
  270. package/dist-engine-src/src/untracked_state/materialization.rs +0 -63
  271. package/dist-engine-src/src/untracked_state/mod.rs +0 -15
  272. package/dist-engine-src/src/untracked_state/storage.rs +0 -898
  273. package/dist-engine-src/src/untracked_state/types.rs +0 -146
  274. package/dist-engine-src/src/wasm/mod.rs +0 -60
@@ -1,122 +0,0 @@
1
- use crate::changelog::ChangeRecord;
2
- use crate::entity_pk::EntityPk;
3
- use crate::json_store::{JsonLoadRequestRef, JsonReadScopeRef, JsonRef, JsonStoreReader};
4
- use crate::storage::StorageRead;
5
- use crate::{parse_row_metadata, LixError};
6
-
7
- /// Read-boundary view of a changelog change with JSON refs resolved.
8
- ///
9
- /// `lix_change` materializes direct durable `changelog.change` facts and
10
- /// derived `lix_commit` changes from `changelog.commit`. History surfaces
11
- /// materialize reachability-aware commit-graph changes, while traversal context
12
- /// stays outside this row shape.
13
- #[derive(Debug, Clone, PartialEq, Eq)]
14
- pub(crate) struct MaterializedChange {
15
- pub(crate) id: String,
16
- pub(crate) entity_pk: EntityPk,
17
- pub(crate) schema_key: String,
18
- pub(crate) file_id: Option<String>,
19
- pub(crate) snapshot_content: Option<String>,
20
- pub(crate) metadata: Option<String>,
21
- pub(crate) created_at: String,
22
- }
23
-
24
- pub(crate) async fn materialize_located_history_change<S>(
25
- json_reader: &mut JsonStoreReader<S>,
26
- change: crate::commit_graph::CommitGraphChange,
27
- ) -> Result<MaterializedChange, LixError>
28
- where
29
- S: StorageRead,
30
- {
31
- materialize_commit_graph_change(json_reader, change).await
32
- }
33
-
34
- pub(crate) async fn materialize_changelog_change_record<S>(
35
- json_reader: &mut JsonStoreReader<S>,
36
- change: ChangeRecord,
37
- ) -> Result<MaterializedChange, LixError>
38
- where
39
- S: StorageRead,
40
- {
41
- materialize_commit_graph_change(
42
- json_reader,
43
- crate::commit_graph::CommitGraphChange {
44
- id: change.change_id,
45
- entity_pk: change.entity_pk,
46
- schema_key: change.schema_key,
47
- file_id: change.file_id,
48
- snapshot_ref: change.snapshot_ref,
49
- metadata_ref: change.metadata_ref,
50
- created_at: change.created_at,
51
- },
52
- )
53
- .await
54
- }
55
-
56
- pub(crate) async fn materialize_commit_graph_change<S>(
57
- json_reader: &mut JsonStoreReader<S>,
58
- change: crate::commit_graph::CommitGraphChange,
59
- ) -> Result<MaterializedChange, LixError>
60
- where
61
- S: StorageRead,
62
- {
63
- let snapshot_content = load_optional_changelog_json_text(
64
- json_reader,
65
- change.snapshot_ref.as_ref(),
66
- "snapshot_ref",
67
- )
68
- .await?;
69
- let metadata = match load_optional_changelog_json_text(
70
- json_reader,
71
- change.metadata_ref.as_ref(),
72
- "metadata_ref",
73
- )
74
- .await?
75
- {
76
- Some(value) => Some(parse_row_metadata(&value, "changelog change metadata_ref")?),
77
- None => None,
78
- };
79
- Ok(MaterializedChange {
80
- id: change.id,
81
- entity_pk: change.entity_pk,
82
- schema_key: change.schema_key,
83
- file_id: change.file_id,
84
- snapshot_content,
85
- metadata,
86
- created_at: change.created_at,
87
- })
88
- }
89
-
90
- async fn load_optional_changelog_json_text<S>(
91
- json_reader: &mut JsonStoreReader<S>,
92
- json_ref: Option<&JsonRef>,
93
- field: &str,
94
- ) -> Result<Option<String>, LixError>
95
- where
96
- S: StorageRead,
97
- {
98
- let Some(json_ref) = json_ref else {
99
- return Ok(None);
100
- };
101
- let batch = json_reader
102
- .load_bytes_many(JsonLoadRequestRef {
103
- refs: std::slice::from_ref(json_ref),
104
- scope: JsonReadScopeRef::OutOfBand,
105
- })
106
- .await?;
107
- let Some(bytes) = batch.into_values().into_iter().next().flatten() else {
108
- return Err(LixError::new(
109
- LixError::CODE_INTERNAL_ERROR,
110
- format!(
111
- "changelog change {field} '{}' is missing",
112
- json_ref.to_hex()
113
- ),
114
- ));
115
- };
116
- String::from_utf8(bytes).map(Some).map_err(|error| {
117
- LixError::new(
118
- LixError::CODE_INTERNAL_ERROR,
119
- format!("changelog change {field} is not UTF-8 JSON: {error}"),
120
- )
121
- })
122
- }
@@ -1,317 +0,0 @@
1
- use std::ptr::NonNull;
2
- use std::sync::Arc;
3
-
4
- use async_trait::async_trait;
5
- use serde_json::Value as JsonValue;
6
- use tokio::sync::Mutex;
7
-
8
- use crate::binary_cas::{BlobBytesBatch, BlobDataReader, BlobHash};
9
- use crate::branch::{BranchHead, BranchRefReader};
10
- use crate::commit_graph::CommitGraphReader;
11
- use crate::functions::FunctionProviderHandle;
12
- use crate::json_store::JsonStoreReader;
13
- use crate::live_state::{
14
- LiveStateFilter, LiveStateReader, LiveStateRowRequest, LiveStateScanRequest,
15
- MaterializedLiveStateRow,
16
- };
17
- use crate::storage::StorageRead;
18
- use crate::transaction::types::{TransactionWrite, TransactionWriteOutcome};
19
- use crate::LixError;
20
-
21
- pub(crate) type SqlChangelogQuerySource<S> = ChangelogQuerySource<S>;
22
- pub(crate) type SqlHistoryQuerySource<S> = HistoryQuerySource<S>;
23
- pub(crate) type SqlJsonReader<S> = JsonStoreReader<S>;
24
-
25
- #[derive(Clone)]
26
- pub(crate) struct HistoryQuerySource<S> {
27
- pub(crate) json_reader: JsonStoreReader<S>,
28
- }
29
-
30
- #[derive(Clone)]
31
- pub(crate) struct ChangelogQuerySource<S> {
32
- pub(crate) store: S,
33
- pub(crate) json_reader: JsonStoreReader<S>,
34
- }
35
-
36
- /// Read-only execution boundary for `sql2::execute_sql(...)`.
37
- ///
38
- /// Session and transaction orchestration stay above `sql2`. They provide the
39
- /// execution-scoped committed read context for each call.
40
- ///
41
- /// This trait is for read SQL session construction. Write SQL should use
42
- /// `SqlWriteExecutionContext` so transaction-scoped reads and staging stay in
43
- /// the transaction capability instead of flowing through committed read
44
- /// sources.
45
- #[allow(dead_code)]
46
- pub(crate) trait SqlExecutionContext {
47
- type ReadStore: StorageRead + Clone + Send + Sync + 'static;
48
-
49
- fn active_branch_id(&self) -> &str;
50
- fn live_state(&self) -> Arc<dyn LiveStateReader>;
51
- fn functions(&self) -> FunctionProviderHandle;
52
- fn history_query_source(&self) -> SqlHistoryQuerySource<Self::ReadStore>;
53
- fn changelog_query_source(&self) -> SqlChangelogQuerySource<Self::ReadStore>;
54
- fn commit_graph(&self) -> Box<dyn CommitGraphReader>;
55
- fn branch_ref(&self) -> Arc<dyn BranchRefReader>;
56
- fn blob_reader(&self) -> Arc<dyn BlobDataReader>;
57
- fn list_visible_schemas(&self) -> Result<Vec<JsonValue>, LixError>;
58
- }
59
-
60
- /// Write-capable SQL runtime boundary.
61
- ///
62
- /// Providers that mutate engine state should target this shape instead of
63
- /// reaching through session/backend escape hatches. The request and write
64
- /// payloads stay in the existing engine forms so this boundary centralizes
65
- /// authority without adding another translation layer.
66
- #[async_trait]
67
- #[allow(dead_code)]
68
- pub(crate) trait SqlWriteExecutionContext {
69
- fn active_branch_id(&self) -> &str;
70
- fn functions(&self) -> FunctionProviderHandle;
71
- fn list_visible_schemas(&self) -> Result<Vec<JsonValue>, LixError>;
72
-
73
- async fn load_bytes_many(&mut self, hashes: &[BlobHash]) -> Result<BlobBytesBatch, LixError>;
74
-
75
- async fn scan_live_state(
76
- &mut self,
77
- request: &LiveStateScanRequest,
78
- ) -> Result<Vec<MaterializedLiveStateRow>, LixError>;
79
-
80
- async fn load_branch_head(&mut self, branch_id: &str) -> Result<Option<String>, LixError>;
81
-
82
- async fn stage_write(
83
- &mut self,
84
- write: TransactionWrite,
85
- ) -> Result<TransactionWriteOutcome, LixError>;
86
- }
87
-
88
- #[derive(Clone)]
89
- pub(crate) struct SqlWriteContext {
90
- ptr: Arc<SqlWriteContextPtr>,
91
- gate: Arc<Mutex<()>>,
92
- }
93
-
94
- struct SqlWriteContextPtr(NonNull<dyn SqlWriteExecutionContext>);
95
-
96
- // DataFusion stores providers as owned Send + Sync trait objects. This context
97
- // is only constructed for one write execution and never outlives the borrowed
98
- // transaction context that owns it.
99
- unsafe impl Send for SqlWriteContextPtr {}
100
- unsafe impl Sync for SqlWriteContextPtr {}
101
-
102
- impl SqlWriteContext {
103
- pub(crate) fn new(ctx: &mut dyn SqlWriteExecutionContext) -> Self {
104
- let ptr = NonNull::from(ctx);
105
- let ptr = unsafe {
106
- std::mem::transmute::<
107
- NonNull<dyn SqlWriteExecutionContext + '_>,
108
- NonNull<dyn SqlWriteExecutionContext + 'static>,
109
- >(ptr)
110
- };
111
- Self {
112
- ptr: Arc::new(SqlWriteContextPtr(ptr)),
113
- gate: Arc::new(Mutex::new(())),
114
- }
115
- }
116
-
117
- pub(crate) fn functions(&self) -> FunctionProviderHandle {
118
- unsafe { self.ptr.0.as_ref().functions() }
119
- }
120
-
121
- pub(crate) fn blob_reader(&self) -> Arc<dyn BlobDataReader> {
122
- Arc::new(WriteContextBlobDataReader::new(self.clone()))
123
- }
124
-
125
- pub(crate) fn list_visible_schemas(&self) -> Result<Vec<JsonValue>, LixError> {
126
- unsafe { self.ptr.0.as_ref().list_visible_schemas() }
127
- }
128
-
129
- pub(crate) fn active_branch_id(&self) -> String {
130
- unsafe { self.ptr.0.as_ref().active_branch_id().to_string() }
131
- }
132
-
133
- pub(crate) async fn scan_live_state(
134
- &self,
135
- request: &LiveStateScanRequest,
136
- ) -> Result<Vec<MaterializedLiveStateRow>, LixError> {
137
- let _guard = self.gate.lock().await;
138
- unsafe {
139
- self.ptr
140
- .0
141
- .as_ptr()
142
- .as_mut()
143
- .unwrap()
144
- .scan_live_state(request)
145
- .await
146
- }
147
- }
148
-
149
- pub(crate) async fn load_bytes_many(
150
- &self,
151
- hashes: &[BlobHash],
152
- ) -> Result<BlobBytesBatch, LixError> {
153
- let _guard = self.gate.lock().await;
154
- unsafe {
155
- self.ptr
156
- .0
157
- .as_ptr()
158
- .as_mut()
159
- .unwrap()
160
- .load_bytes_many(hashes)
161
- .await
162
- }
163
- }
164
-
165
- pub(crate) async fn load_branch_head(
166
- &self,
167
- branch_id: &str,
168
- ) -> Result<Option<String>, LixError> {
169
- let _guard = self.gate.lock().await;
170
- unsafe {
171
- self.ptr
172
- .0
173
- .as_ptr()
174
- .as_mut()
175
- .unwrap()
176
- .load_branch_head(branch_id)
177
- .await
178
- }
179
- }
180
-
181
- pub(crate) async fn stage_write(
182
- &self,
183
- write: TransactionWrite,
184
- ) -> Result<TransactionWriteOutcome, LixError> {
185
- let _guard = self.gate.lock().await;
186
- unsafe {
187
- self.ptr
188
- .0
189
- .as_ptr()
190
- .as_mut()
191
- .unwrap()
192
- .stage_write(write)
193
- .await
194
- }
195
- }
196
- }
197
-
198
- pub(crate) struct WriteContextBlobDataReader {
199
- ctx: SqlWriteContext,
200
- }
201
-
202
- impl WriteContextBlobDataReader {
203
- pub(crate) fn new(ctx: SqlWriteContext) -> Self {
204
- Self { ctx }
205
- }
206
- }
207
-
208
- #[async_trait]
209
- impl BlobDataReader for WriteContextBlobDataReader {
210
- async fn load_bytes_many(&self, hashes: &[BlobHash]) -> Result<BlobBytesBatch, LixError> {
211
- self.ctx.load_bytes_many(hashes).await
212
- }
213
- }
214
-
215
- #[derive(Clone)]
216
- pub(crate) enum WriteAccess {
217
- ReadOnly,
218
- Write { ctx: SqlWriteContext },
219
- }
220
-
221
- impl WriteAccess {
222
- pub(crate) fn read_only() -> Self {
223
- Self::ReadOnly
224
- }
225
-
226
- pub(crate) fn write(ctx: SqlWriteContext) -> Self {
227
- Self::Write { ctx }
228
- }
229
-
230
- pub(crate) fn require_write(
231
- &self,
232
- action: &str,
233
- ) -> Result<SqlWriteContext, datafusion::error::DataFusionError> {
234
- match self {
235
- Self::Write { ctx } => Ok(ctx.clone()),
236
- Self::ReadOnly => Err(datafusion::error::DataFusionError::Execution(format!(
237
- "{action} requires a write transaction"
238
- ))),
239
- }
240
- }
241
-
242
- pub(crate) fn is_write(&self) -> bool {
243
- matches!(self, Self::Write { .. })
244
- }
245
- }
246
-
247
- pub(crate) struct WriteContextLiveStateReader {
248
- ctx: SqlWriteContext,
249
- }
250
-
251
- impl WriteContextLiveStateReader {
252
- pub(crate) fn new(ctx: SqlWriteContext) -> Self {
253
- Self { ctx }
254
- }
255
- }
256
-
257
- #[async_trait]
258
- impl LiveStateReader for WriteContextLiveStateReader {
259
- async fn scan_rows(
260
- &self,
261
- request: &LiveStateScanRequest,
262
- ) -> Result<Vec<MaterializedLiveStateRow>, LixError> {
263
- self.ctx.scan_live_state(request).await
264
- }
265
-
266
- async fn load_row(
267
- &self,
268
- request: &LiveStateRowRequest,
269
- ) -> Result<Option<MaterializedLiveStateRow>, LixError> {
270
- let mut rows = self
271
- .ctx
272
- .scan_live_state(&LiveStateScanRequest {
273
- filter: LiveStateFilter {
274
- schema_keys: vec![request.schema_key.clone()],
275
- entity_pks: vec![request.entity_pk.clone()],
276
- branch_ids: vec![request.branch_id.clone()],
277
- file_ids: vec![request.file_id.clone()],
278
- ..LiveStateFilter::default()
279
- },
280
- projection: Default::default(),
281
- limit: Some(1),
282
- })
283
- .await?;
284
- Ok(rows.pop())
285
- }
286
- }
287
-
288
- pub(crate) struct WriteContextBranchRefReader {
289
- ctx: SqlWriteContext,
290
- }
291
-
292
- impl WriteContextBranchRefReader {
293
- pub(crate) fn new(ctx: SqlWriteContext) -> Self {
294
- Self { ctx }
295
- }
296
- }
297
-
298
- #[async_trait]
299
- impl BranchRefReader for WriteContextBranchRefReader {
300
- async fn load_head(&self, branch_id: &str) -> Result<Option<BranchHead>, LixError> {
301
- Ok(self
302
- .ctx
303
- .load_branch_head(branch_id)
304
- .await?
305
- .map(|commit_id| BranchHead {
306
- branch_id: branch_id.to_string(),
307
- commit_id,
308
- }))
309
- }
310
-
311
- async fn scan_heads(&self) -> Result<Vec<BranchHead>, LixError> {
312
- Err(LixError::new(
313
- "LIX_ERROR_UNKNOWN",
314
- "scan_heads is not available through sql2 write context",
315
- ))
316
- }
317
- }
@@ -1,148 +0,0 @@
1
- use std::any::Any;
2
- use std::fmt::Debug;
3
- use std::sync::Arc;
4
-
5
- use async_trait::async_trait;
6
- use datafusion::arrow::array::{ArrayRef, UInt64Array};
7
- use datafusion::arrow::datatypes::{DataType, Field, Schema, SchemaRef};
8
- use datafusion::arrow::record_batch::RecordBatch;
9
- use datafusion::common::{DataFusionError, Result};
10
- use datafusion::execution::TaskContext;
11
- use datafusion::physical_expr::EquivalenceProperties;
12
- use datafusion::physical_plan::execution_plan::{Boundedness, EmissionType, PlanProperties};
13
- use datafusion::physical_plan::stream::RecordBatchStreamAdapter;
14
- use datafusion::physical_plan::{
15
- DisplayAs, DisplayFormatType, ExecutionPlan, Partitioning, SendableRecordBatchStream,
16
- };
17
- use futures_util::stream;
18
-
19
- use super::runtime;
20
-
21
- #[async_trait]
22
- pub(crate) trait InsertSink: Debug + DisplayAs + Send + Sync {
23
- async fn write_batches(
24
- &self,
25
- batches: Vec<RecordBatch>,
26
- context: &Arc<TaskContext>,
27
- ) -> Result<u64>;
28
- }
29
-
30
- pub(crate) struct InsertExec {
31
- input: Arc<dyn ExecutionPlan>,
32
- sink: Arc<dyn InsertSink>,
33
- result_schema: SchemaRef,
34
- properties: Arc<PlanProperties>,
35
- }
36
-
37
- impl InsertExec {
38
- pub(crate) fn new(input: Arc<dyn ExecutionPlan>, sink: Arc<dyn InsertSink>) -> Self {
39
- let result_schema = dml_count_schema();
40
- let properties = PlanProperties::new(
41
- EquivalenceProperties::new(Arc::clone(&result_schema)),
42
- Partitioning::UnknownPartitioning(1),
43
- EmissionType::Final,
44
- Boundedness::Bounded,
45
- );
46
- Self {
47
- input,
48
- sink,
49
- result_schema,
50
- properties: Arc::new(properties),
51
- }
52
- }
53
- }
54
-
55
- impl Debug for InsertExec {
56
- fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
57
- f.debug_struct("InsertExec").finish()
58
- }
59
- }
60
-
61
- impl DisplayAs for InsertExec {
62
- fn fmt_as(&self, t: DisplayFormatType, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
63
- match t {
64
- DisplayFormatType::Default | DisplayFormatType::Verbose => {
65
- write!(f, "InsertExec: sink=")?;
66
- self.sink.fmt_as(t, f)
67
- }
68
- DisplayFormatType::TreeRender => write!(f, "InsertExec"),
69
- }
70
- }
71
- }
72
-
73
- impl ExecutionPlan for InsertExec {
74
- fn name(&self) -> &str {
75
- "InsertExec"
76
- }
77
-
78
- fn as_any(&self) -> &dyn Any {
79
- self
80
- }
81
-
82
- fn properties(&self) -> &Arc<PlanProperties> {
83
- &self.properties
84
- }
85
-
86
- fn children(&self) -> Vec<&Arc<dyn ExecutionPlan>> {
87
- vec![&self.input]
88
- }
89
-
90
- fn with_new_children(
91
- self: Arc<Self>,
92
- mut children: Vec<Arc<dyn ExecutionPlan>>,
93
- ) -> Result<Arc<dyn ExecutionPlan>> {
94
- if children.len() != 1 {
95
- return Err(DataFusionError::Execution(format!(
96
- "InsertExec expects one input child, got {}",
97
- children.len()
98
- )));
99
- }
100
- Ok(Arc::new(Self::new(
101
- children.swap_remove(0),
102
- Arc::clone(&self.sink),
103
- )))
104
- }
105
-
106
- fn execute(
107
- &self,
108
- partition: usize,
109
- context: Arc<TaskContext>,
110
- ) -> Result<SendableRecordBatchStream> {
111
- if partition != 0 {
112
- return Err(DataFusionError::Execution(format!(
113
- "InsertExec only exposes one partition, got {partition}"
114
- )));
115
- }
116
-
117
- let input = Arc::clone(&self.input);
118
- let sink = Arc::clone(&self.sink);
119
- let stream_schema = Arc::clone(&self.result_schema);
120
- let result_schema = Arc::clone(&self.result_schema);
121
- let stream = stream::once(async move {
122
- let batches = runtime::collect_input_plan(input, Arc::clone(&context)).await?;
123
- let count = sink.write_batches(batches, &context).await?;
124
- dml_count_batch(stream_schema, count)
125
- });
126
-
127
- Ok(Box::pin(RecordBatchStreamAdapter::new(
128
- result_schema,
129
- stream,
130
- )))
131
- }
132
- }
133
-
134
- fn dml_count_schema() -> SchemaRef {
135
- Arc::new(Schema::new(vec![Field::new(
136
- "count",
137
- DataType::UInt64,
138
- false,
139
- )]))
140
- }
141
-
142
- fn dml_count_batch(schema: SchemaRef, count: u64) -> Result<RecordBatch> {
143
- RecordBatch::try_new(
144
- schema,
145
- vec![Arc::new(UInt64Array::from(vec![count])) as ArrayRef],
146
- )
147
- .map_err(DataFusionError::from)
148
- }