@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 +0,0 @@
|
|
|
1
|
-
//! Change-specific behavior lives here once changelog storage is implemented.
|
|
@@ -1,497 +0,0 @@
|
|
|
1
|
-
use super::types::{
|
|
2
|
-
ChangeRecord, ChangeRecordView, CommitChangeRef, CommitChangeRefChunk,
|
|
3
|
-
CommitChangeRefChunkView, CommitChangeRefView, CommitRecord, CommitRecordView, EntityPkRef,
|
|
4
|
-
};
|
|
5
|
-
use crate::common::LixError;
|
|
6
|
-
use crate::entity_pk::EntityPk;
|
|
7
|
-
use crate::json_store::JsonRef;
|
|
8
|
-
|
|
9
|
-
const COMMIT_MAGIC: &[u8; 5] = b"LXCM1";
|
|
10
|
-
const CHANGE_MAGIC: &[u8; 5] = b"LXCH1";
|
|
11
|
-
const COMMIT_CHANGE_REF_CHUNK_MAGIC: &[u8; 5] = b"LXCR1";
|
|
12
|
-
|
|
13
|
-
pub(crate) fn encode_commit_record(record: &CommitRecord) -> Result<Vec<u8>, LixError> {
|
|
14
|
-
let mut bytes = Vec::new();
|
|
15
|
-
bytes.extend_from_slice(COMMIT_MAGIC);
|
|
16
|
-
write_u32(&mut bytes, record.format_version);
|
|
17
|
-
write_str(&mut bytes, &record.commit_id)?;
|
|
18
|
-
write_str_vec(&mut bytes, &record.parent_commit_ids)?;
|
|
19
|
-
write_str(&mut bytes, &record.change_id)?;
|
|
20
|
-
write_str_vec(&mut bytes, &record.author_account_ids)?;
|
|
21
|
-
write_str(&mut bytes, &record.created_at)?;
|
|
22
|
-
Ok(bytes)
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
pub(crate) fn view_commit_record(bytes: &[u8]) -> Result<CommitRecordView<'_>, LixError> {
|
|
26
|
-
let mut cursor = ByteCursor::new(bytes);
|
|
27
|
-
cursor.expect_magic(COMMIT_MAGIC, "commit record")?;
|
|
28
|
-
let view = CommitRecordView {
|
|
29
|
-
format_version: cursor.read_u32("format_version")?,
|
|
30
|
-
commit_id: cursor.read_str("commit_id")?,
|
|
31
|
-
parent_commit_ids: cursor.read_str_vec("parent_commit_ids")?,
|
|
32
|
-
change_id: cursor.read_str("change_id")?,
|
|
33
|
-
author_account_ids: cursor.read_str_vec("author_account_ids")?,
|
|
34
|
-
created_at: cursor.read_str("created_at")?,
|
|
35
|
-
};
|
|
36
|
-
cursor.expect_end("commit record")?;
|
|
37
|
-
Ok(view)
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
pub(crate) fn decode_commit_record(bytes: &[u8]) -> Result<CommitRecord, LixError> {
|
|
41
|
-
let view = view_commit_record(bytes)?;
|
|
42
|
-
Ok(CommitRecord {
|
|
43
|
-
format_version: view.format_version,
|
|
44
|
-
commit_id: view.commit_id.to_string(),
|
|
45
|
-
parent_commit_ids: view
|
|
46
|
-
.parent_commit_ids
|
|
47
|
-
.iter()
|
|
48
|
-
.map(|value| (*value).to_string())
|
|
49
|
-
.collect(),
|
|
50
|
-
change_id: view.change_id.to_string(),
|
|
51
|
-
author_account_ids: view
|
|
52
|
-
.author_account_ids
|
|
53
|
-
.iter()
|
|
54
|
-
.map(|value| (*value).to_string())
|
|
55
|
-
.collect(),
|
|
56
|
-
created_at: view.created_at.to_string(),
|
|
57
|
-
})
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
pub(crate) fn encode_change_record(record: &ChangeRecord) -> Result<Vec<u8>, LixError> {
|
|
61
|
-
let mut bytes = Vec::new();
|
|
62
|
-
bytes.extend_from_slice(CHANGE_MAGIC);
|
|
63
|
-
write_u32(&mut bytes, record.format_version);
|
|
64
|
-
write_str(&mut bytes, &record.change_id)?;
|
|
65
|
-
write_str(&mut bytes, &record.schema_key)?;
|
|
66
|
-
write_entity_pk(&mut bytes, &record.entity_pk)?;
|
|
67
|
-
write_optional_str(&mut bytes, record.file_id.as_deref())?;
|
|
68
|
-
write_optional_json_ref(&mut bytes, record.snapshot_ref)?;
|
|
69
|
-
write_optional_json_ref(&mut bytes, record.metadata_ref)?;
|
|
70
|
-
write_str(&mut bytes, &record.created_at)?;
|
|
71
|
-
Ok(bytes)
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
pub(crate) fn view_change_record(bytes: &[u8]) -> Result<ChangeRecordView<'_>, LixError> {
|
|
75
|
-
let mut cursor = ByteCursor::new(bytes);
|
|
76
|
-
cursor.expect_magic(CHANGE_MAGIC, "change record")?;
|
|
77
|
-
let view = ChangeRecordView {
|
|
78
|
-
format_version: cursor.read_u32("format_version")?,
|
|
79
|
-
change_id: cursor.read_str("change_id")?,
|
|
80
|
-
schema_key: cursor.read_str("schema_key")?,
|
|
81
|
-
entity_pk: cursor.read_entity_pk("entity_pk")?,
|
|
82
|
-
file_id: cursor.read_optional_str("file_id")?,
|
|
83
|
-
snapshot_ref: cursor.read_optional_json_ref("snapshot_ref")?,
|
|
84
|
-
metadata_ref: cursor.read_optional_json_ref("metadata_ref")?,
|
|
85
|
-
created_at: cursor.read_str("created_at")?,
|
|
86
|
-
};
|
|
87
|
-
cursor.expect_end("change record")?;
|
|
88
|
-
Ok(view)
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
pub(crate) fn decode_change_record(bytes: &[u8]) -> Result<ChangeRecord, LixError> {
|
|
92
|
-
let view = view_change_record(bytes)?;
|
|
93
|
-
Ok(ChangeRecord {
|
|
94
|
-
format_version: view.format_version,
|
|
95
|
-
change_id: view.change_id.to_string(),
|
|
96
|
-
schema_key: view.schema_key.to_string(),
|
|
97
|
-
entity_pk: entity_pk_from_ref(view.entity_pk)?,
|
|
98
|
-
file_id: view.file_id.map(str::to_string),
|
|
99
|
-
snapshot_ref: view.snapshot_ref,
|
|
100
|
-
metadata_ref: view.metadata_ref,
|
|
101
|
-
created_at: view.created_at.to_string(),
|
|
102
|
-
})
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
pub(crate) fn encode_commit_change_ref_chunk(
|
|
106
|
-
chunk: &CommitChangeRefChunk,
|
|
107
|
-
) -> Result<Vec<u8>, LixError> {
|
|
108
|
-
let mut bytes = Vec::new();
|
|
109
|
-
bytes.extend_from_slice(COMMIT_CHANGE_REF_CHUNK_MAGIC);
|
|
110
|
-
write_u32(&mut bytes, chunk.format_version);
|
|
111
|
-
let schema_keys = commit_change_ref_schema_dictionary(&chunk.entries);
|
|
112
|
-
let file_ids = commit_change_ref_file_dictionary(&chunk.entries);
|
|
113
|
-
write_len(
|
|
114
|
-
&mut bytes,
|
|
115
|
-
schema_keys.len(),
|
|
116
|
-
"commit change ref schema dictionary",
|
|
117
|
-
)?;
|
|
118
|
-
for schema_key in &schema_keys {
|
|
119
|
-
write_str(&mut bytes, schema_key)?;
|
|
120
|
-
}
|
|
121
|
-
write_len(
|
|
122
|
-
&mut bytes,
|
|
123
|
-
file_ids.len(),
|
|
124
|
-
"commit change ref file dictionary",
|
|
125
|
-
)?;
|
|
126
|
-
for file_id in &file_ids {
|
|
127
|
-
write_optional_str(&mut bytes, *file_id)?;
|
|
128
|
-
}
|
|
129
|
-
write_len(&mut bytes, chunk.entries.len(), "commit change ref entries")?;
|
|
130
|
-
for entry in &chunk.entries {
|
|
131
|
-
let schema_index = dictionary_index(
|
|
132
|
-
schema_keys.iter().copied(),
|
|
133
|
-
entry.schema_key.as_str(),
|
|
134
|
-
"commit change ref schema dictionary",
|
|
135
|
-
)?;
|
|
136
|
-
let file_index = optional_dictionary_index(
|
|
137
|
-
file_ids.iter().copied(),
|
|
138
|
-
entry.file_id.as_deref(),
|
|
139
|
-
"commit change ref file dictionary",
|
|
140
|
-
)?;
|
|
141
|
-
write_u16_index(&mut bytes, schema_index, "commit change ref schema index")?;
|
|
142
|
-
write_u16_index(&mut bytes, file_index, "commit change ref file index")?;
|
|
143
|
-
write_entity_pk_compact(&mut bytes, &entry.entity_pk)?;
|
|
144
|
-
write_str(&mut bytes, &entry.change_id)?;
|
|
145
|
-
}
|
|
146
|
-
Ok(bytes)
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
pub(crate) fn view_commit_change_ref_chunk<'a>(
|
|
150
|
-
bytes: &'a [u8],
|
|
151
|
-
commit_id: &'a str,
|
|
152
|
-
) -> Result<CommitChangeRefChunkView<'a>, LixError> {
|
|
153
|
-
let mut cursor = ByteCursor::new(bytes);
|
|
154
|
-
cursor.expect_magic(COMMIT_CHANGE_REF_CHUNK_MAGIC, "commit change ref chunk")?;
|
|
155
|
-
let format_version = cursor.read_u32("format_version")?;
|
|
156
|
-
let schema_keys = cursor.read_str_vec("commit change ref schema dictionary")?;
|
|
157
|
-
let file_ids = cursor.read_optional_str_vec("commit change ref file dictionary")?;
|
|
158
|
-
let entry_count = cursor.read_len("commit change ref entries")?;
|
|
159
|
-
let mut entries = Vec::with_capacity(entry_count);
|
|
160
|
-
for index in 0..entry_count {
|
|
161
|
-
let context = format!("commit change ref entries[{index}]");
|
|
162
|
-
let schema_index = cursor.read_u16(&format!("{context}.schema_index"))? as usize;
|
|
163
|
-
let file_index = cursor.read_u16(&format!("{context}.file_index"))? as usize;
|
|
164
|
-
entries.push(CommitChangeRefView {
|
|
165
|
-
schema_key: *schema_keys.get(schema_index).ok_or_else(|| {
|
|
166
|
-
LixError::new(
|
|
167
|
-
LixError::CODE_INTERNAL_ERROR,
|
|
168
|
-
format!("changelog {context}.schema_index is out of bounds"),
|
|
169
|
-
)
|
|
170
|
-
})?,
|
|
171
|
-
file_id: *file_ids.get(file_index).ok_or_else(|| {
|
|
172
|
-
LixError::new(
|
|
173
|
-
LixError::CODE_INTERNAL_ERROR,
|
|
174
|
-
format!("changelog {context}.file_index is out of bounds"),
|
|
175
|
-
)
|
|
176
|
-
})?,
|
|
177
|
-
entity_pk: cursor.read_entity_pk_compact(&format!("{context}.entity_pk"))?,
|
|
178
|
-
change_id: cursor.read_str(&format!("{context}.change_id"))?,
|
|
179
|
-
});
|
|
180
|
-
}
|
|
181
|
-
cursor.expect_end("commit change ref chunk")?;
|
|
182
|
-
Ok(CommitChangeRefChunkView {
|
|
183
|
-
format_version,
|
|
184
|
-
commit_id,
|
|
185
|
-
entries,
|
|
186
|
-
})
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
pub(crate) fn decode_commit_change_ref_chunk(
|
|
190
|
-
bytes: &[u8],
|
|
191
|
-
commit_id: &str,
|
|
192
|
-
) -> Result<CommitChangeRefChunk, LixError> {
|
|
193
|
-
let view = view_commit_change_ref_chunk(bytes, commit_id)?;
|
|
194
|
-
Ok(CommitChangeRefChunk {
|
|
195
|
-
format_version: view.format_version,
|
|
196
|
-
commit_id: view.commit_id.to_string(),
|
|
197
|
-
entries: view
|
|
198
|
-
.entries
|
|
199
|
-
.iter()
|
|
200
|
-
.map(|entry| {
|
|
201
|
-
Ok(CommitChangeRef {
|
|
202
|
-
schema_key: entry.schema_key.to_string(),
|
|
203
|
-
file_id: entry.file_id.map(str::to_string),
|
|
204
|
-
entity_pk: entity_pk_from_ref(entry.entity_pk.clone())?,
|
|
205
|
-
change_id: entry.change_id.to_string(),
|
|
206
|
-
})
|
|
207
|
-
})
|
|
208
|
-
.collect::<Result<Vec<_>, LixError>>()?,
|
|
209
|
-
})
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
fn commit_change_ref_schema_dictionary(entries: &[CommitChangeRef]) -> Vec<&str> {
|
|
213
|
-
let mut values = Vec::new();
|
|
214
|
-
for entry in entries {
|
|
215
|
-
if !values.contains(&entry.schema_key.as_str()) {
|
|
216
|
-
values.push(entry.schema_key.as_str());
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
values
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
fn commit_change_ref_file_dictionary(entries: &[CommitChangeRef]) -> Vec<Option<&str>> {
|
|
223
|
-
let mut values = Vec::new();
|
|
224
|
-
for entry in entries {
|
|
225
|
-
let value = entry.file_id.as_deref();
|
|
226
|
-
if !values.contains(&value) {
|
|
227
|
-
values.push(value);
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
values
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
fn dictionary_index<'a>(
|
|
234
|
-
mut values: impl Iterator<Item = &'a str>,
|
|
235
|
-
needle: &str,
|
|
236
|
-
context: &str,
|
|
237
|
-
) -> Result<usize, LixError> {
|
|
238
|
-
values.position(|value| value == needle).ok_or_else(|| {
|
|
239
|
-
LixError::new(
|
|
240
|
-
LixError::CODE_INTERNAL_ERROR,
|
|
241
|
-
format!("changelog {context} is missing value '{needle}'"),
|
|
242
|
-
)
|
|
243
|
-
})
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
fn optional_dictionary_index<'a>(
|
|
247
|
-
mut values: impl Iterator<Item = Option<&'a str>>,
|
|
248
|
-
needle: Option<&str>,
|
|
249
|
-
context: &str,
|
|
250
|
-
) -> Result<usize, LixError> {
|
|
251
|
-
values.position(|value| value == needle).ok_or_else(|| {
|
|
252
|
-
LixError::new(
|
|
253
|
-
LixError::CODE_INTERNAL_ERROR,
|
|
254
|
-
format!("changelog {context} is missing optional value"),
|
|
255
|
-
)
|
|
256
|
-
})
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
fn write_str_vec(out: &mut Vec<u8>, values: &[String]) -> Result<(), LixError> {
|
|
260
|
-
write_len(out, values.len(), "string vec")?;
|
|
261
|
-
for value in values {
|
|
262
|
-
write_str(out, value)?;
|
|
263
|
-
}
|
|
264
|
-
Ok(())
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
fn write_entity_pk(out: &mut Vec<u8>, identity: &EntityPk) -> Result<(), LixError> {
|
|
268
|
-
write_len(out, identity.parts.len(), "entity primary key parts")?;
|
|
269
|
-
for part in &identity.parts {
|
|
270
|
-
write_str(out, part)?;
|
|
271
|
-
}
|
|
272
|
-
Ok(())
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
fn write_entity_pk_compact(out: &mut Vec<u8>, identity: &EntityPk) -> Result<(), LixError> {
|
|
276
|
-
if identity.parts.len() == 1 {
|
|
277
|
-
out.push(1);
|
|
278
|
-
write_str(out, &identity.parts[0])
|
|
279
|
-
} else {
|
|
280
|
-
out.push(0);
|
|
281
|
-
write_entity_pk(out, identity)
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
fn write_optional_str(out: &mut Vec<u8>, value: Option<&str>) -> Result<(), LixError> {
|
|
286
|
-
match value {
|
|
287
|
-
Some(value) => {
|
|
288
|
-
out.push(1);
|
|
289
|
-
write_str(out, value)
|
|
290
|
-
}
|
|
291
|
-
None => {
|
|
292
|
-
out.push(0);
|
|
293
|
-
Ok(())
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
fn write_optional_json_ref(out: &mut Vec<u8>, value: Option<JsonRef>) -> Result<(), LixError> {
|
|
299
|
-
match value {
|
|
300
|
-
Some(value) => {
|
|
301
|
-
out.push(1);
|
|
302
|
-
out.extend_from_slice(value.as_hash_bytes());
|
|
303
|
-
}
|
|
304
|
-
None => out.push(0),
|
|
305
|
-
}
|
|
306
|
-
Ok(())
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
fn write_str(out: &mut Vec<u8>, value: &str) -> Result<(), LixError> {
|
|
310
|
-
write_len(out, value.len(), "string bytes")?;
|
|
311
|
-
out.extend_from_slice(value.as_bytes());
|
|
312
|
-
Ok(())
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
fn write_len(out: &mut Vec<u8>, len: usize, context: &str) -> Result<(), LixError> {
|
|
316
|
-
let len = u32::try_from(len).map_err(|_| {
|
|
317
|
-
LixError::new(
|
|
318
|
-
LixError::CODE_INTERNAL_ERROR,
|
|
319
|
-
format!("changelog {context} length exceeds u32"),
|
|
320
|
-
)
|
|
321
|
-
})?;
|
|
322
|
-
write_u32(out, len);
|
|
323
|
-
Ok(())
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
fn write_u32(out: &mut Vec<u8>, value: u32) {
|
|
327
|
-
out.extend_from_slice(&value.to_be_bytes());
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
fn write_u16_index(out: &mut Vec<u8>, value: usize, context: &str) -> Result<(), LixError> {
|
|
331
|
-
let value = u16::try_from(value).map_err(|_| {
|
|
332
|
-
LixError::new(
|
|
333
|
-
LixError::CODE_INTERNAL_ERROR,
|
|
334
|
-
format!("changelog {context} exceeds u16"),
|
|
335
|
-
)
|
|
336
|
-
})?;
|
|
337
|
-
out.extend_from_slice(&value.to_be_bytes());
|
|
338
|
-
Ok(())
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
fn entity_pk_from_ref(value: EntityPkRef<'_>) -> Result<EntityPk, LixError> {
|
|
342
|
-
EntityPk::from_parts(value.parts.iter().map(|part| (*part).to_string()).collect()).map_err(
|
|
343
|
-
|error| {
|
|
344
|
-
LixError::new(
|
|
345
|
-
LixError::CODE_INTERNAL_ERROR,
|
|
346
|
-
format!("changelog entity primary key is invalid: {error}"),
|
|
347
|
-
)
|
|
348
|
-
},
|
|
349
|
-
)
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
#[derive(Clone)]
|
|
353
|
-
struct ByteCursor<'a> {
|
|
354
|
-
bytes: &'a [u8],
|
|
355
|
-
offset: usize,
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
impl<'a> ByteCursor<'a> {
|
|
359
|
-
fn new(bytes: &'a [u8]) -> Self {
|
|
360
|
-
Self { bytes, offset: 0 }
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
fn expect_magic(&mut self, magic: &[u8], context: &str) -> Result<(), LixError> {
|
|
364
|
-
let found = self.read_bytes(magic.len(), context)?;
|
|
365
|
-
if found != magic {
|
|
366
|
-
return Err(LixError::new(
|
|
367
|
-
LixError::CODE_INTERNAL_ERROR,
|
|
368
|
-
format!("changelog {context} has invalid magic"),
|
|
369
|
-
));
|
|
370
|
-
}
|
|
371
|
-
Ok(())
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
fn read_str_vec(&mut self, context: &str) -> Result<Vec<&'a str>, LixError> {
|
|
375
|
-
let len = self.read_len(context)?;
|
|
376
|
-
let mut values = Vec::with_capacity(len);
|
|
377
|
-
for index in 0..len {
|
|
378
|
-
values.push(self.read_str(&format!("{context}[{index}]"))?);
|
|
379
|
-
}
|
|
380
|
-
Ok(values)
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
fn read_optional_str_vec(&mut self, context: &str) -> Result<Vec<Option<&'a str>>, LixError> {
|
|
384
|
-
let len = self.read_len(context)?;
|
|
385
|
-
let mut values = Vec::with_capacity(len);
|
|
386
|
-
for index in 0..len {
|
|
387
|
-
values.push(self.read_optional_str(&format!("{context}[{index}]"))?);
|
|
388
|
-
}
|
|
389
|
-
Ok(values)
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
fn read_entity_pk(&mut self, context: &str) -> Result<EntityPkRef<'a>, LixError> {
|
|
393
|
-
let len = self.read_len(context)?;
|
|
394
|
-
let mut parts = Vec::with_capacity(len);
|
|
395
|
-
for index in 0..len {
|
|
396
|
-
parts.push(self.read_str(&format!("{context}.parts[{index}]"))?);
|
|
397
|
-
}
|
|
398
|
-
Ok(EntityPkRef { parts })
|
|
399
|
-
}
|
|
400
|
-
|
|
401
|
-
fn read_entity_pk_compact(&mut self, context: &str) -> Result<EntityPkRef<'a>, LixError> {
|
|
402
|
-
match self.read_bytes(1, context)?[0] {
|
|
403
|
-
0 => self.read_entity_pk(context),
|
|
404
|
-
1 => Ok(EntityPkRef {
|
|
405
|
-
parts: vec![self.read_str(&format!("{context}.part"))?],
|
|
406
|
-
}),
|
|
407
|
-
_ => Err(LixError::new(
|
|
408
|
-
LixError::CODE_INTERNAL_ERROR,
|
|
409
|
-
format!("changelog {context} compact entity primary key flag is invalid"),
|
|
410
|
-
)),
|
|
411
|
-
}
|
|
412
|
-
}
|
|
413
|
-
|
|
414
|
-
fn read_optional_str(&mut self, context: &str) -> Result<Option<&'a str>, LixError> {
|
|
415
|
-
match self.read_flag(context)? {
|
|
416
|
-
false => Ok(None),
|
|
417
|
-
true => Ok(Some(self.read_str(context)?)),
|
|
418
|
-
}
|
|
419
|
-
}
|
|
420
|
-
|
|
421
|
-
fn read_optional_json_ref(&mut self, context: &str) -> Result<Option<JsonRef>, LixError> {
|
|
422
|
-
match self.read_flag(context)? {
|
|
423
|
-
false => Ok(None),
|
|
424
|
-
true => {
|
|
425
|
-
let bytes = self.read_bytes(32, context)?;
|
|
426
|
-
let mut hash = [0; 32];
|
|
427
|
-
hash.copy_from_slice(bytes);
|
|
428
|
-
Ok(Some(JsonRef::from_hash_bytes(hash)))
|
|
429
|
-
}
|
|
430
|
-
}
|
|
431
|
-
}
|
|
432
|
-
|
|
433
|
-
fn read_str(&mut self, context: &str) -> Result<&'a str, LixError> {
|
|
434
|
-
let len = self.read_len(context)?;
|
|
435
|
-
let bytes = self.read_bytes(len, context)?;
|
|
436
|
-
std::str::from_utf8(bytes).map_err(|error| {
|
|
437
|
-
LixError::new(
|
|
438
|
-
LixError::CODE_INTERNAL_ERROR,
|
|
439
|
-
format!("changelog {context} contains invalid UTF-8: {error}"),
|
|
440
|
-
)
|
|
441
|
-
})
|
|
442
|
-
}
|
|
443
|
-
|
|
444
|
-
fn read_flag(&mut self, context: &str) -> Result<bool, LixError> {
|
|
445
|
-
let byte = self.read_bytes(1, context)?[0];
|
|
446
|
-
match byte {
|
|
447
|
-
0 => Ok(false),
|
|
448
|
-
1 => Ok(true),
|
|
449
|
-
_ => Err(LixError::new(
|
|
450
|
-
LixError::CODE_INTERNAL_ERROR,
|
|
451
|
-
format!("changelog {context} option flag is invalid"),
|
|
452
|
-
)),
|
|
453
|
-
}
|
|
454
|
-
}
|
|
455
|
-
|
|
456
|
-
fn read_len(&mut self, context: &str) -> Result<usize, LixError> {
|
|
457
|
-
Ok(self.read_u32(context)? as usize)
|
|
458
|
-
}
|
|
459
|
-
|
|
460
|
-
fn read_u32(&mut self, context: &str) -> Result<u32, LixError> {
|
|
461
|
-
let bytes = self.read_bytes(4, context)?;
|
|
462
|
-
Ok(u32::from_be_bytes([bytes[0], bytes[1], bytes[2], bytes[3]]))
|
|
463
|
-
}
|
|
464
|
-
|
|
465
|
-
fn read_u16(&mut self, context: &str) -> Result<u16, LixError> {
|
|
466
|
-
let bytes = self.read_bytes(2, context)?;
|
|
467
|
-
Ok(u16::from_be_bytes([bytes[0], bytes[1]]))
|
|
468
|
-
}
|
|
469
|
-
|
|
470
|
-
fn read_bytes(&mut self, len: usize, context: &str) -> Result<&'a [u8], LixError> {
|
|
471
|
-
let end = self.offset.checked_add(len).ok_or_else(|| {
|
|
472
|
-
LixError::new(
|
|
473
|
-
LixError::CODE_INTERNAL_ERROR,
|
|
474
|
-
format!("changelog {context} length overflows"),
|
|
475
|
-
)
|
|
476
|
-
})?;
|
|
477
|
-
if end > self.bytes.len() {
|
|
478
|
-
return Err(LixError::new(
|
|
479
|
-
LixError::CODE_INTERNAL_ERROR,
|
|
480
|
-
format!("changelog {context} is truncated"),
|
|
481
|
-
));
|
|
482
|
-
}
|
|
483
|
-
let out = &self.bytes[self.offset..end];
|
|
484
|
-
self.offset = end;
|
|
485
|
-
Ok(out)
|
|
486
|
-
}
|
|
487
|
-
|
|
488
|
-
fn expect_end(&self, context: &str) -> Result<(), LixError> {
|
|
489
|
-
if self.offset != self.bytes.len() {
|
|
490
|
-
return Err(LixError::new(
|
|
491
|
-
LixError::CODE_INTERNAL_ERROR,
|
|
492
|
-
format!("changelog {context} has trailing bytes"),
|
|
493
|
-
));
|
|
494
|
-
}
|
|
495
|
-
Ok(())
|
|
496
|
-
}
|
|
497
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
//! Commit-specific behavior lives here once changelog storage is implemented.
|