@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.
- package/README.md +76 -4
- package/dist/errors.d.ts +7 -0
- package/dist/errors.js +19 -0
- package/dist/index.d.ts +4 -5
- package/dist/index.js +3 -3
- package/dist/native.d.ts +1 -0
- package/dist/native.js +47 -0
- package/dist/open-lix.d.ts +38 -207
- package/dist/open-lix.js +59 -284
- package/dist/result.d.ts +18 -0
- package/dist/result.js +48 -0
- package/dist/types.d.ts +114 -1
- package/dist/value.d.ts +28 -0
- package/dist/value.js +245 -0
- package/package.json +38 -71
- package/SKILL.md +0 -507
- package/dist/builtin-schemas.d.ts +0 -1
- package/dist/builtin-schemas.js +0 -1
- package/dist/engine-wasm/index.d.ts +0 -87
- package/dist/engine-wasm/index.js +0 -339
- package/dist/engine-wasm/wasm/lix_engine.d.ts +0 -79
- package/dist/engine-wasm/wasm/lix_engine.js +0 -833
- package/dist/engine-wasm/wasm/lix_engine.wasm +0 -0
- package/dist/engine-wasm/wasm/lix_engine.wasm.d.ts +0 -27
- package/dist/generated/builtin-schemas.d.ts +0 -427
- package/dist/generated/builtin-schemas.js +0 -643
- package/dist/sqlite/index.d.ts +0 -12
- package/dist/sqlite/index.js +0 -359
- package/dist-engine-src/README.md +0 -18
- package/dist-engine-src/src/backend/capabilities.rs +0 -67
- package/dist-engine-src/src/backend/conformance/baseline.rs +0 -1127
- package/dist-engine-src/src/backend/conformance/factory.rs +0 -93
- package/dist-engine-src/src/backend/conformance/failure_tests.rs +0 -608
- package/dist-engine-src/src/backend/conformance/fixtures.rs +0 -26
- package/dist-engine-src/src/backend/conformance/mod.rs +0 -75
- package/dist-engine-src/src/backend/conformance/model.rs +0 -28
- package/dist-engine-src/src/backend/conformance/model_based.rs +0 -257
- package/dist-engine-src/src/backend/conformance/persistence.rs +0 -204
- package/dist-engine-src/src/backend/conformance/projection.rs +0 -21
- package/dist-engine-src/src/backend/conformance/pushdown.rs +0 -24
- package/dist-engine-src/src/backend/conformance/runner.rs +0 -90
- package/dist-engine-src/src/backend/conformance/scan.rs +0 -24
- package/dist-engine-src/src/backend/conformance/write.rs +0 -16
- package/dist-engine-src/src/backend/error.rs +0 -94
- package/dist-engine-src/src/backend/in_memory.rs +0 -670
- package/dist-engine-src/src/backend/mod.rs +0 -39
- package/dist-engine-src/src/backend/predicate.rs +0 -80
- package/dist-engine-src/src/backend/traits.rs +0 -260
- package/dist-engine-src/src/backend/types.rs +0 -239
- package/dist-engine-src/src/binary_cas/chunking.rs +0 -31
- package/dist-engine-src/src/binary_cas/codec.rs +0 -346
- package/dist-engine-src/src/binary_cas/context.rs +0 -139
- package/dist-engine-src/src/binary_cas/kv.rs +0 -1038
- package/dist-engine-src/src/binary_cas/mod.rs +0 -11
- package/dist-engine-src/src/binary_cas/types.rs +0 -121
- package/dist-engine-src/src/branch/context.rs +0 -40
- package/dist-engine-src/src/branch/lifecycle.rs +0 -221
- package/dist-engine-src/src/branch/mod.rs +0 -13
- package/dist-engine-src/src/branch/refs.rs +0 -321
- package/dist-engine-src/src/branch/stage_rows.rs +0 -67
- package/dist-engine-src/src/branch/types.rs +0 -21
- package/dist-engine-src/src/catalog/context.rs +0 -412
- package/dist-engine-src/src/catalog/mod.rs +0 -10
- package/dist-engine-src/src/catalog/schema.rs +0 -4
- package/dist-engine-src/src/catalog/snapshot.rs +0 -1114
- package/dist-engine-src/src/cel/context.rs +0 -86
- package/dist-engine-src/src/cel/error.rs +0 -19
- package/dist-engine-src/src/cel/mod.rs +0 -8
- package/dist-engine-src/src/cel/provider.rs +0 -9
- package/dist-engine-src/src/cel/runtime.rs +0 -167
- package/dist-engine-src/src/cel/value.rs +0 -50
- package/dist-engine-src/src/changelog/bench_support.rs +0 -785
- package/dist-engine-src/src/changelog/change.rs +0 -1
- package/dist-engine-src/src/changelog/codec.rs +0 -497
- package/dist-engine-src/src/changelog/commit.rs +0 -1
- package/dist-engine-src/src/changelog/context.rs +0 -1614
- package/dist-engine-src/src/changelog/mod.rs +0 -29
- package/dist-engine-src/src/changelog/store.rs +0 -163
- package/dist-engine-src/src/changelog/test_support.rs +0 -54
- package/dist-engine-src/src/changelog/types.rs +0 -213
- package/dist-engine-src/src/commit_graph/context.rs +0 -944
- package/dist-engine-src/src/commit_graph/mod.rs +0 -9
- package/dist-engine-src/src/commit_graph/types.rs +0 -89
- package/dist-engine-src/src/commit_graph/walker.rs +0 -786
- package/dist-engine-src/src/common/error.rs +0 -347
- package/dist-engine-src/src/common/fingerprint.rs +0 -3
- package/dist-engine-src/src/common/fs_path.rs +0 -1336
- package/dist-engine-src/src/common/identity.rs +0 -145
- package/dist-engine-src/src/common/json_pointer.rs +0 -67
- package/dist-engine-src/src/common/metadata.rs +0 -40
- package/dist-engine-src/src/common/mod.rs +0 -23
- package/dist-engine-src/src/common/types.rs +0 -105
- package/dist-engine-src/src/common/wire.rs +0 -222
- package/dist-engine-src/src/domain.rs +0 -320
- package/dist-engine-src/src/engine.rs +0 -203
- package/dist-engine-src/src/entity_pk.rs +0 -402
- package/dist-engine-src/src/functions/context.rs +0 -296
- package/dist-engine-src/src/functions/deterministic.rs +0 -113
- package/dist-engine-src/src/functions/mod.rs +0 -18
- package/dist-engine-src/src/functions/provider.rs +0 -130
- package/dist-engine-src/src/functions/state.rs +0 -335
- package/dist-engine-src/src/functions/types.rs +0 -37
- package/dist-engine-src/src/init.rs +0 -692
- package/dist-engine-src/src/json_store/compression.rs +0 -77
- package/dist-engine-src/src/json_store/context.rs +0 -172
- package/dist-engine-src/src/json_store/encoded.rs +0 -15
- package/dist-engine-src/src/json_store/mod.rs +0 -38
- package/dist-engine-src/src/json_store/store.rs +0 -494
- package/dist-engine-src/src/json_store/types.rs +0 -212
- package/dist-engine-src/src/lib.rs +0 -92
- package/dist-engine-src/src/live_state/context.rs +0 -1883
- package/dist-engine-src/src/live_state/mod.rs +0 -21
- package/dist-engine-src/src/live_state/overlay.rs +0 -75
- package/dist-engine-src/src/live_state/reader.rs +0 -23
- package/dist-engine-src/src/live_state/types.rs +0 -231
- package/dist-engine-src/src/live_state/visibility.rs +0 -666
- package/dist-engine-src/src/plugin/archive.rs +0 -438
- package/dist-engine-src/src/plugin/component.rs +0 -183
- package/dist-engine-src/src/plugin/install.rs +0 -619
- package/dist-engine-src/src/plugin/manifest.rs +0 -516
- package/dist-engine-src/src/plugin/materializer.rs +0 -202
- package/dist-engine-src/src/plugin/mod.rs +0 -33
- package/dist-engine-src/src/plugin/plugin_manifest.json +0 -119
- package/dist-engine-src/src/plugin/storage.rs +0 -74
- package/dist-engine-src/src/schema/annotations/defaults.rs +0 -275
- package/dist-engine-src/src/schema/annotations/mod.rs +0 -1
- package/dist-engine-src/src/schema/builtin/lix_account.json +0 -21
- package/dist-engine-src/src/schema/builtin/lix_active_account.json +0 -29
- package/dist-engine-src/src/schema/builtin/lix_binary_blob_ref.json +0 -29
- package/dist-engine-src/src/schema/builtin/lix_branch_descriptor.json +0 -34
- package/dist-engine-src/src/schema/builtin/lix_branch_ref.json +0 -48
- package/dist-engine-src/src/schema/builtin/lix_change.json +0 -63
- package/dist-engine-src/src/schema/builtin/lix_change_author.json +0 -45
- package/dist-engine-src/src/schema/builtin/lix_commit.json +0 -24
- package/dist-engine-src/src/schema/builtin/lix_commit_edge.json +0 -53
- package/dist-engine-src/src/schema/builtin/lix_directory_descriptor.json +0 -52
- package/dist-engine-src/src/schema/builtin/lix_file_descriptor.json +0 -52
- package/dist-engine-src/src/schema/builtin/lix_key_value.json +0 -40
- package/dist-engine-src/src/schema/builtin/lix_label.json +0 -29
- package/dist-engine-src/src/schema/builtin/lix_label_assignment.json +0 -74
- package/dist-engine-src/src/schema/builtin/lix_registered_schema.json +0 -25
- package/dist-engine-src/src/schema/builtin/mod.rs +0 -220
- package/dist-engine-src/src/schema/compatibility.rs +0 -787
- package/dist-engine-src/src/schema/definition.json +0 -187
- package/dist-engine-src/src/schema/definition.rs +0 -742
- package/dist-engine-src/src/schema/key.rs +0 -138
- package/dist-engine-src/src/schema/mod.rs +0 -20
- package/dist-engine-src/src/schema/seed.rs +0 -14
- package/dist-engine-src/src/schema/tests.rs +0 -780
- package/dist-engine-src/src/session/context.rs +0 -1059
- package/dist-engine-src/src/session/create_branch.rs +0 -94
- package/dist-engine-src/src/session/execute.rs +0 -681
- package/dist-engine-src/src/session/merge/analysis.rs +0 -108
- package/dist-engine-src/src/session/merge/branch.rs +0 -417
- package/dist-engine-src/src/session/merge/conflicts.rs +0 -63
- package/dist-engine-src/src/session/merge/mod.rs +0 -10
- package/dist-engine-src/src/session/merge/stats.rs +0 -61
- package/dist-engine-src/src/session/mod.rs +0 -30
- package/dist-engine-src/src/session/switch_branch.rs +0 -113
- package/dist-engine-src/src/session/transaction.rs +0 -557
- package/dist-engine-src/src/sql2/bind/classify.rs +0 -102
- package/dist-engine-src/src/sql2/bind/error.rs +0 -5
- package/dist-engine-src/src/sql2/bind/expr.rs +0 -29
- package/dist-engine-src/src/sql2/bind/mod.rs +0 -12
- package/dist-engine-src/src/sql2/bind/public_udf.rs +0 -306
- package/dist-engine-src/src/sql2/bind/read.rs +0 -65
- package/dist-engine-src/src/sql2/bind/statement.rs +0 -2236
- package/dist-engine-src/src/sql2/bind/table.rs +0 -273
- package/dist-engine-src/src/sql2/bind/write.rs +0 -86
- package/dist-engine-src/src/sql2/branch_scope.rs +0 -436
- package/dist-engine-src/src/sql2/catalog/capability.rs +0 -20
- package/dist-engine-src/src/sql2/catalog/entity_surface.rs +0 -296
- package/dist-engine-src/src/sql2/catalog/mod.rs +0 -15
- package/dist-engine-src/src/sql2/catalog/registry.rs +0 -556
- package/dist-engine-src/src/sql2/catalog/schema.rs +0 -88
- package/dist-engine-src/src/sql2/catalog/surface.rs +0 -41
- package/dist-engine-src/src/sql2/change_materialization.rs +0 -122
- package/dist-engine-src/src/sql2/context.rs +0 -317
- package/dist-engine-src/src/sql2/dml.rs +0 -148
- package/dist-engine-src/src/sql2/error.rs +0 -215
- package/dist-engine-src/src/sql2/exec/bound_public_write.rs +0 -1593
- package/dist-engine-src/src/sql2/exec/datafusion.rs +0 -5266
- package/dist-engine-src/src/sql2/exec/fast_write.rs +0 -82
- package/dist-engine-src/src/sql2/exec/mod.rs +0 -24
- package/dist-engine-src/src/sql2/exec/write.rs +0 -661
- package/dist-engine-src/src/sql2/filesystem_planner.rs +0 -1485
- package/dist-engine-src/src/sql2/filesystem_predicates.rs +0 -159
- package/dist-engine-src/src/sql2/filesystem_visibility.rs +0 -383
- package/dist-engine-src/src/sql2/history_projection.rs +0 -56
- package/dist-engine-src/src/sql2/history_route.rs +0 -661
- package/dist-engine-src/src/sql2/mod.rs +0 -52
- package/dist-engine-src/src/sql2/optimize/datafusion.rs +0 -1
- package/dist-engine-src/src/sql2/optimize/mod.rs +0 -2
- package/dist-engine-src/src/sql2/optimize/simple_write.rs +0 -116
- package/dist-engine-src/src/sql2/parse/mod.rs +0 -69
- package/dist-engine-src/src/sql2/parse/normalize.rs +0 -1
- package/dist-engine-src/src/sql2/plan/branch_scope.rs +0 -24
- package/dist-engine-src/src/sql2/plan/mod.rs +0 -5
- package/dist-engine-src/src/sql2/plan/predicate.rs +0 -22
- package/dist-engine-src/src/sql2/plan/write.rs +0 -147
- package/dist-engine-src/src/sql2/predicate_typecheck.rs +0 -504
- package/dist-engine-src/src/sql2/providers/branch.rs +0 -1206
- package/dist-engine-src/src/sql2/providers/change.rs +0 -445
- package/dist-engine-src/src/sql2/providers/directory.rs +0 -2422
- package/dist-engine-src/src/sql2/providers/directory_history.rs +0 -645
- package/dist-engine-src/src/sql2/providers/entity.rs +0 -1484
- package/dist-engine-src/src/sql2/providers/entity_history.rs +0 -452
- package/dist-engine-src/src/sql2/providers/file.rs +0 -3686
- package/dist-engine-src/src/sql2/providers/file_history.rs +0 -924
- package/dist-engine-src/src/sql2/providers/history.rs +0 -426
- package/dist-engine-src/src/sql2/providers/lix_state.rs +0 -2542
- package/dist-engine-src/src/sql2/providers/mod.rs +0 -508
- package/dist-engine-src/src/sql2/read_only.rs +0 -63
- package/dist-engine-src/src/sql2/record_batch.rs +0 -17
- package/dist-engine-src/src/sql2/result_metadata.rs +0 -29
- package/dist-engine-src/src/sql2/runtime.rs +0 -60
- package/dist-engine-src/src/sql2/session.rs +0 -83
- package/dist-engine-src/src/sql2/storage/constraints.rs +0 -1
- package/dist-engine-src/src/sql2/storage/mod.rs +0 -1
- package/dist-engine-src/src/sql2/test_support/differential.rs +0 -712
- package/dist-engine-src/src/sql2/test_support/generators.rs +0 -354
- package/dist-engine-src/src/sql2/test_support/mod.rs +0 -2
- package/dist-engine-src/src/sql2/udfs/common.rs +0 -295
- package/dist-engine-src/src/sql2/udfs/lix_active_branch_commit_id.rs +0 -53
- package/dist-engine-src/src/sql2/udfs/lix_empty_blob.rs +0 -47
- package/dist-engine-src/src/sql2/udfs/lix_json.rs +0 -100
- package/dist-engine-src/src/sql2/udfs/lix_json_get.rs +0 -99
- package/dist-engine-src/src/sql2/udfs/lix_json_get_text.rs +0 -99
- package/dist-engine-src/src/sql2/udfs/lix_text_decode.rs +0 -82
- package/dist-engine-src/src/sql2/udfs/lix_text_encode.rs +0 -85
- package/dist-engine-src/src/sql2/udfs/lix_timestamp.rs +0 -76
- package/dist-engine-src/src/sql2/udfs/lix_uuid_v7.rs +0 -76
- package/dist-engine-src/src/sql2/udfs/mod.rs +0 -86
- package/dist-engine-src/src/sql2/write_normalization.rs +0 -368
- package/dist-engine-src/src/storage/conformance.rs +0 -399
- package/dist-engine-src/src/storage/context.rs +0 -620
- package/dist-engine-src/src/storage/mod.rs +0 -52
- package/dist-engine-src/src/storage/point.rs +0 -440
- package/dist-engine-src/src/storage/read_scope.rs +0 -67
- package/dist-engine-src/src/storage/reader.rs +0 -867
- package/dist-engine-src/src/storage/scan.rs +0 -784
- package/dist-engine-src/src/storage/spaces.rs +0 -236
- package/dist-engine-src/src/storage/stats.rs +0 -80
- package/dist-engine-src/src/storage/write_set.rs +0 -962
- package/dist-engine-src/src/storage_bench.rs +0 -171
- package/dist-engine-src/src/test_support.rs +0 -450
- package/dist-engine-src/src/tracked_state/bench_support.rs +0 -394
- package/dist-engine-src/src/tracked_state/codec.rs +0 -1183
- package/dist-engine-src/src/tracked_state/commit_root_rebuild.rs +0 -358
- package/dist-engine-src/src/tracked_state/context.rs +0 -2801
- package/dist-engine-src/src/tracked_state/diff.rs +0 -2140
- package/dist-engine-src/src/tracked_state/merge.rs +0 -478
- package/dist-engine-src/src/tracked_state/mod.rs +0 -35
- package/dist-engine-src/src/tracked_state/row_materialization.rs +0 -275
- package/dist-engine-src/src/tracked_state/storage.rs +0 -427
- package/dist-engine-src/src/tracked_state/tree.rs +0 -3063
- package/dist-engine-src/src/tracked_state/types.rs +0 -238
- package/dist-engine-src/src/transaction/bench_support.rs +0 -407
- package/dist-engine-src/src/transaction/commit.rs +0 -1592
- package/dist-engine-src/src/transaction/context.rs +0 -1653
- package/dist-engine-src/src/transaction/mod.rs +0 -24
- package/dist-engine-src/src/transaction/normalization.rs +0 -877
- package/dist-engine-src/src/transaction/prep.rs +0 -37
- package/dist-engine-src/src/transaction/schema_resolver.rs +0 -163
- package/dist-engine-src/src/transaction/staging.rs +0 -1525
- package/dist-engine-src/src/transaction/types.rs +0 -403
- package/dist-engine-src/src/transaction/validation.rs +0 -5766
- package/dist-engine-src/src/untracked_state/codec.rs +0 -615
- package/dist-engine-src/src/untracked_state/context.rs +0 -98
- package/dist-engine-src/src/untracked_state/materialization.rs +0 -63
- package/dist-engine-src/src/untracked_state/mod.rs +0 -15
- package/dist-engine-src/src/untracked_state/storage.rs +0 -898
- package/dist-engine-src/src/untracked_state/types.rs +0 -146
- package/dist-engine-src/src/wasm/mod.rs +0 -60
|
@@ -1,944 +0,0 @@
|
|
|
1
|
-
use std::collections::BTreeSet;
|
|
2
|
-
|
|
3
|
-
use crate::changelog::{
|
|
4
|
-
ChangeLoadRequest, ChangeRecord, ChangelogContext, ChangelogReader, CommitLoadEntry,
|
|
5
|
-
CommitLoadRequest, CommitProjection, CommitRecord, CommitScanRequest,
|
|
6
|
-
};
|
|
7
|
-
use crate::commit_graph::walker::{best_common_ancestors, walk_reachable_commits};
|
|
8
|
-
use crate::commit_graph::{
|
|
9
|
-
CommitGraphChange, CommitGraphChangeHistoryEntry, CommitGraphChangeHistoryRequest,
|
|
10
|
-
CommitGraphCommit, CommitGraphEdge, CommitGraphReader, ReachableCommitGraphCommit,
|
|
11
|
-
};
|
|
12
|
-
use crate::entity_pk::EntityPk;
|
|
13
|
-
use crate::storage::StorageRead;
|
|
14
|
-
use crate::LixError;
|
|
15
|
-
|
|
16
|
-
const COMMIT_SCHEMA_KEY: &str = "lix_commit";
|
|
17
|
-
|
|
18
|
-
/// Read model for resolving changelog commits into entity state at a head.
|
|
19
|
-
///
|
|
20
|
-
/// This module does not own durable storage. It reads immutable changelog
|
|
21
|
-
/// facts through a caller-provided KV store and applies commit graph rules on
|
|
22
|
-
/// top.
|
|
23
|
-
#[derive(Clone)]
|
|
24
|
-
pub(crate) struct CommitGraphContext;
|
|
25
|
-
|
|
26
|
-
impl CommitGraphContext {
|
|
27
|
-
pub(crate) fn new() -> Self {
|
|
28
|
-
Self
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/// Creates a graph reader over a caller-provided KV store.
|
|
32
|
-
pub(crate) fn reader<S>(&self, store: S) -> CommitGraphStoreReader<S>
|
|
33
|
-
where
|
|
34
|
-
S: StorageRead + Send + Sync,
|
|
35
|
-
{
|
|
36
|
-
CommitGraphStoreReader { store }
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/// Commit-graph reader that resolves changelog entities at a commit head.
|
|
41
|
-
pub(crate) struct CommitGraphStoreReader<S>
|
|
42
|
-
where
|
|
43
|
-
S: StorageRead + Send + Sync,
|
|
44
|
-
{
|
|
45
|
-
store: S,
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
impl<S> CommitGraphStoreReader<S>
|
|
49
|
-
where
|
|
50
|
-
S: StorageRead + Send + Sync,
|
|
51
|
-
{
|
|
52
|
-
/// Loads and parses a `lix_commit` canonical change by commit id.
|
|
53
|
-
pub(crate) async fn load_commit(
|
|
54
|
-
&mut self,
|
|
55
|
-
commit_id: &str,
|
|
56
|
-
) -> Result<Option<CommitGraphCommit>, LixError> {
|
|
57
|
-
self.load_changelog_commit(commit_id).await
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/// Loads every direct commit fact from the changelog.
|
|
61
|
-
///
|
|
62
|
-
/// This is used by global commit surfaces where the caller wants the durable
|
|
63
|
-
/// graph facts themselves, not reachability from a particular branch head.
|
|
64
|
-
pub(crate) async fn all_commits(&mut self) -> Result<Vec<CommitGraphCommit>, LixError> {
|
|
65
|
-
let mut commits = Vec::new();
|
|
66
|
-
let mut start_after = None::<String>;
|
|
67
|
-
loop {
|
|
68
|
-
let mut reader = ChangelogContext::new().reader(&self.store);
|
|
69
|
-
let scan = reader
|
|
70
|
-
.scan_commits(CommitScanRequest {
|
|
71
|
-
start_after: start_after.as_deref(),
|
|
72
|
-
limit: Some(1024),
|
|
73
|
-
projection: CommitProjection::Record,
|
|
74
|
-
})
|
|
75
|
-
.await?;
|
|
76
|
-
for entry in scan.entries {
|
|
77
|
-
let CommitLoadEntry::Record(record) = entry else {
|
|
78
|
-
return Err(LixError::new(
|
|
79
|
-
LixError::CODE_INTERNAL_ERROR,
|
|
80
|
-
"changelog commit scan returned non-record entry",
|
|
81
|
-
));
|
|
82
|
-
};
|
|
83
|
-
commits.push(commit_graph_commit_from_commit_record(record, Vec::new()));
|
|
84
|
-
}
|
|
85
|
-
let Some(next) = scan.next_start_after else {
|
|
86
|
-
break;
|
|
87
|
-
};
|
|
88
|
-
start_after = Some(next);
|
|
89
|
-
}
|
|
90
|
-
commits.sort_by(|left, right| left.commit_id.cmp(&right.commit_id));
|
|
91
|
-
Ok(commits)
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
/// Walks from `head_commit_id` through parent commits and records nearest depth.
|
|
95
|
-
pub(crate) async fn reachable_commits(
|
|
96
|
-
&mut self,
|
|
97
|
-
head_commit_id: &str,
|
|
98
|
-
) -> Result<Vec<ReachableCommitGraphCommit>, LixError> {
|
|
99
|
-
walk_reachable_commits(self, head_commit_id).await
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
/// Returns the best common ancestors shared by two commit heads.
|
|
103
|
-
///
|
|
104
|
-
/// This is the commit-DAG primitive. It can return more than one commit in
|
|
105
|
-
/// criss-cross histories. Merge code should layer an explicit merge-base
|
|
106
|
-
/// policy on top when it needs exactly one base for a three-way merge.
|
|
107
|
-
pub(crate) async fn best_common_ancestors(
|
|
108
|
-
&mut self,
|
|
109
|
-
left_commit_id: &str,
|
|
110
|
-
right_commit_id: &str,
|
|
111
|
-
) -> Result<Vec<CommitGraphCommit>, LixError> {
|
|
112
|
-
best_common_ancestors(self, left_commit_id, right_commit_id).await
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
/// Resolves the single commit base to use for a three-way merge.
|
|
116
|
-
///
|
|
117
|
-
/// This is merge policy layered over `best_common_ancestors(...)`. Histories
|
|
118
|
-
/// with no shared base or multiple equally good bases are rejected for now
|
|
119
|
-
/// so merge code cannot accidentally hide unsupported graph semantics.
|
|
120
|
-
pub(crate) async fn merge_base(
|
|
121
|
-
&mut self,
|
|
122
|
-
left_commit_id: &str,
|
|
123
|
-
right_commit_id: &str,
|
|
124
|
-
) -> Result<CommitGraphCommit, LixError> {
|
|
125
|
-
let ancestors = self
|
|
126
|
-
.best_common_ancestors(left_commit_id, right_commit_id)
|
|
127
|
-
.await?;
|
|
128
|
-
match ancestors.as_slice() {
|
|
129
|
-
[] => Err(LixError::new(
|
|
130
|
-
"LIX_ERROR_UNKNOWN",
|
|
131
|
-
format!(
|
|
132
|
-
"commit_graph found no common history between '{left_commit_id}' and '{right_commit_id}'"
|
|
133
|
-
),
|
|
134
|
-
)),
|
|
135
|
-
[base] => Ok(base.clone()),
|
|
136
|
-
_ => Err(LixError::ambiguous_merge_base(
|
|
137
|
-
left_commit_id,
|
|
138
|
-
right_commit_id,
|
|
139
|
-
ancestors
|
|
140
|
-
.iter()
|
|
141
|
-
.map(|ancestor| ancestor.commit_id.clone())
|
|
142
|
-
.collect(),
|
|
143
|
-
)),
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
/// Derives parent/child edges from parsed commits.
|
|
148
|
-
pub(crate) fn commit_edges(&self, commits: &[CommitGraphCommit]) -> Vec<CommitGraphEdge> {
|
|
149
|
-
commits
|
|
150
|
-
.iter()
|
|
151
|
-
.flat_map(|commit| {
|
|
152
|
-
commit.parent_commit_ids.iter().enumerate().map(
|
|
153
|
-
|(parent_order, parent_commit_id)| CommitGraphEdge {
|
|
154
|
-
parent_commit_id: parent_commit_id.clone(),
|
|
155
|
-
child_commit_id: commit.commit_id.clone(),
|
|
156
|
-
parent_order: parent_order as u32,
|
|
157
|
-
},
|
|
158
|
-
)
|
|
159
|
-
})
|
|
160
|
-
.collect()
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
/// Returns canonical changes reachable from `start_commit_id`.
|
|
164
|
-
///
|
|
165
|
-
/// This is the primitive history API. It reports the commit/depth where a
|
|
166
|
-
/// reachable commit's change-ref set first exposes each matching canonical
|
|
167
|
-
/// change during graph traversal and leaves row shaping to callers such as
|
|
168
|
-
/// SQL providers.
|
|
169
|
-
pub(crate) async fn change_history_from_commit(
|
|
170
|
-
&mut self,
|
|
171
|
-
start_commit_id: &str,
|
|
172
|
-
request: &CommitGraphChangeHistoryRequest,
|
|
173
|
-
) -> Result<Vec<CommitGraphChangeHistoryEntry>, LixError> {
|
|
174
|
-
let commits = self.reachable_commits(start_commit_id).await?;
|
|
175
|
-
let mut entries = Vec::new();
|
|
176
|
-
let mut seen_change_ids = BTreeSet::new();
|
|
177
|
-
|
|
178
|
-
for reachable in commits {
|
|
179
|
-
if !depth_matches(reachable.depth, request) {
|
|
180
|
-
continue;
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
let commit_id = reachable.commit.commit_id;
|
|
184
|
-
let canonical_change = reachable.commit.canonical_change;
|
|
185
|
-
if seen_change_ids.insert(canonical_change.id.clone())
|
|
186
|
-
&& change_matches_history_request(&canonical_change, request)
|
|
187
|
-
{
|
|
188
|
-
entries.push(CommitGraphChangeHistoryEntry {
|
|
189
|
-
change: canonical_change,
|
|
190
|
-
observed_commit_id: commit_id.clone(),
|
|
191
|
-
start_commit_id: start_commit_id.to_string(),
|
|
192
|
-
depth: reachable.depth,
|
|
193
|
-
});
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
for change_id in reachable.commit.change_ids {
|
|
197
|
-
if !seen_change_ids.insert(change_id.clone()) {
|
|
198
|
-
continue;
|
|
199
|
-
}
|
|
200
|
-
let change = self.load_member_canonical_change(&change_id).await?;
|
|
201
|
-
if change_matches_history_request(&change, request) {
|
|
202
|
-
entries.push(CommitGraphChangeHistoryEntry {
|
|
203
|
-
change,
|
|
204
|
-
observed_commit_id: commit_id.clone(),
|
|
205
|
-
start_commit_id: start_commit_id.to_string(),
|
|
206
|
-
depth: reachable.depth,
|
|
207
|
-
});
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
Ok(entries)
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
async fn load_member_canonical_change(
|
|
216
|
-
&mut self,
|
|
217
|
-
change_id: &str,
|
|
218
|
-
) -> Result<CommitGraphChange, LixError> {
|
|
219
|
-
let change_ids = vec![change_id.to_string()];
|
|
220
|
-
self.load_canonical_changes(&change_ids)
|
|
221
|
-
.await?
|
|
222
|
-
.into_iter()
|
|
223
|
-
.next()
|
|
224
|
-
.flatten()
|
|
225
|
-
.ok_or_else(|| {
|
|
226
|
-
LixError::new(
|
|
227
|
-
"LIX_ERROR_UNKNOWN",
|
|
228
|
-
format!("commit_graph references missing change '{change_id}'"),
|
|
229
|
-
)
|
|
230
|
-
})
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
async fn load_changelog_commit(
|
|
234
|
-
&mut self,
|
|
235
|
-
commit_id: &str,
|
|
236
|
-
) -> Result<Option<CommitGraphCommit>, LixError> {
|
|
237
|
-
let mut reader = ChangelogContext::new().reader(&self.store);
|
|
238
|
-
let batch = reader
|
|
239
|
-
.load_commits(CommitLoadRequest {
|
|
240
|
-
commit_ids: &[commit_id.to_string()],
|
|
241
|
-
projection: CommitProjection::Full,
|
|
242
|
-
})
|
|
243
|
-
.await?;
|
|
244
|
-
let Some(entry) = batch.entries.into_iter().next().flatten() else {
|
|
245
|
-
return Ok(None);
|
|
246
|
-
};
|
|
247
|
-
match entry {
|
|
248
|
-
CommitLoadEntry::Full {
|
|
249
|
-
record,
|
|
250
|
-
change_ref_chunks,
|
|
251
|
-
} => {
|
|
252
|
-
let change_ids = change_ref_chunks
|
|
253
|
-
.into_iter()
|
|
254
|
-
.flat_map(|chunk| chunk.entries.into_iter().map(|entry| entry.change_id))
|
|
255
|
-
.collect::<Vec<_>>();
|
|
256
|
-
Ok(Some(commit_graph_commit_from_commit_record(
|
|
257
|
-
record, change_ids,
|
|
258
|
-
)))
|
|
259
|
-
}
|
|
260
|
-
_ => Err(LixError::new(
|
|
261
|
-
LixError::CODE_INTERNAL_ERROR,
|
|
262
|
-
"changelog full commit projection returned non-full entry",
|
|
263
|
-
)),
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
async fn load_canonical_changes(
|
|
268
|
-
&self,
|
|
269
|
-
change_ids: &[String],
|
|
270
|
-
) -> Result<Vec<Option<CommitGraphChange>>, LixError> {
|
|
271
|
-
let mut reader = ChangelogContext::new().reader(&self.store);
|
|
272
|
-
let batch = reader
|
|
273
|
-
.load_changes(ChangeLoadRequest { change_ids })
|
|
274
|
-
.await?;
|
|
275
|
-
batch
|
|
276
|
-
.entries
|
|
277
|
-
.into_iter()
|
|
278
|
-
.map(|entry| Ok(entry.map(commit_graph_change_from_change_record)))
|
|
279
|
-
.collect()
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
fn commit_graph_change_from_change_record(change: ChangeRecord) -> CommitGraphChange {
|
|
284
|
-
CommitGraphChange {
|
|
285
|
-
id: change.change_id,
|
|
286
|
-
entity_pk: change.entity_pk,
|
|
287
|
-
schema_key: change.schema_key,
|
|
288
|
-
file_id: change.file_id,
|
|
289
|
-
snapshot_ref: change.snapshot_ref,
|
|
290
|
-
metadata_ref: change.metadata_ref,
|
|
291
|
-
created_at: change.created_at,
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
#[async_trait::async_trait]
|
|
296
|
-
impl<S> CommitGraphReader for CommitGraphStoreReader<S>
|
|
297
|
-
where
|
|
298
|
-
S: StorageRead + Send + Sync,
|
|
299
|
-
{
|
|
300
|
-
async fn load_commit(
|
|
301
|
-
&mut self,
|
|
302
|
-
commit_id: &str,
|
|
303
|
-
) -> Result<Option<CommitGraphCommit>, LixError> {
|
|
304
|
-
CommitGraphStoreReader::load_commit(self, commit_id).await
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
async fn reachable_commits(
|
|
308
|
-
&mut self,
|
|
309
|
-
head_commit_id: &str,
|
|
310
|
-
) -> Result<Vec<ReachableCommitGraphCommit>, LixError> {
|
|
311
|
-
CommitGraphStoreReader::reachable_commits(self, head_commit_id).await
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
async fn change_history_from_commit(
|
|
315
|
-
&mut self,
|
|
316
|
-
start_commit_id: &str,
|
|
317
|
-
request: &CommitGraphChangeHistoryRequest,
|
|
318
|
-
) -> Result<Vec<CommitGraphChangeHistoryEntry>, LixError> {
|
|
319
|
-
CommitGraphStoreReader::change_history_from_commit(self, start_commit_id, request).await
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
fn depth_matches(depth: u32, request: &CommitGraphChangeHistoryRequest) -> bool {
|
|
324
|
-
request.min_depth.map_or(true, |min| depth >= min)
|
|
325
|
-
&& request.max_depth.map_or(true, |max| depth <= max)
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
fn change_matches_history_request(
|
|
329
|
-
change: &CommitGraphChange,
|
|
330
|
-
request: &CommitGraphChangeHistoryRequest,
|
|
331
|
-
) -> bool {
|
|
332
|
-
(request.include_tombstones || change.snapshot_ref.is_some())
|
|
333
|
-
&& (request.entity_pks.is_empty() || request.entity_pks.contains(&change.entity_pk))
|
|
334
|
-
&& (request.schema_keys.is_empty() || request.schema_keys.contains(&change.schema_key))
|
|
335
|
-
&& (request.file_ids.is_empty()
|
|
336
|
-
|| change
|
|
337
|
-
.file_id
|
|
338
|
-
.as_ref()
|
|
339
|
-
.is_some_and(|file_id| request.file_ids.contains(file_id)))
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
fn commit_graph_commit_from_commit_record(
|
|
343
|
-
record: CommitRecord,
|
|
344
|
-
change_ids: Vec<String>,
|
|
345
|
-
) -> CommitGraphCommit {
|
|
346
|
-
let change = commit_record_canonical_change(&record);
|
|
347
|
-
CommitGraphCommit {
|
|
348
|
-
canonical_change: change.clone(),
|
|
349
|
-
change,
|
|
350
|
-
commit_id: record.commit_id,
|
|
351
|
-
change_ids,
|
|
352
|
-
author_account_ids: record.author_account_ids,
|
|
353
|
-
parent_commit_ids: record.parent_commit_ids,
|
|
354
|
-
}
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
fn commit_record_canonical_change(record: &CommitRecord) -> CommitGraphChange {
|
|
358
|
-
let snapshot_content = serde_json::to_string(&serde_json::json!({
|
|
359
|
-
"id": record.commit_id,
|
|
360
|
-
}))
|
|
361
|
-
.expect("lix_commit snapshot serialization should not fail");
|
|
362
|
-
CommitGraphChange {
|
|
363
|
-
id: record.change_id.clone(),
|
|
364
|
-
entity_pk: EntityPk::single(&record.commit_id),
|
|
365
|
-
schema_key: COMMIT_SCHEMA_KEY.to_string(),
|
|
366
|
-
file_id: None,
|
|
367
|
-
snapshot_ref: Some(crate::json_store::JsonRef::for_content(
|
|
368
|
-
snapshot_content.as_bytes(),
|
|
369
|
-
)),
|
|
370
|
-
metadata_ref: None,
|
|
371
|
-
created_at: record.created_at.clone(),
|
|
372
|
-
}
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
#[cfg(test)]
|
|
376
|
-
mod tests {
|
|
377
|
-
use std::collections::{BTreeMap, BTreeSet};
|
|
378
|
-
|
|
379
|
-
use crate::changelog::{
|
|
380
|
-
ChangeRecord, ChangelogAppend, ChangelogContext, ChangelogWriter, CommitChangeRef,
|
|
381
|
-
CommitChangeRefSet, CommitRecord,
|
|
382
|
-
};
|
|
383
|
-
use crate::commit_graph::{
|
|
384
|
-
CommitGraphChange, CommitGraphChangeHistoryRequest, CommitGraphContext,
|
|
385
|
-
};
|
|
386
|
-
use crate::storage::StorageContext;
|
|
387
|
-
use crate::storage::{InMemoryStorageBackend, StorageReadOptions, StorageWriteOptions};
|
|
388
|
-
|
|
389
|
-
#[tokio::test]
|
|
390
|
-
async fn load_commit_parses_commit_snapshot() {
|
|
391
|
-
let storage = StorageContext::new(InMemoryStorageBackend::new());
|
|
392
|
-
append_changes(
|
|
393
|
-
&storage,
|
|
394
|
-
&[
|
|
395
|
-
entity_change("change-1", "entity-1", "example", "{}"),
|
|
396
|
-
entity_change("change-2", "entity-2", "example", "{}"),
|
|
397
|
-
commit_change(
|
|
398
|
-
"commit-1-change",
|
|
399
|
-
"commit-1",
|
|
400
|
-
&["change-1", "change-2"],
|
|
401
|
-
&["parent-1"],
|
|
402
|
-
),
|
|
403
|
-
],
|
|
404
|
-
)
|
|
405
|
-
.await;
|
|
406
|
-
|
|
407
|
-
let graph = CommitGraphContext::new();
|
|
408
|
-
let read = storage
|
|
409
|
-
.begin_read(StorageReadOptions::default())
|
|
410
|
-
.expect("read should open");
|
|
411
|
-
let mut reader = graph.reader(read);
|
|
412
|
-
let commit = reader
|
|
413
|
-
.load_commit("commit-1")
|
|
414
|
-
.await
|
|
415
|
-
.expect("commit load should succeed")
|
|
416
|
-
.expect("commit should exist");
|
|
417
|
-
|
|
418
|
-
assert_eq!(commit.commit_id, "commit-1");
|
|
419
|
-
assert_eq!(commit.change_ids, vec!["change-1", "change-2"]);
|
|
420
|
-
assert_eq!(commit.parent_commit_ids, vec!["parent-1"]);
|
|
421
|
-
assert_eq!(commit.change.id, "commit-1-change");
|
|
422
|
-
}
|
|
423
|
-
|
|
424
|
-
#[tokio::test]
|
|
425
|
-
async fn load_commit_returns_none_for_missing_commit() {
|
|
426
|
-
let storage = StorageContext::new(InMemoryStorageBackend::new());
|
|
427
|
-
let graph = CommitGraphContext::new();
|
|
428
|
-
let read = storage
|
|
429
|
-
.begin_read(StorageReadOptions::default())
|
|
430
|
-
.expect("read should open");
|
|
431
|
-
let mut reader = graph.reader(read);
|
|
432
|
-
|
|
433
|
-
let commit = reader
|
|
434
|
-
.load_commit("missing")
|
|
435
|
-
.await
|
|
436
|
-
.expect("commit load should succeed");
|
|
437
|
-
|
|
438
|
-
assert_eq!(commit, None);
|
|
439
|
-
}
|
|
440
|
-
|
|
441
|
-
#[tokio::test]
|
|
442
|
-
async fn all_commits_returns_parsed_commits_sorted_by_id() {
|
|
443
|
-
let storage = StorageContext::new(InMemoryStorageBackend::new());
|
|
444
|
-
append_changes(
|
|
445
|
-
&storage,
|
|
446
|
-
&[
|
|
447
|
-
commit_change("commit-b-change", "commit-b", &[], &[]),
|
|
448
|
-
entity_change("change-1", "entity-1", "example", "{}"),
|
|
449
|
-
commit_change("commit-a-change", "commit-a", &[], &[]),
|
|
450
|
-
],
|
|
451
|
-
)
|
|
452
|
-
.await;
|
|
453
|
-
|
|
454
|
-
let graph = CommitGraphContext::new();
|
|
455
|
-
let read = storage
|
|
456
|
-
.begin_read(StorageReadOptions::default())
|
|
457
|
-
.expect("read should open");
|
|
458
|
-
let mut reader = graph.reader(read);
|
|
459
|
-
let commits = reader
|
|
460
|
-
.all_commits()
|
|
461
|
-
.await
|
|
462
|
-
.expect("commit scan should succeed");
|
|
463
|
-
|
|
464
|
-
assert_eq!(
|
|
465
|
-
commits
|
|
466
|
-
.iter()
|
|
467
|
-
.map(|commit| commit.commit_id.as_str())
|
|
468
|
-
.collect::<Vec<_>>(),
|
|
469
|
-
vec!["commit-a", "commit-b"]
|
|
470
|
-
);
|
|
471
|
-
}
|
|
472
|
-
|
|
473
|
-
#[tokio::test]
|
|
474
|
-
async fn commit_edges_are_derived_from_parent_commit_ids() {
|
|
475
|
-
let graph = CommitGraphContext::new();
|
|
476
|
-
let storage = StorageContext::new(InMemoryStorageBackend::new());
|
|
477
|
-
let read = storage
|
|
478
|
-
.begin_read(StorageReadOptions::default())
|
|
479
|
-
.expect("read should open");
|
|
480
|
-
let reader = graph.reader(read);
|
|
481
|
-
let commits = vec![parsed_commit(
|
|
482
|
-
"commit-head",
|
|
483
|
-
&[],
|
|
484
|
-
&["commit-left", "commit-right"],
|
|
485
|
-
)];
|
|
486
|
-
|
|
487
|
-
let edges = reader.commit_edges(&commits);
|
|
488
|
-
|
|
489
|
-
assert_eq!(
|
|
490
|
-
edges
|
|
491
|
-
.iter()
|
|
492
|
-
.map(|edge| (
|
|
493
|
-
edge.parent_commit_id.as_str(),
|
|
494
|
-
edge.child_commit_id.as_str(),
|
|
495
|
-
edge.parent_order,
|
|
496
|
-
))
|
|
497
|
-
.collect::<Vec<_>>(),
|
|
498
|
-
vec![
|
|
499
|
-
("commit-left", "commit-head", 0),
|
|
500
|
-
("commit-right", "commit-head", 1)
|
|
501
|
-
]
|
|
502
|
-
);
|
|
503
|
-
}
|
|
504
|
-
|
|
505
|
-
#[tokio::test]
|
|
506
|
-
async fn change_history_from_commit_reports_matching_canonical_changes_with_depth() {
|
|
507
|
-
let storage = StorageContext::new(InMemoryStorageBackend::new());
|
|
508
|
-
append_changes(
|
|
509
|
-
&storage,
|
|
510
|
-
&[
|
|
511
|
-
entity_change("change-root", "entity-root", "test_schema", "{}"),
|
|
512
|
-
entity_change("change-head", "entity-head", "test_schema", "{}"),
|
|
513
|
-
commit_change("commit-root-change", "commit-root", &["change-root"], &[]),
|
|
514
|
-
commit_change(
|
|
515
|
-
"commit-head-change",
|
|
516
|
-
"commit-head",
|
|
517
|
-
&["change-head"],
|
|
518
|
-
&["commit-root"],
|
|
519
|
-
),
|
|
520
|
-
],
|
|
521
|
-
)
|
|
522
|
-
.await;
|
|
523
|
-
|
|
524
|
-
let graph = CommitGraphContext::new();
|
|
525
|
-
let read = storage
|
|
526
|
-
.begin_read(StorageReadOptions::default())
|
|
527
|
-
.expect("read should open");
|
|
528
|
-
let mut reader = graph.reader(read);
|
|
529
|
-
let history = reader
|
|
530
|
-
.change_history_from_commit(
|
|
531
|
-
"commit-head",
|
|
532
|
-
&CommitGraphChangeHistoryRequest {
|
|
533
|
-
schema_keys: vec!["test_schema".to_string()],
|
|
534
|
-
include_tombstones: true,
|
|
535
|
-
..CommitGraphChangeHistoryRequest::default()
|
|
536
|
-
},
|
|
537
|
-
)
|
|
538
|
-
.await
|
|
539
|
-
.expect("history should resolve");
|
|
540
|
-
|
|
541
|
-
assert_eq!(
|
|
542
|
-
history
|
|
543
|
-
.iter()
|
|
544
|
-
.map(|entry| (
|
|
545
|
-
entry.change.id.as_str(),
|
|
546
|
-
entry.observed_commit_id.as_str(),
|
|
547
|
-
entry.start_commit_id.as_str(),
|
|
548
|
-
entry.depth
|
|
549
|
-
))
|
|
550
|
-
.collect::<Vec<_>>(),
|
|
551
|
-
vec![
|
|
552
|
-
("change-head", "commit-head", "commit-head", 0),
|
|
553
|
-
("change-root", "commit-root", "commit-head", 1),
|
|
554
|
-
]
|
|
555
|
-
);
|
|
556
|
-
}
|
|
557
|
-
|
|
558
|
-
#[tokio::test]
|
|
559
|
-
async fn change_history_from_commit_filters_depth_entity_file_and_tombstones() {
|
|
560
|
-
let storage = StorageContext::new(InMemoryStorageBackend::new());
|
|
561
|
-
append_changes(
|
|
562
|
-
&storage,
|
|
563
|
-
&[
|
|
564
|
-
entity_change_with_file(
|
|
565
|
-
"change-file-a",
|
|
566
|
-
"entity-1",
|
|
567
|
-
"test_schema",
|
|
568
|
-
Some("file-a"),
|
|
569
|
-
"{}",
|
|
570
|
-
),
|
|
571
|
-
entity_tombstone("change-tombstone", "entity-1", "test_schema"),
|
|
572
|
-
entity_change_with_file(
|
|
573
|
-
"change-file-b",
|
|
574
|
-
"entity-2",
|
|
575
|
-
"test_schema",
|
|
576
|
-
Some("file-b"),
|
|
577
|
-
"{}",
|
|
578
|
-
),
|
|
579
|
-
commit_change("commit-root-change", "commit-root", &["change-file-a"], &[]),
|
|
580
|
-
commit_change(
|
|
581
|
-
"commit-head-change",
|
|
582
|
-
"commit-head",
|
|
583
|
-
&["change-tombstone", "change-file-b"],
|
|
584
|
-
&["commit-root"],
|
|
585
|
-
),
|
|
586
|
-
],
|
|
587
|
-
)
|
|
588
|
-
.await;
|
|
589
|
-
|
|
590
|
-
let graph = CommitGraphContext::new();
|
|
591
|
-
let read = storage
|
|
592
|
-
.begin_read(StorageReadOptions::default())
|
|
593
|
-
.expect("read should open");
|
|
594
|
-
let mut reader = graph.reader(read);
|
|
595
|
-
let history = reader
|
|
596
|
-
.change_history_from_commit(
|
|
597
|
-
"commit-head",
|
|
598
|
-
&CommitGraphChangeHistoryRequest {
|
|
599
|
-
entity_pks: vec![crate::entity_pk::EntityPk::single("entity-1")],
|
|
600
|
-
file_ids: vec!["file-a".to_string()],
|
|
601
|
-
min_depth: Some(1),
|
|
602
|
-
max_depth: Some(1),
|
|
603
|
-
include_tombstones: false,
|
|
604
|
-
..CommitGraphChangeHistoryRequest::default()
|
|
605
|
-
},
|
|
606
|
-
)
|
|
607
|
-
.await
|
|
608
|
-
.expect("history should resolve");
|
|
609
|
-
|
|
610
|
-
assert_eq!(history.len(), 1);
|
|
611
|
-
assert_eq!(history[0].change.id, "change-file-a");
|
|
612
|
-
assert_eq!(history[0].depth, 1);
|
|
613
|
-
}
|
|
614
|
-
|
|
615
|
-
#[tokio::test]
|
|
616
|
-
async fn change_history_from_commit_includes_tombstones_when_requested() {
|
|
617
|
-
let storage = StorageContext::new(InMemoryStorageBackend::new());
|
|
618
|
-
append_changes(
|
|
619
|
-
&storage,
|
|
620
|
-
&[
|
|
621
|
-
entity_tombstone("change-deleted", "entity-1", "test_schema"),
|
|
622
|
-
commit_change(
|
|
623
|
-
"commit-head-change",
|
|
624
|
-
"commit-head",
|
|
625
|
-
&["change-deleted"],
|
|
626
|
-
&[],
|
|
627
|
-
),
|
|
628
|
-
],
|
|
629
|
-
)
|
|
630
|
-
.await;
|
|
631
|
-
|
|
632
|
-
let graph = CommitGraphContext::new();
|
|
633
|
-
let read = storage
|
|
634
|
-
.begin_read(StorageReadOptions::default())
|
|
635
|
-
.expect("read should open");
|
|
636
|
-
let mut reader = graph.reader(read);
|
|
637
|
-
let hidden = reader
|
|
638
|
-
.change_history_from_commit(
|
|
639
|
-
"commit-head",
|
|
640
|
-
&CommitGraphChangeHistoryRequest {
|
|
641
|
-
schema_keys: vec!["test_schema".to_string()],
|
|
642
|
-
..CommitGraphChangeHistoryRequest::default()
|
|
643
|
-
},
|
|
644
|
-
)
|
|
645
|
-
.await
|
|
646
|
-
.expect("history should resolve");
|
|
647
|
-
let visible = reader
|
|
648
|
-
.change_history_from_commit(
|
|
649
|
-
"commit-head",
|
|
650
|
-
&CommitGraphChangeHistoryRequest {
|
|
651
|
-
schema_keys: vec!["test_schema".to_string()],
|
|
652
|
-
include_tombstones: true,
|
|
653
|
-
..CommitGraphChangeHistoryRequest::default()
|
|
654
|
-
},
|
|
655
|
-
)
|
|
656
|
-
.await
|
|
657
|
-
.expect("history should resolve");
|
|
658
|
-
|
|
659
|
-
assert!(hidden.is_empty());
|
|
660
|
-
assert_eq!(visible.len(), 1);
|
|
661
|
-
assert_eq!(visible[0].change.id, "change-deleted");
|
|
662
|
-
}
|
|
663
|
-
|
|
664
|
-
#[derive(Clone)]
|
|
665
|
-
struct TestChange {
|
|
666
|
-
change: CommitGraphChange,
|
|
667
|
-
commit_change_ids: Vec<String>,
|
|
668
|
-
parent_commit_ids: Vec<String>,
|
|
669
|
-
author_account_ids: Vec<String>,
|
|
670
|
-
}
|
|
671
|
-
|
|
672
|
-
impl TestChange {
|
|
673
|
-
fn commit(
|
|
674
|
-
change_id: &str,
|
|
675
|
-
commit_id: &str,
|
|
676
|
-
change_ids: &[&str],
|
|
677
|
-
parent_commit_ids: &[&str],
|
|
678
|
-
) -> Self {
|
|
679
|
-
Self {
|
|
680
|
-
change: CommitGraphChange {
|
|
681
|
-
id: change_id.to_string(),
|
|
682
|
-
entity_pk: crate::entity_pk::EntityPk::single(commit_id),
|
|
683
|
-
schema_key: super::COMMIT_SCHEMA_KEY.to_string(),
|
|
684
|
-
file_id: None,
|
|
685
|
-
snapshot_ref: None,
|
|
686
|
-
metadata_ref: None,
|
|
687
|
-
created_at: "2026-01-01T00:00:00Z".to_string(),
|
|
688
|
-
},
|
|
689
|
-
commit_change_ids: change_ids.iter().map(|id| id.to_string()).collect(),
|
|
690
|
-
parent_commit_ids: parent_commit_ids.iter().map(|id| id.to_string()).collect(),
|
|
691
|
-
author_account_ids: Vec::new(),
|
|
692
|
-
}
|
|
693
|
-
}
|
|
694
|
-
|
|
695
|
-
fn entity(
|
|
696
|
-
change_id: &str,
|
|
697
|
-
entity_pk: &str,
|
|
698
|
-
schema_key: &str,
|
|
699
|
-
file_id: Option<&str>,
|
|
700
|
-
snapshot_content: Option<&str>,
|
|
701
|
-
created_at: &str,
|
|
702
|
-
) -> Self {
|
|
703
|
-
Self {
|
|
704
|
-
change: CommitGraphChange {
|
|
705
|
-
id: change_id.to_string(),
|
|
706
|
-
entity_pk: crate::entity_pk::EntityPk::single(entity_pk),
|
|
707
|
-
schema_key: schema_key.to_string(),
|
|
708
|
-
file_id: file_id.map(str::to_string),
|
|
709
|
-
snapshot_ref: snapshot_content.map(|content| {
|
|
710
|
-
crate::json_store::JsonRef::from_hash(blake3::hash(content.as_bytes()))
|
|
711
|
-
}),
|
|
712
|
-
metadata_ref: None,
|
|
713
|
-
created_at: created_at.to_string(),
|
|
714
|
-
},
|
|
715
|
-
commit_change_ids: Vec::new(),
|
|
716
|
-
parent_commit_ids: Vec::new(),
|
|
717
|
-
author_account_ids: Vec::new(),
|
|
718
|
-
}
|
|
719
|
-
}
|
|
720
|
-
|
|
721
|
-
fn is_commit(&self) -> bool {
|
|
722
|
-
self.change.schema_key == super::COMMIT_SCHEMA_KEY
|
|
723
|
-
}
|
|
724
|
-
}
|
|
725
|
-
|
|
726
|
-
async fn append_changes(storage: &StorageContext, changes: &[TestChange]) {
|
|
727
|
-
let mut read = storage
|
|
728
|
-
.begin_read(StorageReadOptions::default())
|
|
729
|
-
.expect("read should open");
|
|
730
|
-
let mut writes = storage.new_write_set();
|
|
731
|
-
let canonical_changes = changes
|
|
732
|
-
.iter()
|
|
733
|
-
.filter(|change| !change.is_commit())
|
|
734
|
-
.cloned()
|
|
735
|
-
.collect::<Vec<_>>();
|
|
736
|
-
let changes_by_id: BTreeMap<&str, &TestChange> = canonical_changes
|
|
737
|
-
.iter()
|
|
738
|
-
.map(|change| (change.change.id.as_str(), change))
|
|
739
|
-
.collect::<BTreeMap<_, _>>();
|
|
740
|
-
let mut authored_change_ids = BTreeSet::new();
|
|
741
|
-
let provided_commit_ids = changes
|
|
742
|
-
.iter()
|
|
743
|
-
.filter(|change| change.is_commit())
|
|
744
|
-
.map(|change| {
|
|
745
|
-
change
|
|
746
|
-
.change
|
|
747
|
-
.entity_pk
|
|
748
|
-
.as_single_string()
|
|
749
|
-
.expect("commit fixture should use single entity pk")
|
|
750
|
-
.to_string()
|
|
751
|
-
})
|
|
752
|
-
.collect::<BTreeSet<_>>();
|
|
753
|
-
let mut staged_commit_ids = BTreeSet::new();
|
|
754
|
-
let changelog = ChangelogContext::new();
|
|
755
|
-
let mut writer = changelog.writer(&mut read, &mut writes);
|
|
756
|
-
let mut append = ChangelogAppend::default();
|
|
757
|
-
for change in changes.iter().filter(|change| change.is_commit()) {
|
|
758
|
-
let commit = crate::commit_graph::CommitGraphCommit {
|
|
759
|
-
canonical_change: change.change.clone(),
|
|
760
|
-
change: change.change.clone(),
|
|
761
|
-
commit_id: change
|
|
762
|
-
.change
|
|
763
|
-
.entity_pk
|
|
764
|
-
.as_single_string()
|
|
765
|
-
.expect("commit fixture should use single entity pk")
|
|
766
|
-
.to_string(),
|
|
767
|
-
change_ids: change.commit_change_ids.clone(),
|
|
768
|
-
author_account_ids: change.author_account_ids.clone(),
|
|
769
|
-
parent_commit_ids: change.parent_commit_ids.clone(),
|
|
770
|
-
};
|
|
771
|
-
for parent_commit_id in &commit.parent_commit_ids {
|
|
772
|
-
if !provided_commit_ids.contains(parent_commit_id)
|
|
773
|
-
&& staged_commit_ids.insert(parent_commit_id.clone())
|
|
774
|
-
{
|
|
775
|
-
append_empty_commit(&mut append, parent_commit_id);
|
|
776
|
-
}
|
|
777
|
-
}
|
|
778
|
-
let mut refs = Vec::new();
|
|
779
|
-
for change_id in &commit.change_ids {
|
|
780
|
-
if let Some(change) = changes_by_id.get(change_id.as_str()) {
|
|
781
|
-
if authored_change_ids.insert(change_id.clone()) {
|
|
782
|
-
append.changes.push(change_record_from_test_change(change));
|
|
783
|
-
}
|
|
784
|
-
refs.push(commit_change_ref_from_test_change(change));
|
|
785
|
-
}
|
|
786
|
-
}
|
|
787
|
-
|
|
788
|
-
append.commits.push(CommitRecord {
|
|
789
|
-
format_version: 1,
|
|
790
|
-
commit_id: commit.commit_id.clone(),
|
|
791
|
-
parent_commit_ids: commit.parent_commit_ids.clone(),
|
|
792
|
-
change_id: commit.canonical_change.id.clone(),
|
|
793
|
-
author_account_ids: commit.author_account_ids.clone(),
|
|
794
|
-
created_at: commit.canonical_change.created_at.clone(),
|
|
795
|
-
});
|
|
796
|
-
append.commit_change_refs.push(CommitChangeRefSet {
|
|
797
|
-
commit_id: commit.commit_id.clone(),
|
|
798
|
-
entries: refs,
|
|
799
|
-
});
|
|
800
|
-
staged_commit_ids.insert(commit.commit_id.clone());
|
|
801
|
-
}
|
|
802
|
-
writer
|
|
803
|
-
.stage_append(append)
|
|
804
|
-
.await
|
|
805
|
-
.expect("changelog append should stage");
|
|
806
|
-
storage
|
|
807
|
-
.commit_write_set(writes, StorageWriteOptions::default())
|
|
808
|
-
.expect("commit should succeed");
|
|
809
|
-
}
|
|
810
|
-
|
|
811
|
-
fn append_empty_commit(append: &mut ChangelogAppend, commit_id: &str) {
|
|
812
|
-
let change_id = format!("{commit_id}-change");
|
|
813
|
-
append.commits.push(CommitRecord {
|
|
814
|
-
format_version: 1,
|
|
815
|
-
commit_id: commit_id.to_string(),
|
|
816
|
-
parent_commit_ids: Vec::new(),
|
|
817
|
-
change_id: change_id.clone(),
|
|
818
|
-
author_account_ids: Vec::new(),
|
|
819
|
-
created_at: "2026-01-01T00:00:00Z".to_string(),
|
|
820
|
-
});
|
|
821
|
-
append.commit_change_refs.push(CommitChangeRefSet {
|
|
822
|
-
commit_id: commit_id.to_string(),
|
|
823
|
-
entries: Vec::new(),
|
|
824
|
-
});
|
|
825
|
-
}
|
|
826
|
-
|
|
827
|
-
fn change_record_from_test_change(change: &TestChange) -> ChangeRecord {
|
|
828
|
-
ChangeRecord {
|
|
829
|
-
format_version: 1,
|
|
830
|
-
change_id: change.change.id.clone(),
|
|
831
|
-
entity_pk: change.change.entity_pk.clone(),
|
|
832
|
-
schema_key: change.change.schema_key.clone(),
|
|
833
|
-
file_id: change.change.file_id.clone(),
|
|
834
|
-
snapshot_ref: change.change.snapshot_ref,
|
|
835
|
-
metadata_ref: change.change.metadata_ref,
|
|
836
|
-
created_at: change.change.created_at.clone(),
|
|
837
|
-
}
|
|
838
|
-
}
|
|
839
|
-
|
|
840
|
-
fn commit_change_ref_from_test_change(change: &TestChange) -> CommitChangeRef {
|
|
841
|
-
CommitChangeRef {
|
|
842
|
-
schema_key: change.change.schema_key.clone(),
|
|
843
|
-
file_id: change.change.file_id.clone(),
|
|
844
|
-
entity_pk: change.change.entity_pk.clone(),
|
|
845
|
-
change_id: change.change.id.clone(),
|
|
846
|
-
}
|
|
847
|
-
}
|
|
848
|
-
|
|
849
|
-
fn commit_change(
|
|
850
|
-
change_id: &str,
|
|
851
|
-
commit_id: &str,
|
|
852
|
-
change_ids: &[&str],
|
|
853
|
-
parent_commit_ids: &[&str],
|
|
854
|
-
) -> TestChange {
|
|
855
|
-
TestChange::commit(change_id, commit_id, change_ids, parent_commit_ids)
|
|
856
|
-
}
|
|
857
|
-
|
|
858
|
-
fn parsed_commit(
|
|
859
|
-
commit_id: &str,
|
|
860
|
-
change_ids: &[&str],
|
|
861
|
-
parent_commit_ids: &[&str],
|
|
862
|
-
) -> crate::commit_graph::CommitGraphCommit {
|
|
863
|
-
let fixture = commit_change(
|
|
864
|
-
&format!("{commit_id}-change"),
|
|
865
|
-
commit_id,
|
|
866
|
-
change_ids,
|
|
867
|
-
parent_commit_ids,
|
|
868
|
-
);
|
|
869
|
-
crate::commit_graph::CommitGraphCommit {
|
|
870
|
-
canonical_change: fixture.change.clone(),
|
|
871
|
-
change: fixture.change,
|
|
872
|
-
commit_id: commit_id.to_string(),
|
|
873
|
-
change_ids: change_ids
|
|
874
|
-
.iter()
|
|
875
|
-
.map(|change_id| change_id.to_string())
|
|
876
|
-
.collect(),
|
|
877
|
-
author_account_ids: Vec::new(),
|
|
878
|
-
parent_commit_ids: parent_commit_ids
|
|
879
|
-
.iter()
|
|
880
|
-
.map(|parent_id| parent_id.to_string())
|
|
881
|
-
.collect(),
|
|
882
|
-
}
|
|
883
|
-
}
|
|
884
|
-
|
|
885
|
-
fn entity_change(
|
|
886
|
-
change_id: &str,
|
|
887
|
-
entity_pk: &str,
|
|
888
|
-
schema_key: &str,
|
|
889
|
-
snapshot_content: &str,
|
|
890
|
-
) -> TestChange {
|
|
891
|
-
entity_change_at(
|
|
892
|
-
change_id,
|
|
893
|
-
entity_pk,
|
|
894
|
-
schema_key,
|
|
895
|
-
snapshot_content,
|
|
896
|
-
"2026-01-01T00:00:00Z",
|
|
897
|
-
)
|
|
898
|
-
}
|
|
899
|
-
|
|
900
|
-
fn entity_change_at(
|
|
901
|
-
change_id: &str,
|
|
902
|
-
entity_pk: &str,
|
|
903
|
-
schema_key: &str,
|
|
904
|
-
snapshot_content: &str,
|
|
905
|
-
created_at: &str,
|
|
906
|
-
) -> TestChange {
|
|
907
|
-
TestChange::entity(
|
|
908
|
-
change_id,
|
|
909
|
-
entity_pk,
|
|
910
|
-
schema_key,
|
|
911
|
-
None,
|
|
912
|
-
Some(snapshot_content),
|
|
913
|
-
created_at,
|
|
914
|
-
)
|
|
915
|
-
}
|
|
916
|
-
|
|
917
|
-
fn entity_change_with_file(
|
|
918
|
-
change_id: &str,
|
|
919
|
-
entity_pk: &str,
|
|
920
|
-
schema_key: &str,
|
|
921
|
-
file_id: Option<&str>,
|
|
922
|
-
snapshot_content: &str,
|
|
923
|
-
) -> TestChange {
|
|
924
|
-
TestChange::entity(
|
|
925
|
-
change_id,
|
|
926
|
-
entity_pk,
|
|
927
|
-
schema_key,
|
|
928
|
-
file_id,
|
|
929
|
-
Some(snapshot_content),
|
|
930
|
-
"2026-01-01T00:00:00Z",
|
|
931
|
-
)
|
|
932
|
-
}
|
|
933
|
-
|
|
934
|
-
fn entity_tombstone(change_id: &str, entity_pk: &str, schema_key: &str) -> TestChange {
|
|
935
|
-
TestChange::entity(
|
|
936
|
-
change_id,
|
|
937
|
-
entity_pk,
|
|
938
|
-
schema_key,
|
|
939
|
-
None,
|
|
940
|
-
None,
|
|
941
|
-
"2026-01-02T00:00:00Z",
|
|
942
|
-
)
|
|
943
|
-
}
|
|
944
|
-
}
|