@lix-js/sdk 0.6.0-preview.5 → 0.6.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 (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,171 +0,0 @@
1
- use std::sync::atomic::{AtomicU64, Ordering};
2
-
3
- use bytes::Bytes;
4
-
5
- use crate::entity_pk::EntityPk;
6
- use crate::storage::{
7
- ScanPlan, StorageCoreProjection, StorageKey, StoragePrefix, StorageProjectedValue, StorageRead,
8
- StorageScanOptions, StorageValue, StorageWriteOptions, StorageWriteSet, StorageWriteSetError,
9
- };
10
- use crate::untracked_state::UntrackedStateRowRef;
11
-
12
- static TRANSACTION_ROWS_STAGED: AtomicU64 = AtomicU64::new(0);
13
- static TRANSACTION_UNTRACKED_ROWS: AtomicU64 = AtomicU64::new(0);
14
- static TRANSACTION_VALIDATION_BRANCHS: AtomicU64 = AtomicU64::new(0);
15
- static TRANSACTION_SCHEMA_CATALOG_LOADS: AtomicU64 = AtomicU64::new(0);
16
- static JSON_STORE_STAGE_BYTES: AtomicU64 = AtomicU64::new(0);
17
-
18
- pub(crate) fn record_transaction_rows_staged(count: usize) {
19
- TRANSACTION_ROWS_STAGED.fetch_add(count as u64, Ordering::Relaxed);
20
- }
21
-
22
- pub(crate) fn record_transaction_untracked_rows(count: usize) {
23
- TRANSACTION_UNTRACKED_ROWS.fetch_add(count as u64, Ordering::Relaxed);
24
- }
25
-
26
- pub(crate) fn record_transaction_validation_branch() {
27
- TRANSACTION_VALIDATION_BRANCHS.fetch_add(1, Ordering::Relaxed);
28
- }
29
-
30
- pub(crate) fn record_transaction_schema_catalog_load() {
31
- TRANSACTION_SCHEMA_CATALOG_LOADS.fetch_add(1, Ordering::Relaxed);
32
- }
33
-
34
- pub(crate) fn record_json_store_stage_bytes(hash: [u8; 32]) {
35
- JSON_STORE_STAGE_BYTES.fetch_add(hash.len() as u64, Ordering::Relaxed);
36
- }
37
-
38
- #[derive(Clone, Debug)]
39
- pub struct StorageLayoutAccounting {
40
- pub space_id: u32,
41
- pub space: &'static str,
42
- pub rows: u64,
43
- pub key_bytes: u64,
44
- pub value_bytes: u64,
45
- }
46
-
47
- pub(crate) fn commit_write_set_for_bench<B>(
48
- storage: &crate::storage::StorageContext<B>,
49
- writes: StorageWriteSet,
50
- ) -> Result<crate::storage::StorageWriteSetStats, StorageWriteSetError>
51
- where
52
- B: crate::storage::StorageBackend,
53
- {
54
- let (_commit, stats) = storage.commit_write_set(writes, StorageWriteOptions::default())?;
55
- Ok(stats)
56
- }
57
-
58
- pub fn layout_accounting<R>(read: &R) -> Vec<StorageLayoutAccounting>
59
- where
60
- R: StorageRead,
61
- {
62
- native_storage_spaces()
63
- .iter()
64
- .map(|space| scan_layout_space(read, *space))
65
- .collect()
66
- }
67
-
68
- fn native_storage_spaces() -> &'static [crate::storage::StorageSpace] {
69
- &[
70
- crate::untracked_state::storage::UNTRACKED_STATE_ROW_SPACE,
71
- crate::json_store::store::JSON_SPACE,
72
- crate::tracked_state::TRACKED_STATE_TREE_CHUNK_SPACE,
73
- crate::tracked_state::TRACKED_STATE_COMMIT_ROOT_SPACE,
74
- crate::binary_cas::kv::BINARY_CAS_MANIFEST_SPACE,
75
- crate::binary_cas::kv::BINARY_CAS_MANIFEST_CHUNK_SPACE,
76
- crate::binary_cas::kv::BINARY_CAS_CHUNK_SPACE,
77
- crate::changelog::COMMIT_SPACE,
78
- crate::changelog::CHANGE_SPACE,
79
- crate::changelog::COMMIT_CHANGE_REF_CHUNK_SPACE,
80
- ]
81
- }
82
-
83
- fn scan_layout_space<R>(read: &R, space: crate::storage::StorageSpace) -> StorageLayoutAccounting
84
- where
85
- R: StorageRead,
86
- {
87
- let result = ScanPlan::prefix(
88
- space,
89
- StoragePrefix {
90
- bytes: Bytes::new(),
91
- },
92
- )
93
- .collect(
94
- read,
95
- StorageScanOptions {
96
- projection: StorageCoreProjection::FullValue,
97
- limit_rows: 1_000_000,
98
- ..StorageScanOptions::default()
99
- },
100
- )
101
- .expect("scan storage bench layout space");
102
-
103
- StorageLayoutAccounting {
104
- space_id: space.id.0,
105
- space: space.name,
106
- rows: result.value.entries.len() as u64,
107
- key_bytes: result
108
- .value
109
- .entries
110
- .iter()
111
- .map(|entry| entry.key.0.len() as u64 + 4)
112
- .sum(),
113
- value_bytes: result
114
- .value
115
- .entries
116
- .iter()
117
- .map(|entry| match &entry.value {
118
- StorageProjectedValue::KeyOnly => 0,
119
- StorageProjectedValue::FullValue(value) => value.len() as u64,
120
- })
121
- .sum(),
122
- }
123
- }
124
-
125
- pub fn untracked_state_row_key_value(
126
- entity_pk: &str,
127
- snapshot_content: &str,
128
- ) -> (StorageKey, StorageValue) {
129
- untracked_state_row_key_value_with_payload(entity_pk, snapshot_content, false)
130
- }
131
-
132
- pub fn untracked_state_full_row_key_value(
133
- entity_pk: &str,
134
- snapshot_content: &str,
135
- ) -> (StorageKey, StorageValue) {
136
- untracked_state_row_key_value_with_payload(entity_pk, snapshot_content, true)
137
- }
138
-
139
- fn untracked_state_row_key_value_with_payload(
140
- entity_pk: &str,
141
- snapshot_content: &str,
142
- include_identity_in_value: bool,
143
- ) -> (StorageKey, StorageValue) {
144
- let entity_pk = EntityPk::single(entity_pk);
145
- let row = UntrackedStateRowRef {
146
- entity_pk: &entity_pk,
147
- schema_key: "json_pointer",
148
- file_id: Some(""),
149
- snapshot_content: Some(snapshot_content),
150
- metadata: None,
151
- created_at: "2026-01-01T00:00:00.000Z",
152
- updated_at: "2026-01-01T00:00:00.000Z",
153
- global: false,
154
- branch_id: "bench-branch",
155
- };
156
- let value = if include_identity_in_value {
157
- crate::untracked_state::codec::encode_row_ref(row).expect("encode untracked bench row")
158
- } else {
159
- crate::untracked_state::codec::encode_payload_ref(row)
160
- .expect("encode untracked bench payload")
161
- };
162
- (
163
- StorageKey(Bytes::from(
164
- crate::untracked_state::storage::encode_untracked_state_row_key_ref(row.into())
165
- .expect("encode untracked bench key"),
166
- )),
167
- StorageValue {
168
- bytes: Bytes::from(value),
169
- },
170
- )
171
- }
@@ -1,450 +0,0 @@
1
- use std::sync::Arc;
2
-
3
- use std::collections::BTreeMap;
4
-
5
- use crate::branch::BranchContext;
6
- use crate::changelog::{
7
- ChangeLoadRequest, ChangeRecord, ChangelogAppend, ChangelogContext, ChangelogReader,
8
- ChangelogWriter, CommitChangeRef, CommitChangeRefSet, CommitRecord,
9
- };
10
- use crate::json_store::{JsonRef, JsonStoreContext, JsonWritePlacementRef, NormalizedJsonRef};
11
- use crate::storage::StorageContext;
12
- use crate::storage::StorageRead;
13
- use crate::storage::StorageWriteSet;
14
- use crate::tracked_state::{
15
- MaterializedTrackedStateRow, TrackedStateContext, TrackedStateDeltaRef,
16
- };
17
- use crate::transaction::prepare_branch_ref_row;
18
- use crate::untracked_state::{
19
- MaterializedUntrackedStateRow, UntrackedStateContext, UntrackedStateRow,
20
- };
21
-
22
- fn prepare_json_ref(value: &str) -> crate::json_store::JsonRef {
23
- crate::json_store::JsonRef::for_content(value.as_bytes())
24
- }
25
- use crate::GLOBAL_BRANCH_ID;
26
-
27
- pub(crate) const TEST_EMPTY_ROOT_COMMIT_ID: &str = "test-empty-root";
28
- const TEST_TIMESTAMP: &str = "1970-01-01T00:00:00.000Z";
29
-
30
- /// Seeds a branch head and matching tracked root for unit tests.
31
- ///
32
- /// A branch ref that points at a commit without a tracked root is invalid for
33
- /// the serving state. This helper keeps that invariant in one place while
34
- /// still letting low-level tests use synthetic commit ids.
35
- pub(crate) async fn seed_branch_head(storage: StorageContext, branch_id: &str, commit_id: &str) {
36
- seed_branch_head_with_rows(storage, branch_id, commit_id, &[]).await;
37
- }
38
-
39
- /// Seeds the global branch head to an empty tracked root for unit tests.
40
- pub(crate) async fn seed_global_branch_head(storage: StorageContext) {
41
- seed_branch_head(storage, GLOBAL_BRANCH_ID, TEST_EMPTY_ROOT_COMMIT_ID).await;
42
- }
43
-
44
- /// Seeds a branch head and writes the tracked root contents for its commit.
45
- pub(crate) async fn seed_branch_head_with_rows(
46
- storage: StorageContext,
47
- branch_id: &str,
48
- commit_id: &str,
49
- rows: &[MaterializedTrackedStateRow],
50
- ) {
51
- let mut read = storage
52
- .begin_read(crate::storage::StorageReadOptions::default())
53
- .expect("seed read should open");
54
- let branch_ctx = BranchContext::new(Arc::new(UntrackedStateContext::new()));
55
- let mut writes = StorageWriteSet::new();
56
- let canonical_row = prepare_branch_ref_row(branch_id, commit_id, TEST_TIMESTAMP)
57
- .expect("branch ref should canonicalize");
58
- branch_ctx
59
- .stage_canonical_ref_rows(&mut writes, &[canonical_row.row])
60
- .expect("branch ref should stage");
61
- stage_tracked_root_from_materialized(
62
- &mut read,
63
- &mut writes,
64
- &TrackedStateContext::new(),
65
- commit_id,
66
- None,
67
- rows,
68
- )
69
- .await
70
- .expect("tracked root should write");
71
- storage
72
- .commit_write_set(writes, crate::storage::StorageWriteOptions::default())
73
- .expect("seed should commit");
74
- }
75
-
76
- pub(crate) async fn stage_tracked_root_from_materialized(
77
- read: &mut (impl StorageRead + Send + Sync + ?Sized),
78
- writes: &mut StorageWriteSet,
79
- tracked_state: &TrackedStateContext,
80
- commit_id: &str,
81
- parent_commit_id: Option<&str>,
82
- rows: &[MaterializedTrackedStateRow],
83
- ) -> Result<(), crate::LixError> {
84
- let changes = rows
85
- .iter()
86
- .map(tracked_change_from_materialized)
87
- .collect::<Result<Vec<_>, _>>()?;
88
- let parent_ids = parent_commit_id
89
- .map(|parent| vec![parent.to_string()])
90
- .unwrap_or_default();
91
- let commit_change_id = format!("{commit_id}:commit");
92
- let staged = stage_test_changelog_commit(
93
- read,
94
- writes,
95
- commit_id,
96
- &commit_change_id,
97
- &parent_ids,
98
- rows,
99
- &changes,
100
- )
101
- .await?;
102
- let commit_snapshot = commit_row_snapshot_content(commit_id)?;
103
- let commit_snapshot_ref = JsonRef::for_content(commit_snapshot.as_bytes());
104
- let commit_entity_pk = crate::entity_pk::EntityPk::single(commit_id);
105
- let mut deltas = staged
106
- .change_commit_ids
107
- .iter()
108
- .map(|(row_index, change_commit_id)| {
109
- let change = &changes[*row_index];
110
- let row = &rows[*row_index];
111
- TrackedStateDeltaRef {
112
- schema_key: &change.schema_key,
113
- file_id: change.file_id.as_deref(),
114
- entity_pk: &change.entity_pk,
115
- change_id: &change.change_id,
116
- commit_id: change_commit_id,
117
- snapshot_ref: change.snapshot_ref.as_ref(),
118
- metadata_ref: change.metadata_ref.as_ref(),
119
- deleted: change.snapshot_ref.is_none(),
120
- created_at: &row.created_at,
121
- updated_at: &row.updated_at,
122
- }
123
- })
124
- .collect::<Vec<_>>();
125
- deltas.push(TrackedStateDeltaRef {
126
- schema_key: "lix_commit",
127
- file_id: None,
128
- entity_pk: &commit_entity_pk,
129
- change_id: &staged.commit_change_id,
130
- commit_id,
131
- snapshot_ref: Some(&commit_snapshot_ref),
132
- metadata_ref: None,
133
- deleted: false,
134
- created_at: &staged.commit_created_at,
135
- updated_at: &staged.commit_created_at,
136
- });
137
- tracked_state
138
- .writer(read, writes)
139
- .stage_commit_root(commit_id, parent_commit_id, deltas)
140
- .await?;
141
- Ok(())
142
- }
143
-
144
- pub(crate) async fn stage_tracked_root_from_materialized_with_parents(
145
- read: &mut (impl StorageRead + Send + Sync + ?Sized),
146
- writes: &mut StorageWriteSet,
147
- tracked_state: &TrackedStateContext,
148
- commit_id: &str,
149
- parent_ids: &[String],
150
- commit_root_parent_commit_id: Option<&str>,
151
- rows: &[MaterializedTrackedStateRow],
152
- ) -> Result<(), crate::LixError> {
153
- let changes = rows
154
- .iter()
155
- .map(tracked_change_from_materialized)
156
- .collect::<Result<Vec<_>, _>>()?;
157
- let commit_change_id = format!("{commit_id}:commit");
158
- let staged = stage_test_changelog_commit(
159
- read,
160
- writes,
161
- commit_id,
162
- &commit_change_id,
163
- parent_ids,
164
- rows,
165
- &changes,
166
- )
167
- .await?;
168
- let commit_snapshot = commit_row_snapshot_content(commit_id)?;
169
- let commit_snapshot_ref = JsonRef::for_content(commit_snapshot.as_bytes());
170
- let commit_entity_pk = crate::entity_pk::EntityPk::single(commit_id);
171
- let mut deltas = staged
172
- .change_commit_ids
173
- .iter()
174
- .map(|(row_index, change_commit_id)| {
175
- let change = &changes[*row_index];
176
- let row = &rows[*row_index];
177
- TrackedStateDeltaRef {
178
- schema_key: &change.schema_key,
179
- file_id: change.file_id.as_deref(),
180
- entity_pk: &change.entity_pk,
181
- change_id: &change.change_id,
182
- commit_id: change_commit_id,
183
- snapshot_ref: change.snapshot_ref.as_ref(),
184
- metadata_ref: change.metadata_ref.as_ref(),
185
- deleted: change.snapshot_ref.is_none(),
186
- created_at: &row.created_at,
187
- updated_at: &row.updated_at,
188
- }
189
- })
190
- .collect::<Vec<_>>();
191
- deltas.push(TrackedStateDeltaRef {
192
- schema_key: "lix_commit",
193
- file_id: None,
194
- entity_pk: &commit_entity_pk,
195
- change_id: &staged.commit_change_id,
196
- commit_id,
197
- snapshot_ref: Some(&commit_snapshot_ref),
198
- metadata_ref: None,
199
- deleted: false,
200
- created_at: &staged.commit_created_at,
201
- updated_at: &staged.commit_created_at,
202
- });
203
- tracked_state
204
- .writer(read, writes)
205
- .stage_commit_root(commit_id, commit_root_parent_commit_id, deltas)
206
- .await?;
207
- Ok(())
208
- }
209
-
210
- pub(crate) async fn stage_empty_changelog_commit(
211
- read: &mut (impl StorageRead + Send + Sync + ?Sized),
212
- writes: &mut StorageWriteSet,
213
- commit_id: &str,
214
- parent_commit_id: Option<&str>,
215
- ) -> Result<(), crate::LixError> {
216
- let parent_ids = parent_commit_id
217
- .map(|parent| vec![parent.to_string()])
218
- .unwrap_or_default();
219
- let commit_change_id = format!("{commit_id}:commit");
220
- stage_test_changelog_commit(
221
- read,
222
- writes,
223
- commit_id,
224
- &commit_change_id,
225
- &parent_ids,
226
- &[],
227
- &[],
228
- )
229
- .await?;
230
- Ok(())
231
- }
232
-
233
- pub(crate) async fn stage_empty_changelog_commit_with_parents(
234
- read: &mut (impl StorageRead + Send + Sync + ?Sized),
235
- writes: &mut StorageWriteSet,
236
- commit_id: &str,
237
- parent_ids: &[String],
238
- ) -> Result<(), crate::LixError> {
239
- let commit_change_id = format!("{commit_id}:commit");
240
- stage_test_changelog_commit(
241
- read,
242
- writes,
243
- commit_id,
244
- &commit_change_id,
245
- parent_ids,
246
- &[],
247
- &[],
248
- )
249
- .await?;
250
- Ok(())
251
- }
252
-
253
- async fn stage_test_changelog_commit(
254
- mut read: &mut (impl StorageRead + Send + Sync + ?Sized),
255
- writes: &mut StorageWriteSet,
256
- commit_id: &str,
257
- commit_change_id: &str,
258
- parent_ids: &[String],
259
- rows: &[MaterializedTrackedStateRow],
260
- changes: &[ChangeRecord],
261
- ) -> Result<TestStagedChangelogCommit, crate::LixError> {
262
- let winner_indices = final_state_row_winner_indices(rows)?;
263
- let winner_change_ids = winner_indices
264
- .iter()
265
- .map(|&index| changes[index].change_id.clone())
266
- .collect::<Vec<_>>();
267
- let existing_change_ids = load_existing_changelog_change_ids(read, &winner_change_ids).await?;
268
- let mut append = ChangelogAppend::default();
269
- let mut refs = Vec::new();
270
- let mut change_commit_ids = Vec::new();
271
- let mut json_payloads = Vec::new();
272
- let mut seen_json_refs = std::collections::BTreeSet::new();
273
- for &row_index in &winner_indices {
274
- let row = &rows[row_index];
275
- let change = &changes[row_index];
276
- if !existing_change_ids.contains(&change.change_id) {
277
- for (json_ref, payload) in json_payloads_from_materialized(row) {
278
- if seen_json_refs.insert(json_ref.as_hash_bytes().to_vec()) {
279
- json_payloads.push((json_ref, payload));
280
- }
281
- }
282
- append.changes.push(change.clone());
283
- }
284
- refs.push(commit_change_ref_from_change(change));
285
- change_commit_ids.push((row_index, row.commit_id.clone()));
286
- }
287
- let commit_snapshot = commit_row_snapshot_content(commit_id)?;
288
- let commit_snapshot_ref = JsonRef::for_content(commit_snapshot.as_bytes());
289
- json_payloads.push((commit_snapshot_ref, commit_snapshot));
290
- stage_json_payloads(writes, &json_payloads)?;
291
- let created_at = rows
292
- .first()
293
- .map(|row| row.created_at.clone())
294
- .unwrap_or_else(|| TEST_TIMESTAMP.to_string());
295
- append.commits.push(CommitRecord {
296
- format_version: 1,
297
- commit_id: commit_id.to_string(),
298
- parent_commit_ids: parent_ids.to_vec(),
299
- change_id: commit_change_id.to_string(),
300
- author_account_ids: Vec::new(),
301
- created_at: created_at.clone(),
302
- });
303
- append.commit_change_refs.push(CommitChangeRefSet {
304
- commit_id: commit_id.to_string(),
305
- entries: refs,
306
- });
307
- let mut writer = ChangelogContext::new().writer(&mut read, writes);
308
- writer.stage_append(append).await?;
309
- change_commit_ids.sort_by_key(|(row_index, _)| *row_index);
310
- Ok(TestStagedChangelogCommit {
311
- change_commit_ids,
312
- commit_change_id: commit_change_id.to_string(),
313
- commit_created_at: created_at,
314
- })
315
- }
316
-
317
- fn commit_row_snapshot_content(commit_id: &str) -> Result<String, crate::LixError> {
318
- serde_json::to_string(&serde_json::json!({
319
- "id": commit_id,
320
- }))
321
- .map_err(|error| {
322
- crate::LixError::new(
323
- crate::LixError::CODE_INTERNAL_ERROR,
324
- format!("failed to encode lix_commit snapshot: {error}"),
325
- )
326
- })
327
- }
328
-
329
- struct TestStagedChangelogCommit {
330
- change_commit_ids: Vec<(usize, String)>,
331
- commit_change_id: String,
332
- commit_created_at: String,
333
- }
334
-
335
- async fn load_existing_changelog_change_ids(
336
- read: &mut (impl StorageRead + Send + Sync + ?Sized),
337
- change_ids: &[String],
338
- ) -> Result<std::collections::BTreeSet<String>, crate::LixError> {
339
- if change_ids.is_empty() {
340
- return Ok(std::collections::BTreeSet::new());
341
- }
342
- let mut unique = change_ids.to_vec();
343
- unique.sort();
344
- unique.dedup();
345
- let mut reader = ChangelogContext::new().reader(&mut *read);
346
- let batch = reader
347
- .load_changes(ChangeLoadRequest {
348
- change_ids: &unique,
349
- })
350
- .await?;
351
- Ok(unique
352
- .into_iter()
353
- .zip(batch.entries)
354
- .filter_map(|(change_id, entry)| entry.map(|_| change_id))
355
- .collect())
356
- }
357
-
358
- fn final_state_row_winner_indices(
359
- rows: &[MaterializedTrackedStateRow],
360
- ) -> Result<Vec<usize>, crate::LixError> {
361
- let mut winners =
362
- BTreeMap::<(String, Option<String>, crate::entity_pk::EntityPk), usize>::new();
363
- for (index, row) in rows.iter().enumerate() {
364
- winners.insert(
365
- (
366
- row.schema_key.clone(),
367
- row.file_id.clone(),
368
- row.entity_pk.clone(),
369
- ),
370
- index,
371
- );
372
- }
373
- let mut indices = winners.into_values().collect::<Vec<_>>();
374
- indices.sort_unstable();
375
- Ok(indices)
376
- }
377
-
378
- fn json_payloads_from_materialized(
379
- row: &MaterializedTrackedStateRow,
380
- ) -> Vec<(crate::json_store::JsonRef, String)> {
381
- let mut payloads = Vec::new();
382
- if let Some(snapshot) = row.snapshot_content.as_deref() {
383
- payloads.push((prepare_json_ref(snapshot), snapshot.to_string()));
384
- }
385
- if let Some(metadata) = row.metadata.as_ref() {
386
- let serialized = crate::serialize_row_metadata(metadata);
387
- payloads.push((prepare_json_ref(&serialized), serialized));
388
- }
389
- payloads
390
- }
391
-
392
- fn stage_json_payloads(
393
- writes: &mut StorageWriteSet,
394
- payloads: &[(crate::json_store::JsonRef, String)],
395
- ) -> Result<(), crate::LixError> {
396
- let payloads = payloads
397
- .iter()
398
- .map(|(json_ref, payload)| NormalizedJsonRef::trusted_prehashed(payload, *json_ref))
399
- .collect::<Vec<_>>();
400
- JsonStoreContext::new().writer().stage_batch(
401
- writes,
402
- JsonWritePlacementRef::OutOfBand,
403
- payloads,
404
- )?;
405
- Ok(())
406
- }
407
-
408
- fn commit_change_ref_from_change(change: &ChangeRecord) -> CommitChangeRef {
409
- CommitChangeRef {
410
- schema_key: change.schema_key.clone(),
411
- file_id: change.file_id.clone(),
412
- entity_pk: change.entity_pk.clone(),
413
- change_id: change.change_id.clone(),
414
- }
415
- }
416
-
417
- pub(crate) fn tracked_change_from_materialized(
418
- row: &MaterializedTrackedStateRow,
419
- ) -> Result<ChangeRecord, crate::LixError> {
420
- Ok(ChangeRecord {
421
- format_version: 1,
422
- change_id: row.change_id.clone(),
423
- entity_pk: row.entity_pk.clone(),
424
- schema_key: row.schema_key.clone(),
425
- file_id: row.file_id.clone(),
426
- snapshot_ref: row.snapshot_content.as_deref().map(prepare_json_ref),
427
- metadata_ref: row.metadata.as_ref().map(|value| {
428
- let serialized = crate::serialize_row_metadata(value);
429
- prepare_json_ref(&serialized)
430
- }),
431
- created_at: row.updated_at.clone(),
432
- })
433
- }
434
-
435
- pub(crate) fn untracked_state_row_from_materialized(
436
- _writes: &mut StorageWriteSet,
437
- row: &MaterializedUntrackedStateRow,
438
- ) -> Result<UntrackedStateRow, crate::LixError> {
439
- Ok(UntrackedStateRow {
440
- entity_pk: row.entity_pk.clone(),
441
- schema_key: row.schema_key.clone(),
442
- file_id: row.file_id.clone(),
443
- snapshot_content: row.snapshot_content.clone(),
444
- metadata: row.metadata.as_ref().map(crate::serialize_row_metadata),
445
- created_at: row.created_at.clone(),
446
- updated_at: row.updated_at.clone(),
447
- global: row.global,
448
- branch_id: row.branch_id.clone(),
449
- })
450
- }