@lix-js/sdk 0.6.0-preview.1 → 0.6.0-preview.3
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/SKILL.md +304 -320
- package/dist/engine-wasm/wasm/lix_engine.d.ts +5 -0
- package/dist/engine-wasm/wasm/lix_engine.js +9 -13
- package/dist/engine-wasm/wasm/lix_engine.wasm +0 -0
- package/dist/engine-wasm/wasm/lix_engine.wasm.d.ts +1 -0
- package/dist/generated/builtin-schemas.d.ts +87 -162
- package/dist/generated/builtin-schemas.js +139 -236
- package/dist/open-lix.d.ts +103 -14
- package/dist/open-lix.js +3 -0
- package/dist/sqlite/index.js +99 -22
- package/dist-engine-src/README.md +18 -0
- package/dist-engine-src/src/backend/kv.rs +358 -0
- package/dist-engine-src/src/backend/mod.rs +12 -0
- package/dist-engine-src/src/backend/testing.rs +658 -0
- package/dist-engine-src/src/backend/types.rs +96 -0
- package/dist-engine-src/src/binary_cas/chunking.rs +31 -0
- package/dist-engine-src/src/binary_cas/codec.rs +346 -0
- package/dist-engine-src/src/binary_cas/context.rs +139 -0
- package/dist-engine-src/src/binary_cas/kv.rs +1063 -0
- package/dist-engine-src/src/binary_cas/mod.rs +11 -0
- package/dist-engine-src/src/binary_cas/types.rs +121 -0
- package/dist-engine-src/src/catalog/context.rs +412 -0
- package/dist-engine-src/src/catalog/mod.rs +10 -0
- package/dist-engine-src/src/catalog/schema.rs +4 -0
- package/dist-engine-src/src/catalog/snapshot.rs +1114 -0
- package/dist-engine-src/src/cel/context.rs +86 -0
- package/dist-engine-src/src/cel/error.rs +19 -0
- package/dist-engine-src/src/cel/mod.rs +8 -0
- package/dist-engine-src/src/cel/provider.rs +9 -0
- package/dist-engine-src/src/cel/runtime.rs +167 -0
- package/dist-engine-src/src/cel/value.rs +50 -0
- package/dist-engine-src/src/commit_graph/context.rs +901 -0
- package/dist-engine-src/src/commit_graph/mod.rs +11 -0
- package/dist-engine-src/src/commit_graph/types.rs +109 -0
- package/dist-engine-src/src/commit_graph/walker.rs +756 -0
- package/dist-engine-src/src/commit_store/codec.rs +887 -0
- package/dist-engine-src/src/commit_store/context.rs +944 -0
- package/dist-engine-src/src/commit_store/materialization.rs +84 -0
- package/dist-engine-src/src/commit_store/mod.rs +16 -0
- package/dist-engine-src/src/commit_store/storage.rs +600 -0
- package/dist-engine-src/src/commit_store/types.rs +215 -0
- package/dist-engine-src/src/common/error.rs +313 -0
- package/dist-engine-src/src/common/fingerprint.rs +3 -0
- package/dist-engine-src/src/common/fs_path.rs +1336 -0
- package/dist-engine-src/src/common/identity.rs +145 -0
- package/dist-engine-src/src/common/json_pointer.rs +67 -0
- package/dist-engine-src/src/common/metadata.rs +40 -0
- package/dist-engine-src/src/common/mod.rs +23 -0
- package/dist-engine-src/src/common/types.rs +105 -0
- package/dist-engine-src/src/common/wire.rs +222 -0
- package/dist-engine-src/src/domain.rs +324 -0
- package/dist-engine-src/src/engine.rs +225 -0
- package/dist-engine-src/src/entity_identity.rs +405 -0
- package/dist-engine-src/src/functions/context.rs +292 -0
- package/dist-engine-src/src/functions/deterministic.rs +113 -0
- package/dist-engine-src/src/functions/mod.rs +18 -0
- package/dist-engine-src/src/functions/provider.rs +130 -0
- package/dist-engine-src/src/functions/state.rs +336 -0
- package/dist-engine-src/src/functions/types.rs +37 -0
- package/dist-engine-src/src/init.rs +558 -0
- package/dist-engine-src/src/json_store/compression.rs +77 -0
- package/dist-engine-src/src/json_store/context.rs +423 -0
- package/dist-engine-src/src/json_store/encoded.rs +15 -0
- package/dist-engine-src/src/json_store/mod.rs +12 -0
- package/dist-engine-src/src/json_store/store.rs +1109 -0
- package/dist-engine-src/src/json_store/types.rs +217 -0
- package/dist-engine-src/src/lib.rs +62 -0
- package/dist-engine-src/src/live_state/context.rs +2019 -0
- package/dist-engine-src/src/live_state/mod.rs +15 -0
- package/dist-engine-src/src/live_state/overlay.rs +75 -0
- package/dist-engine-src/src/live_state/reader.rs +23 -0
- package/dist-engine-src/src/live_state/types.rs +222 -0
- package/dist-engine-src/src/live_state/visibility.rs +223 -0
- package/dist-engine-src/src/plugin/archive.rs +438 -0
- package/dist-engine-src/src/plugin/component.rs +183 -0
- package/dist-engine-src/src/plugin/install.rs +619 -0
- package/dist-engine-src/src/plugin/manifest.rs +516 -0
- package/dist-engine-src/src/plugin/materializer.rs +477 -0
- package/dist-engine-src/src/plugin/mod.rs +33 -0
- package/dist-engine-src/src/plugin/plugin_manifest.json +118 -0
- package/dist-engine-src/src/plugin/storage.rs +74 -0
- package/dist-engine-src/src/schema/annotations/defaults.rs +275 -0
- package/dist-engine-src/src/schema/annotations/mod.rs +1 -0
- package/dist-engine-src/src/schema/builtin/lix_account.json +21 -0
- package/dist-engine-src/src/schema/builtin/lix_active_account.json +29 -0
- package/dist-engine-src/src/schema/builtin/lix_binary_blob_ref.json +29 -0
- package/dist-engine-src/src/schema/builtin/lix_change.json +63 -0
- package/dist-engine-src/src/schema/builtin/lix_change_author.json +45 -0
- package/dist-engine-src/src/schema/builtin/lix_commit.json +24 -0
- package/dist-engine-src/src/schema/builtin/lix_commit_edge.json +53 -0
- package/dist-engine-src/src/schema/builtin/lix_directory_descriptor.json +52 -0
- package/dist-engine-src/src/schema/builtin/lix_file_descriptor.json +52 -0
- package/dist-engine-src/src/schema/builtin/lix_key_value.json +40 -0
- package/dist-engine-src/src/schema/builtin/lix_label.json +29 -0
- package/dist-engine-src/src/schema/builtin/lix_label_assignment.json +74 -0
- package/dist-engine-src/src/schema/builtin/lix_registered_schema.json +25 -0
- package/dist-engine-src/src/schema/builtin/lix_version_descriptor.json +34 -0
- package/dist-engine-src/src/schema/builtin/lix_version_ref.json +48 -0
- package/dist-engine-src/src/schema/builtin/mod.rs +222 -0
- package/dist-engine-src/src/schema/compatibility.rs +787 -0
- package/dist-engine-src/src/schema/definition.json +187 -0
- package/dist-engine-src/src/schema/definition.rs +742 -0
- package/dist-engine-src/src/schema/key.rs +138 -0
- package/dist-engine-src/src/schema/mod.rs +20 -0
- package/dist-engine-src/src/schema/seed.rs +14 -0
- package/dist-engine-src/src/schema/tests.rs +780 -0
- package/dist-engine-src/src/session/context.rs +364 -0
- package/dist-engine-src/src/session/create_version.rs +88 -0
- package/dist-engine-src/src/session/execute.rs +478 -0
- package/dist-engine-src/src/session/merge/analysis.rs +102 -0
- package/dist-engine-src/src/session/merge/apply.rs +23 -0
- package/dist-engine-src/src/session/merge/conflicts.rs +63 -0
- package/dist-engine-src/src/session/merge/mod.rs +11 -0
- package/dist-engine-src/src/session/merge/stats.rs +65 -0
- package/dist-engine-src/src/session/merge/version.rs +427 -0
- package/dist-engine-src/src/session/mod.rs +27 -0
- package/dist-engine-src/src/session/optimization9_sql2_bench.rs +100 -0
- package/dist-engine-src/src/session/switch_version.rs +109 -0
- package/dist-engine-src/src/sql2/change_provider.rs +331 -0
- package/dist-engine-src/src/sql2/classify.rs +182 -0
- package/dist-engine-src/src/sql2/context.rs +311 -0
- package/dist-engine-src/src/sql2/directory_history_provider.rs +631 -0
- package/dist-engine-src/src/sql2/directory_provider.rs +2453 -0
- package/dist-engine-src/src/sql2/dml.rs +148 -0
- package/dist-engine-src/src/sql2/entity_history_provider.rs +440 -0
- package/dist-engine-src/src/sql2/entity_provider.rs +3211 -0
- package/dist-engine-src/src/sql2/error.rs +216 -0
- package/dist-engine-src/src/sql2/execute.rs +3440 -0
- package/dist-engine-src/src/sql2/file_history_provider.rs +910 -0
- package/dist-engine-src/src/sql2/file_provider.rs +3679 -0
- package/dist-engine-src/src/sql2/filesystem_planner.rs +1490 -0
- package/dist-engine-src/src/sql2/filesystem_predicates.rs +159 -0
- package/dist-engine-src/src/sql2/filesystem_visibility.rs +383 -0
- package/dist-engine-src/src/sql2/history_projection.rs +56 -0
- package/dist-engine-src/src/sql2/history_provider.rs +412 -0
- package/dist-engine-src/src/sql2/history_route.rs +657 -0
- package/dist-engine-src/src/sql2/lix_state_provider.rs +2512 -0
- package/dist-engine-src/src/sql2/mod.rs +46 -0
- package/dist-engine-src/src/sql2/predicate_typecheck.rs +246 -0
- package/dist-engine-src/src/sql2/public_bind/assignment.rs +46 -0
- package/dist-engine-src/src/sql2/public_bind/capability.rs +41 -0
- package/dist-engine-src/src/sql2/public_bind/dml.rs +166 -0
- package/dist-engine-src/src/sql2/public_bind/mod.rs +25 -0
- package/dist-engine-src/src/sql2/public_bind/table.rs +168 -0
- package/dist-engine-src/src/sql2/read_only.rs +63 -0
- package/dist-engine-src/src/sql2/record_batch.rs +17 -0
- package/dist-engine-src/src/sql2/result_metadata.rs +29 -0
- package/dist-engine-src/src/sql2/runtime.rs +60 -0
- package/dist-engine-src/src/sql2/session.rs +132 -0
- package/dist-engine-src/src/sql2/udfs/common.rs +295 -0
- package/dist-engine-src/src/sql2/udfs/lix_active_version_commit_id.rs +53 -0
- package/dist-engine-src/src/sql2/udfs/lix_empty_blob.rs +47 -0
- package/dist-engine-src/src/sql2/udfs/lix_json.rs +100 -0
- package/dist-engine-src/src/sql2/udfs/lix_json_get.rs +99 -0
- package/dist-engine-src/src/sql2/udfs/lix_json_get_text.rs +99 -0
- package/dist-engine-src/src/sql2/udfs/lix_text_decode.rs +82 -0
- package/dist-engine-src/src/sql2/udfs/lix_text_encode.rs +85 -0
- package/dist-engine-src/src/sql2/udfs/lix_timestamp.rs +76 -0
- package/dist-engine-src/src/sql2/udfs/lix_uuid_v7.rs +76 -0
- package/dist-engine-src/src/sql2/udfs/mod.rs +89 -0
- package/dist-engine-src/src/sql2/udfs/public_call.rs +211 -0
- package/dist-engine-src/src/sql2/version_provider.rs +1202 -0
- package/dist-engine-src/src/sql2/version_scope.rs +394 -0
- package/dist-engine-src/src/sql2/write_normalization.rs +345 -0
- package/dist-engine-src/src/storage/context.rs +356 -0
- package/dist-engine-src/src/storage/mod.rs +14 -0
- package/dist-engine-src/src/storage/read_scope.rs +88 -0
- package/dist-engine-src/src/storage/types.rs +501 -0
- package/dist-engine-src/src/storage_bench.rs +4863 -0
- package/dist-engine-src/src/test_support.rs +228 -0
- package/dist-engine-src/src/tracked_state/by_file_index.rs +98 -0
- package/dist-engine-src/src/tracked_state/codec.rs +2085 -0
- package/dist-engine-src/src/tracked_state/context.rs +1867 -0
- package/dist-engine-src/src/tracked_state/diff.rs +686 -0
- package/dist-engine-src/src/tracked_state/materialization.rs +403 -0
- package/dist-engine-src/src/tracked_state/materializer.rs +488 -0
- package/dist-engine-src/src/tracked_state/merge.rs +492 -0
- package/dist-engine-src/src/tracked_state/mod.rs +32 -0
- package/dist-engine-src/src/tracked_state/storage.rs +375 -0
- package/dist-engine-src/src/tracked_state/tree.rs +3187 -0
- package/dist-engine-src/src/tracked_state/types.rs +231 -0
- package/dist-engine-src/src/transaction/commit.rs +1484 -0
- package/dist-engine-src/src/transaction/context.rs +1548 -0
- package/dist-engine-src/src/transaction/live_state_overlay.rs +35 -0
- package/dist-engine-src/src/transaction/mod.rs +13 -0
- package/dist-engine-src/src/transaction/normalization.rs +890 -0
- package/dist-engine-src/src/transaction/prep.rs +37 -0
- package/dist-engine-src/src/transaction/schema_resolver.rs +149 -0
- package/dist-engine-src/src/transaction/staging.rs +1731 -0
- package/dist-engine-src/src/transaction/types.rs +460 -0
- package/dist-engine-src/src/transaction/validation.rs +5830 -0
- package/dist-engine-src/src/untracked_state/codec.rs +307 -0
- package/dist-engine-src/src/untracked_state/context.rs +98 -0
- package/dist-engine-src/src/untracked_state/materialization.rs +63 -0
- package/dist-engine-src/src/untracked_state/mod.rs +15 -0
- package/dist-engine-src/src/untracked_state/storage.rs +396 -0
- package/dist-engine-src/src/untracked_state/types.rs +146 -0
- package/dist-engine-src/src/version/context.rs +40 -0
- package/dist-engine-src/src/version/lifecycle.rs +221 -0
- package/dist-engine-src/src/version/mod.rs +13 -0
- package/dist-engine-src/src/version/refs.rs +330 -0
- package/dist-engine-src/src/version/stage_rows.rs +67 -0
- package/dist-engine-src/src/version/types.rs +21 -0
- package/dist-engine-src/src/wasm/mod.rs +60 -0
- package/package.json +68 -64
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
use crate::entity_identity::EntityIdentity;
|
|
2
|
+
use crate::json_store::JsonRef;
|
|
3
|
+
|
|
4
|
+
/// Physical append/locality unit for commit metadata and derived commit SQL
|
|
5
|
+
/// surfaces.
|
|
6
|
+
#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
|
|
7
|
+
pub(crate) struct Commit {
|
|
8
|
+
pub(crate) id: String,
|
|
9
|
+
pub(crate) change_id: String,
|
|
10
|
+
pub(crate) parent_ids: Vec<String>,
|
|
11
|
+
pub(crate) author_account_ids: Vec<String>,
|
|
12
|
+
pub(crate) created_at: String,
|
|
13
|
+
pub(crate) change_pack_count: u32,
|
|
14
|
+
pub(crate) membership_pack_count: u32,
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
impl Commit {
|
|
18
|
+
pub(crate) fn as_ref(&self) -> StoredCommitRef<'_> {
|
|
19
|
+
StoredCommitRef {
|
|
20
|
+
id: &self.id,
|
|
21
|
+
change_id: &self.change_id,
|
|
22
|
+
parent_ids: &self.parent_ids,
|
|
23
|
+
author_account_ids: &self.author_account_ids,
|
|
24
|
+
created_at: &self.created_at,
|
|
25
|
+
change_pack_count: self.change_pack_count,
|
|
26
|
+
membership_pack_count: self.membership_pack_count,
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/// Zero-copy view of stored [`Commit`] bytes.
|
|
32
|
+
#[derive(Debug, Clone, Copy)]
|
|
33
|
+
pub(crate) struct StoredCommitRef<'a> {
|
|
34
|
+
pub(crate) id: &'a str,
|
|
35
|
+
pub(crate) change_id: &'a str,
|
|
36
|
+
pub(crate) parent_ids: &'a [String],
|
|
37
|
+
pub(crate) author_account_ids: &'a [String],
|
|
38
|
+
pub(crate) created_at: &'a str,
|
|
39
|
+
pub(crate) change_pack_count: u32,
|
|
40
|
+
pub(crate) membership_pack_count: u32,
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/// Zero-copy view of a logical commit supplied before physical packing.
|
|
44
|
+
#[derive(Debug, Clone, Copy)]
|
|
45
|
+
pub(crate) struct CommitDraftRef<'a> {
|
|
46
|
+
pub(crate) id: &'a str,
|
|
47
|
+
pub(crate) change_id: &'a str,
|
|
48
|
+
pub(crate) parent_ids: &'a [String],
|
|
49
|
+
pub(crate) author_account_ids: &'a [String],
|
|
50
|
+
pub(crate) created_at: &'a str,
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/// Logical entity mutation fact stored in a commit change pack.
|
|
54
|
+
#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
|
|
55
|
+
pub(crate) struct Change {
|
|
56
|
+
pub(crate) id: String,
|
|
57
|
+
pub(crate) entity_id: EntityIdentity,
|
|
58
|
+
pub(crate) schema_key: String,
|
|
59
|
+
pub(crate) file_id: Option<String>,
|
|
60
|
+
pub(crate) snapshot_ref: Option<JsonRef>,
|
|
61
|
+
pub(crate) metadata_ref: Option<JsonRef>,
|
|
62
|
+
pub(crate) created_at: String,
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/// Read-boundary view of a commit-store change with JSON refs resolved.
|
|
66
|
+
#[derive(Debug, Clone, PartialEq, Eq)]
|
|
67
|
+
pub(crate) struct MaterializedChange {
|
|
68
|
+
pub(crate) id: String,
|
|
69
|
+
pub(crate) entity_id: EntityIdentity,
|
|
70
|
+
pub(crate) schema_key: String,
|
|
71
|
+
pub(crate) file_id: Option<String>,
|
|
72
|
+
pub(crate) snapshot_content: Option<String>,
|
|
73
|
+
pub(crate) metadata: Option<String>,
|
|
74
|
+
pub(crate) created_at: String,
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/// Commit-store change plus the physical pack that owns its JSON payloads.
|
|
78
|
+
#[derive(Debug, Clone, PartialEq, Eq)]
|
|
79
|
+
pub(crate) struct LocatedChange {
|
|
80
|
+
pub(crate) record: Change,
|
|
81
|
+
pub(crate) source_commit_id: String,
|
|
82
|
+
pub(crate) source_pack_id: u32,
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
impl Change {
|
|
86
|
+
pub(crate) fn as_ref(&self) -> ChangeRef<'_> {
|
|
87
|
+
ChangeRef {
|
|
88
|
+
id: &self.id,
|
|
89
|
+
entity_id: &self.entity_id,
|
|
90
|
+
schema_key: &self.schema_key,
|
|
91
|
+
file_id: self.file_id.as_deref(),
|
|
92
|
+
snapshot_ref: self.snapshot_ref.as_ref(),
|
|
93
|
+
metadata_ref: self.metadata_ref.as_ref(),
|
|
94
|
+
created_at: &self.created_at,
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/// Zero-copy view of [`Change`].
|
|
100
|
+
#[derive(Debug, Clone, Copy)]
|
|
101
|
+
pub(crate) struct ChangeRef<'a> {
|
|
102
|
+
pub(crate) id: &'a str,
|
|
103
|
+
pub(crate) entity_id: &'a EntityIdentity,
|
|
104
|
+
pub(crate) schema_key: &'a str,
|
|
105
|
+
pub(crate) file_id: Option<&'a str>,
|
|
106
|
+
pub(crate) snapshot_ref: Option<&'a JsonRef>,
|
|
107
|
+
pub(crate) metadata_ref: Option<&'a JsonRef>,
|
|
108
|
+
pub(crate) created_at: &'a str,
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/// Logical scan request for the `lix_change` SQL surface over commit_store.
|
|
112
|
+
#[derive(Debug, Clone, Default)]
|
|
113
|
+
pub(crate) struct ChangeScanRequest {
|
|
114
|
+
pub(crate) limit: Option<usize>,
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/// Commit-local physical pack of newly authored change payloads.
|
|
118
|
+
#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
|
|
119
|
+
pub(crate) struct ChangePack {
|
|
120
|
+
pub(crate) commit_id: String,
|
|
121
|
+
pub(crate) pack_id: u32,
|
|
122
|
+
pub(crate) changes: Vec<Change>,
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
impl ChangePack {
|
|
126
|
+
pub(crate) fn as_view(&self) -> ChangePackView<'_> {
|
|
127
|
+
ChangePackView {
|
|
128
|
+
commit_id: &self.commit_id,
|
|
129
|
+
pack_id: self.pack_id,
|
|
130
|
+
changes: &self.changes,
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/// Zero-copy view for a decoded [`ChangePack`].
|
|
136
|
+
#[derive(Debug, Clone, Copy)]
|
|
137
|
+
pub(crate) struct ChangePackView<'a> {
|
|
138
|
+
pub(crate) commit_id: &'a str,
|
|
139
|
+
pub(crate) pack_id: u32,
|
|
140
|
+
pub(crate) changes: &'a [Change],
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/// Storage location of an existing change payload.
|
|
144
|
+
#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
|
|
145
|
+
pub(crate) struct ChangeLocator {
|
|
146
|
+
pub(crate) source_commit_id: String,
|
|
147
|
+
pub(crate) source_pack_id: u32,
|
|
148
|
+
pub(crate) source_ordinal: u32,
|
|
149
|
+
pub(crate) change_id: String,
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
impl ChangeLocator {
|
|
153
|
+
pub(crate) fn as_ref(&self) -> ChangeLocatorRef<'_> {
|
|
154
|
+
ChangeLocatorRef {
|
|
155
|
+
source_commit_id: &self.source_commit_id,
|
|
156
|
+
source_pack_id: self.source_pack_id,
|
|
157
|
+
source_ordinal: self.source_ordinal,
|
|
158
|
+
change_id: &self.change_id,
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/// Zero-copy view of [`ChangeLocator`].
|
|
164
|
+
#[derive(Debug, Clone, Copy)]
|
|
165
|
+
pub(crate) struct ChangeLocatorRef<'a> {
|
|
166
|
+
pub(crate) source_commit_id: &'a str,
|
|
167
|
+
pub(crate) source_pack_id: u32,
|
|
168
|
+
pub(crate) source_ordinal: u32,
|
|
169
|
+
pub(crate) change_id: &'a str,
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/// Exact lookup entry for a derived-surface-visible change id.
|
|
173
|
+
#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
|
|
174
|
+
pub(crate) enum ChangeIndexEntry {
|
|
175
|
+
CommitHeader {
|
|
176
|
+
commit_id: String,
|
|
177
|
+
change_id: String,
|
|
178
|
+
},
|
|
179
|
+
PackedChange {
|
|
180
|
+
locator: ChangeLocator,
|
|
181
|
+
},
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/// Commit-local physical pack of adopted/shared membership locators.
|
|
185
|
+
#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
|
|
186
|
+
pub(crate) struct MembershipPack {
|
|
187
|
+
pub(crate) commit_id: String,
|
|
188
|
+
pub(crate) pack_id: u32,
|
|
189
|
+
pub(crate) members: Vec<ChangeLocator>,
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
impl MembershipPack {
|
|
193
|
+
pub(crate) fn as_view(&self) -> MembershipPackView<'_> {
|
|
194
|
+
MembershipPackView {
|
|
195
|
+
commit_id: &self.commit_id,
|
|
196
|
+
pack_id: self.pack_id,
|
|
197
|
+
members: &self.members,
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/// Zero-copy view for a decoded [`MembershipPack`].
|
|
203
|
+
#[derive(Debug, Clone, Copy)]
|
|
204
|
+
pub(crate) struct MembershipPackView<'a> {
|
|
205
|
+
pub(crate) commit_id: &'a str,
|
|
206
|
+
pub(crate) pack_id: u32,
|
|
207
|
+
pub(crate) members: &'a [ChangeLocator],
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/// Locators produced while staging a commit.
|
|
211
|
+
#[derive(Debug, Clone, PartialEq, Eq)]
|
|
212
|
+
pub(crate) struct StagedCommitStoreCommit {
|
|
213
|
+
pub(crate) authored_locators: Vec<ChangeLocator>,
|
|
214
|
+
pub(crate) adopted_locators: Vec<ChangeLocator>,
|
|
215
|
+
}
|
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
use serde_json::{json, Value as JsonValue};
|
|
2
|
+
|
|
3
|
+
/// Structured error type surfaced by Lix to every SDK binding.
|
|
4
|
+
///
|
|
5
|
+
/// Carries a machine-readable [`code`](Self::code), a human-readable
|
|
6
|
+
/// [`message`](Self::message), and an optional [`hint`](Self::hint)
|
|
7
|
+
/// suggesting how to recover. Hints follow the Postgres/rustc convention:
|
|
8
|
+
/// `message` states what went wrong in factual terms, and `hint` offers a
|
|
9
|
+
/// possible fix when one is known.
|
|
10
|
+
///
|
|
11
|
+
/// ```
|
|
12
|
+
/// use lix_engine::LixError;
|
|
13
|
+
///
|
|
14
|
+
/// let err = LixError::new(
|
|
15
|
+
/// "LIX_ERROR_UNSUPPORTED_WRITE_EXPRESSION",
|
|
16
|
+
/// "json(...) is not supported",
|
|
17
|
+
/// )
|
|
18
|
+
/// .with_hint("use lix_json('...') instead");
|
|
19
|
+
///
|
|
20
|
+
/// assert_eq!(err.hint(), Some("use lix_json('...') instead"));
|
|
21
|
+
/// ```
|
|
22
|
+
#[derive(Debug, Clone, PartialEq, Eq)]
|
|
23
|
+
pub struct LixError {
|
|
24
|
+
pub code: String,
|
|
25
|
+
pub message: String,
|
|
26
|
+
pub hint: Option<String>,
|
|
27
|
+
pub details: Option<JsonValue>,
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
impl LixError {
|
|
31
|
+
/// True fallback — use when no more specific category fits. Producing
|
|
32
|
+
/// sites should prefer the categorized codes below whenever possible;
|
|
33
|
+
/// the SDK contract is that `LIX_ERROR_UNKNOWN` is the *last* resort,
|
|
34
|
+
/// never the default.
|
|
35
|
+
pub const CODE_UNKNOWN: &'static str = "LIX_ERROR_UNKNOWN";
|
|
36
|
+
|
|
37
|
+
/// SQL text could not be parsed.
|
|
38
|
+
pub const CODE_PARSE_ERROR: &'static str = "LIX_PARSE_ERROR";
|
|
39
|
+
|
|
40
|
+
/// A SQL function name could not be resolved.
|
|
41
|
+
pub const CODE_UDF_NOT_FOUND: &'static str = "LIX_UDF_NOT_FOUND";
|
|
42
|
+
|
|
43
|
+
/// A SQL expression or function argument had an incompatible type.
|
|
44
|
+
pub const CODE_TYPE_MISMATCH: &'static str = "LIX_TYPE_MISMATCH";
|
|
45
|
+
|
|
46
|
+
/// A Lix JSON path argument used another dialect's path language instead
|
|
47
|
+
/// of Lix's canonical variadic key/index segments.
|
|
48
|
+
pub const CODE_INVALID_JSON_PATH: &'static str = "LIX_INVALID_JSON_PATH";
|
|
49
|
+
|
|
50
|
+
/// SQL syntax belongs to another dialect and is outside the Lix SQL
|
|
51
|
+
/// surface.
|
|
52
|
+
pub const CODE_DIALECT_UNSUPPORTED: &'static str = "LIX_DIALECT_UNSUPPORTED";
|
|
53
|
+
|
|
54
|
+
/// SQL parameters could not be bound to placeholders.
|
|
55
|
+
pub const CODE_BINDING_ERROR: &'static str = "LIX_BINDING_ERROR";
|
|
56
|
+
|
|
57
|
+
/// A caller supplied an invalid SQL parameter value or parameter list.
|
|
58
|
+
pub const CODE_INVALID_PARAM: &'static str = "LIX_INVALID_PARAM";
|
|
59
|
+
|
|
60
|
+
/// A SQL table or view name could not be resolved.
|
|
61
|
+
pub const CODE_TABLE_NOT_FOUND: &'static str = "LIX_TABLE_NOT_FOUND";
|
|
62
|
+
|
|
63
|
+
/// A SQL column name could not be resolved in the available projection.
|
|
64
|
+
pub const CODE_COLUMN_NOT_FOUND: &'static str = "LIX_COLUMN_NOT_FOUND";
|
|
65
|
+
|
|
66
|
+
/// A SQL write violated a primary-key, unique, NOT NULL, or other
|
|
67
|
+
/// relational constraint.
|
|
68
|
+
pub const CODE_CONSTRAINT_VIOLATION: &'static str = "LIX_CONSTRAINT_VIOLATION";
|
|
69
|
+
|
|
70
|
+
/// A SQL write targeted a read-only internal/component surface.
|
|
71
|
+
pub const CODE_READ_ONLY: &'static str = "LIX_ERROR_READ_ONLY";
|
|
72
|
+
|
|
73
|
+
/// A history table was queried without an explicit commit/version range.
|
|
74
|
+
pub const CODE_HISTORY_FILTER_REQUIRED: &'static str = "LIX_HISTORY_FILTER_REQUIRED";
|
|
75
|
+
|
|
76
|
+
/// SQL syntax is valid, but the feature is intentionally outside the Lix
|
|
77
|
+
/// SQL surface.
|
|
78
|
+
pub const CODE_UNSUPPORTED_SQL: &'static str = "LIX_UNSUPPORTED_SQL";
|
|
79
|
+
|
|
80
|
+
/// SQL planning succeeded far enough to produce a physical runtime shape
|
|
81
|
+
/// that the current engine target cannot execute safely.
|
|
82
|
+
pub const CODE_UNSUPPORTED_SQL_RUNTIME_PLAN: &'static str = "LIX_UNSUPPORTED_SQL_RUNTIME_PLAN";
|
|
83
|
+
|
|
84
|
+
/// Storage/backend IO failed while executing an operation.
|
|
85
|
+
pub const CODE_STORAGE_ERROR: &'static str = "LIX_STORAGE_ERROR";
|
|
86
|
+
|
|
87
|
+
/// An internal engine invariant failed.
|
|
88
|
+
pub const CODE_INTERNAL_ERROR: &'static str = "LIX_INTERNAL_ERROR";
|
|
89
|
+
|
|
90
|
+
/// Write-time failure where user data did not conform to a registered
|
|
91
|
+
/// schema (type mismatch, missing required field, pattern violation,
|
|
92
|
+
/// additionalProperties, etc.). Raised from the JSON-Schema validator
|
|
93
|
+
/// run over a candidate row's snapshot.
|
|
94
|
+
pub const CODE_SCHEMA_VALIDATION: &'static str = "LIX_ERROR_SCHEMA_VALIDATION";
|
|
95
|
+
|
|
96
|
+
/// A foreign-key constraint could not be satisfied. Covers both the
|
|
97
|
+
/// insert-side "no matching target row" failure and the delete-side
|
|
98
|
+
/// "still referenced" (restrict) failure.
|
|
99
|
+
pub const CODE_FOREIGN_KEY: &'static str = "LIX_ERROR_FOREIGN_KEY";
|
|
100
|
+
|
|
101
|
+
/// A row references a non-null `file_id` that has no matching `lix_file`
|
|
102
|
+
/// descriptor in the same effective version scope.
|
|
103
|
+
pub const CODE_FILE_NOT_FOUND: &'static str = "LIX_ERROR_FILE_NOT_FOUND";
|
|
104
|
+
|
|
105
|
+
/// A primary-key or `x-lix-unique` constraint was violated — another
|
|
106
|
+
/// row already owns the value(s) for the declared pointer group.
|
|
107
|
+
pub const CODE_UNIQUE: &'static str = "LIX_ERROR_UNIQUE";
|
|
108
|
+
|
|
109
|
+
/// An `INSERT ... VALUES (...)` expression is not supported by the
|
|
110
|
+
/// public write surface (e.g. `json(...)`, subqueries, arbitrary SQL
|
|
111
|
+
/// expressions). Users should wrap inline JSON with `lix_json(...)`.
|
|
112
|
+
pub const CODE_UNSUPPORTED_WRITE_EXPRESSION: &'static str =
|
|
113
|
+
"LIX_ERROR_UNSUPPORTED_WRITE_EXPRESSION";
|
|
114
|
+
|
|
115
|
+
/// The schema JSON itself (the *definition*, not a row against it) is
|
|
116
|
+
/// malformed — a missing `x-lix-key`, a JSON-Pointer without the
|
|
117
|
+
/// leading slash, a reserved-namespace collision, or any other
|
|
118
|
+
/// meta-schema validation failure.
|
|
119
|
+
pub const CODE_SCHEMA_DEFINITION: &'static str = "LIX_ERROR_SCHEMA_DEFINITION";
|
|
120
|
+
|
|
121
|
+
/// The logical Lix handle/session has been closed and cannot run further
|
|
122
|
+
/// operations. Close is a resource-release lifecycle boundary, not a
|
|
123
|
+
/// durability boundary.
|
|
124
|
+
pub const CODE_CLOSED: &'static str = "LIX_ERROR_CLOSED";
|
|
125
|
+
|
|
126
|
+
/// A merge found incompatible changes to the same tracked-state identity.
|
|
127
|
+
pub const CODE_MERGE_CONFLICT: &'static str = "LIX_MERGE_CONFLICT";
|
|
128
|
+
|
|
129
|
+
/// A caller referenced a version id that has no matching version ref.
|
|
130
|
+
pub const CODE_VERSION_NOT_FOUND: &'static str = "LIX_VERSION_NOT_FOUND";
|
|
131
|
+
|
|
132
|
+
/// A staged row's storage scope flags disagree, such as a global row not
|
|
133
|
+
/// using the reserved global version id.
|
|
134
|
+
pub const CODE_INVALID_STORAGE_SCOPE: &'static str = "LIX_ERROR_INVALID_STORAGE_SCOPE";
|
|
135
|
+
|
|
136
|
+
/// Merge graph analysis found multiple equally valid merge bases.
|
|
137
|
+
pub const CODE_AMBIGUOUS_MERGE_BASE: &'static str = "LIX_AMBIGUOUS_MERGE_BASE";
|
|
138
|
+
|
|
139
|
+
/// A merge request is well-formed but nonsensical for the commit graph,
|
|
140
|
+
/// such as merging a version into itself.
|
|
141
|
+
pub const CODE_INVALID_MERGE: &'static str = "LIX_INVALID_MERGE";
|
|
142
|
+
|
|
143
|
+
pub fn new(code: impl Into<String>, message: impl Into<String>) -> Self {
|
|
144
|
+
Self {
|
|
145
|
+
code: code.into(),
|
|
146
|
+
message: message.into(),
|
|
147
|
+
hint: None,
|
|
148
|
+
details: None,
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
pub fn unknown(message: impl Into<String>) -> Self {
|
|
153
|
+
Self::new("LIX_ERROR_UNKNOWN", message)
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
pub fn version_not_found(
|
|
157
|
+
version_id: impl Into<String>,
|
|
158
|
+
operation: impl Into<String>,
|
|
159
|
+
role: impl Into<String>,
|
|
160
|
+
) -> Self {
|
|
161
|
+
let version_id = version_id.into();
|
|
162
|
+
let operation = operation.into();
|
|
163
|
+
let role = role.into();
|
|
164
|
+
Self::new(
|
|
165
|
+
Self::CODE_VERSION_NOT_FOUND,
|
|
166
|
+
format!("version '{version_id}' was not found"),
|
|
167
|
+
)
|
|
168
|
+
.with_details(json!({
|
|
169
|
+
"version_id": version_id,
|
|
170
|
+
"operation": operation,
|
|
171
|
+
"role": role,
|
|
172
|
+
}))
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
pub fn ambiguous_merge_base(
|
|
176
|
+
left_commit_id: impl Into<String>,
|
|
177
|
+
right_commit_id: impl Into<String>,
|
|
178
|
+
candidates: Vec<String>,
|
|
179
|
+
) -> Self {
|
|
180
|
+
let left_commit_id = left_commit_id.into();
|
|
181
|
+
let right_commit_id = right_commit_id.into();
|
|
182
|
+
Self::new(
|
|
183
|
+
Self::CODE_AMBIGUOUS_MERGE_BASE,
|
|
184
|
+
format!("ambiguous merge base between '{left_commit_id}' and '{right_commit_id}'"),
|
|
185
|
+
)
|
|
186
|
+
.with_details(json!({
|
|
187
|
+
"left_commit_id": left_commit_id,
|
|
188
|
+
"right_commit_id": right_commit_id,
|
|
189
|
+
"candidates": candidates,
|
|
190
|
+
}))
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
pub fn invalid_self_merge(version_id: impl Into<String>) -> Self {
|
|
194
|
+
let version_id = version_id.into();
|
|
195
|
+
Self::new(
|
|
196
|
+
Self::CODE_INVALID_MERGE,
|
|
197
|
+
format!("cannot merge version '{version_id}' into itself"),
|
|
198
|
+
)
|
|
199
|
+
.with_details(json!({
|
|
200
|
+
"operation": "merge_version",
|
|
201
|
+
"target_version_id": version_id,
|
|
202
|
+
"source_version_id": version_id,
|
|
203
|
+
}))
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/// Attach a hint to this error. Consumers render hints alongside the
|
|
207
|
+
/// primary message (e.g. a CLI prints them as `hint: <text>`).
|
|
208
|
+
///
|
|
209
|
+
/// ```
|
|
210
|
+
/// use lix_engine::LixError;
|
|
211
|
+
///
|
|
212
|
+
/// let err = LixError::new("CODE", "boom").with_hint("try this");
|
|
213
|
+
/// assert_eq!(err.hint(), Some("try this"));
|
|
214
|
+
/// ```
|
|
215
|
+
pub fn with_hint(mut self, hint: impl Into<String>) -> Self {
|
|
216
|
+
self.hint = Some(hint.into());
|
|
217
|
+
self
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/// Attach machine-readable details to this error.
|
|
221
|
+
pub fn with_details(mut self, details: JsonValue) -> Self {
|
|
222
|
+
self.details = Some(details);
|
|
223
|
+
self
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/// Return the attached hint, if any.
|
|
227
|
+
///
|
|
228
|
+
/// Returns `None` when no hint was attached at the error's producer
|
|
229
|
+
/// site. This is the accessor SDK consumers should prefer over
|
|
230
|
+
/// reading the `hint` field directly — it returns `Option<&str>`,
|
|
231
|
+
/// avoiding the need for `.as_deref()` at the call site.
|
|
232
|
+
///
|
|
233
|
+
/// ```
|
|
234
|
+
/// use lix_engine::LixError;
|
|
235
|
+
///
|
|
236
|
+
/// let without_hint = LixError::new("CODE", "boom");
|
|
237
|
+
/// assert_eq!(without_hint.hint(), None);
|
|
238
|
+
///
|
|
239
|
+
/// let with_hint = LixError::new("CODE", "boom").with_hint("fix it");
|
|
240
|
+
/// assert_eq!(with_hint.hint(), Some("fix it"));
|
|
241
|
+
/// ```
|
|
242
|
+
pub fn hint(&self) -> Option<&str> {
|
|
243
|
+
self.hint.as_deref()
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
pub fn message_with_hint(&self) -> String {
|
|
247
|
+
match self.hint() {
|
|
248
|
+
Some(hint) => format!("{}\nhint: {hint}", self.message),
|
|
249
|
+
None => self.message.clone(),
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
pub fn format(&self) -> String {
|
|
254
|
+
let mut s = format!("code: {}\nmessage: {}", self.code, self.message);
|
|
255
|
+
if let Some(hint) = &self.hint {
|
|
256
|
+
s.push_str(&format!("\nhint: {hint}"));
|
|
257
|
+
}
|
|
258
|
+
s
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
impl std::fmt::Display for LixError {
|
|
263
|
+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
264
|
+
write!(f, "{}", self.format())
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
impl std::error::Error for LixError {}
|
|
269
|
+
|
|
270
|
+
#[cfg(test)]
|
|
271
|
+
mod tests {
|
|
272
|
+
use super::*;
|
|
273
|
+
|
|
274
|
+
#[test]
|
|
275
|
+
fn format_without_hint_omits_hint_line() {
|
|
276
|
+
let err = LixError::new("LIX_ERROR_FOO", "something went wrong");
|
|
277
|
+
assert_eq!(
|
|
278
|
+
err.format(),
|
|
279
|
+
"code: LIX_ERROR_FOO\nmessage: something went wrong"
|
|
280
|
+
);
|
|
281
|
+
assert!(err.hint.is_none());
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
#[test]
|
|
285
|
+
fn format_with_hint_appends_hint_line() {
|
|
286
|
+
let err = LixError::new("LIX_ERROR_FOO", "something went wrong").with_hint("try the fix");
|
|
287
|
+
assert_eq!(
|
|
288
|
+
err.format(),
|
|
289
|
+
"code: LIX_ERROR_FOO\nmessage: something went wrong\nhint: try the fix"
|
|
290
|
+
);
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
#[test]
|
|
294
|
+
fn with_hint_is_chainable_and_replaces_prior_hint() {
|
|
295
|
+
let err = LixError::new("LIX_ERROR_FOO", "desc")
|
|
296
|
+
.with_hint("first")
|
|
297
|
+
.with_hint("second");
|
|
298
|
+
assert_eq!(err.hint.as_deref(), Some("second"));
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
#[test]
|
|
302
|
+
fn new_defaults_hint_to_none() {
|
|
303
|
+
let err = LixError::new("CODE", "desc");
|
|
304
|
+
assert_eq!(err.hint, None);
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
#[test]
|
|
308
|
+
fn unknown_defaults_hint_to_none() {
|
|
309
|
+
let err = LixError::unknown("desc");
|
|
310
|
+
assert_eq!(err.code, "LIX_ERROR_UNKNOWN");
|
|
311
|
+
assert_eq!(err.hint, None);
|
|
312
|
+
}
|
|
313
|
+
}
|