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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (274) hide show
  1. package/README.md +76 -4
  2. package/dist/errors.d.ts +7 -0
  3. package/dist/errors.js +19 -0
  4. package/dist/index.d.ts +4 -5
  5. package/dist/index.js +3 -3
  6. package/dist/native.d.ts +1 -0
  7. package/dist/native.js +47 -0
  8. package/dist/open-lix.d.ts +38 -207
  9. package/dist/open-lix.js +59 -284
  10. package/dist/result.d.ts +18 -0
  11. package/dist/result.js +48 -0
  12. package/dist/types.d.ts +114 -1
  13. package/dist/value.d.ts +28 -0
  14. package/dist/value.js +245 -0
  15. package/package.json +38 -71
  16. package/SKILL.md +0 -507
  17. package/dist/builtin-schemas.d.ts +0 -1
  18. package/dist/builtin-schemas.js +0 -1
  19. package/dist/engine-wasm/index.d.ts +0 -87
  20. package/dist/engine-wasm/index.js +0 -339
  21. package/dist/engine-wasm/wasm/lix_engine.d.ts +0 -79
  22. package/dist/engine-wasm/wasm/lix_engine.js +0 -833
  23. package/dist/engine-wasm/wasm/lix_engine.wasm +0 -0
  24. package/dist/engine-wasm/wasm/lix_engine.wasm.d.ts +0 -27
  25. package/dist/generated/builtin-schemas.d.ts +0 -427
  26. package/dist/generated/builtin-schemas.js +0 -643
  27. package/dist/sqlite/index.d.ts +0 -12
  28. package/dist/sqlite/index.js +0 -359
  29. package/dist-engine-src/README.md +0 -18
  30. package/dist-engine-src/src/backend/capabilities.rs +0 -67
  31. package/dist-engine-src/src/backend/conformance/baseline.rs +0 -1127
  32. package/dist-engine-src/src/backend/conformance/factory.rs +0 -93
  33. package/dist-engine-src/src/backend/conformance/failure_tests.rs +0 -608
  34. package/dist-engine-src/src/backend/conformance/fixtures.rs +0 -26
  35. package/dist-engine-src/src/backend/conformance/mod.rs +0 -75
  36. package/dist-engine-src/src/backend/conformance/model.rs +0 -28
  37. package/dist-engine-src/src/backend/conformance/model_based.rs +0 -257
  38. package/dist-engine-src/src/backend/conformance/persistence.rs +0 -204
  39. package/dist-engine-src/src/backend/conformance/projection.rs +0 -21
  40. package/dist-engine-src/src/backend/conformance/pushdown.rs +0 -24
  41. package/dist-engine-src/src/backend/conformance/runner.rs +0 -90
  42. package/dist-engine-src/src/backend/conformance/scan.rs +0 -24
  43. package/dist-engine-src/src/backend/conformance/write.rs +0 -16
  44. package/dist-engine-src/src/backend/error.rs +0 -94
  45. package/dist-engine-src/src/backend/in_memory.rs +0 -670
  46. package/dist-engine-src/src/backend/mod.rs +0 -39
  47. package/dist-engine-src/src/backend/predicate.rs +0 -80
  48. package/dist-engine-src/src/backend/traits.rs +0 -260
  49. package/dist-engine-src/src/backend/types.rs +0 -239
  50. package/dist-engine-src/src/binary_cas/chunking.rs +0 -31
  51. package/dist-engine-src/src/binary_cas/codec.rs +0 -346
  52. package/dist-engine-src/src/binary_cas/context.rs +0 -139
  53. package/dist-engine-src/src/binary_cas/kv.rs +0 -1038
  54. package/dist-engine-src/src/binary_cas/mod.rs +0 -11
  55. package/dist-engine-src/src/binary_cas/types.rs +0 -121
  56. package/dist-engine-src/src/branch/context.rs +0 -40
  57. package/dist-engine-src/src/branch/lifecycle.rs +0 -221
  58. package/dist-engine-src/src/branch/mod.rs +0 -13
  59. package/dist-engine-src/src/branch/refs.rs +0 -321
  60. package/dist-engine-src/src/branch/stage_rows.rs +0 -67
  61. package/dist-engine-src/src/branch/types.rs +0 -21
  62. package/dist-engine-src/src/catalog/context.rs +0 -412
  63. package/dist-engine-src/src/catalog/mod.rs +0 -10
  64. package/dist-engine-src/src/catalog/schema.rs +0 -4
  65. package/dist-engine-src/src/catalog/snapshot.rs +0 -1114
  66. package/dist-engine-src/src/cel/context.rs +0 -86
  67. package/dist-engine-src/src/cel/error.rs +0 -19
  68. package/dist-engine-src/src/cel/mod.rs +0 -8
  69. package/dist-engine-src/src/cel/provider.rs +0 -9
  70. package/dist-engine-src/src/cel/runtime.rs +0 -167
  71. package/dist-engine-src/src/cel/value.rs +0 -50
  72. package/dist-engine-src/src/changelog/bench_support.rs +0 -785
  73. package/dist-engine-src/src/changelog/change.rs +0 -1
  74. package/dist-engine-src/src/changelog/codec.rs +0 -497
  75. package/dist-engine-src/src/changelog/commit.rs +0 -1
  76. package/dist-engine-src/src/changelog/context.rs +0 -1614
  77. package/dist-engine-src/src/changelog/mod.rs +0 -29
  78. package/dist-engine-src/src/changelog/store.rs +0 -163
  79. package/dist-engine-src/src/changelog/test_support.rs +0 -54
  80. package/dist-engine-src/src/changelog/types.rs +0 -213
  81. package/dist-engine-src/src/commit_graph/context.rs +0 -944
  82. package/dist-engine-src/src/commit_graph/mod.rs +0 -9
  83. package/dist-engine-src/src/commit_graph/types.rs +0 -89
  84. package/dist-engine-src/src/commit_graph/walker.rs +0 -786
  85. package/dist-engine-src/src/common/error.rs +0 -347
  86. package/dist-engine-src/src/common/fingerprint.rs +0 -3
  87. package/dist-engine-src/src/common/fs_path.rs +0 -1336
  88. package/dist-engine-src/src/common/identity.rs +0 -145
  89. package/dist-engine-src/src/common/json_pointer.rs +0 -67
  90. package/dist-engine-src/src/common/metadata.rs +0 -40
  91. package/dist-engine-src/src/common/mod.rs +0 -23
  92. package/dist-engine-src/src/common/types.rs +0 -105
  93. package/dist-engine-src/src/common/wire.rs +0 -222
  94. package/dist-engine-src/src/domain.rs +0 -320
  95. package/dist-engine-src/src/engine.rs +0 -203
  96. package/dist-engine-src/src/entity_pk.rs +0 -402
  97. package/dist-engine-src/src/functions/context.rs +0 -296
  98. package/dist-engine-src/src/functions/deterministic.rs +0 -113
  99. package/dist-engine-src/src/functions/mod.rs +0 -18
  100. package/dist-engine-src/src/functions/provider.rs +0 -130
  101. package/dist-engine-src/src/functions/state.rs +0 -335
  102. package/dist-engine-src/src/functions/types.rs +0 -37
  103. package/dist-engine-src/src/init.rs +0 -692
  104. package/dist-engine-src/src/json_store/compression.rs +0 -77
  105. package/dist-engine-src/src/json_store/context.rs +0 -172
  106. package/dist-engine-src/src/json_store/encoded.rs +0 -15
  107. package/dist-engine-src/src/json_store/mod.rs +0 -38
  108. package/dist-engine-src/src/json_store/store.rs +0 -494
  109. package/dist-engine-src/src/json_store/types.rs +0 -212
  110. package/dist-engine-src/src/lib.rs +0 -92
  111. package/dist-engine-src/src/live_state/context.rs +0 -1883
  112. package/dist-engine-src/src/live_state/mod.rs +0 -21
  113. package/dist-engine-src/src/live_state/overlay.rs +0 -75
  114. package/dist-engine-src/src/live_state/reader.rs +0 -23
  115. package/dist-engine-src/src/live_state/types.rs +0 -231
  116. package/dist-engine-src/src/live_state/visibility.rs +0 -666
  117. package/dist-engine-src/src/plugin/archive.rs +0 -438
  118. package/dist-engine-src/src/plugin/component.rs +0 -183
  119. package/dist-engine-src/src/plugin/install.rs +0 -619
  120. package/dist-engine-src/src/plugin/manifest.rs +0 -516
  121. package/dist-engine-src/src/plugin/materializer.rs +0 -202
  122. package/dist-engine-src/src/plugin/mod.rs +0 -33
  123. package/dist-engine-src/src/plugin/plugin_manifest.json +0 -119
  124. package/dist-engine-src/src/plugin/storage.rs +0 -74
  125. package/dist-engine-src/src/schema/annotations/defaults.rs +0 -275
  126. package/dist-engine-src/src/schema/annotations/mod.rs +0 -1
  127. package/dist-engine-src/src/schema/builtin/lix_account.json +0 -21
  128. package/dist-engine-src/src/schema/builtin/lix_active_account.json +0 -29
  129. package/dist-engine-src/src/schema/builtin/lix_binary_blob_ref.json +0 -29
  130. package/dist-engine-src/src/schema/builtin/lix_branch_descriptor.json +0 -34
  131. package/dist-engine-src/src/schema/builtin/lix_branch_ref.json +0 -48
  132. package/dist-engine-src/src/schema/builtin/lix_change.json +0 -63
  133. package/dist-engine-src/src/schema/builtin/lix_change_author.json +0 -45
  134. package/dist-engine-src/src/schema/builtin/lix_commit.json +0 -24
  135. package/dist-engine-src/src/schema/builtin/lix_commit_edge.json +0 -53
  136. package/dist-engine-src/src/schema/builtin/lix_directory_descriptor.json +0 -52
  137. package/dist-engine-src/src/schema/builtin/lix_file_descriptor.json +0 -52
  138. package/dist-engine-src/src/schema/builtin/lix_key_value.json +0 -40
  139. package/dist-engine-src/src/schema/builtin/lix_label.json +0 -29
  140. package/dist-engine-src/src/schema/builtin/lix_label_assignment.json +0 -74
  141. package/dist-engine-src/src/schema/builtin/lix_registered_schema.json +0 -25
  142. package/dist-engine-src/src/schema/builtin/mod.rs +0 -220
  143. package/dist-engine-src/src/schema/compatibility.rs +0 -787
  144. package/dist-engine-src/src/schema/definition.json +0 -187
  145. package/dist-engine-src/src/schema/definition.rs +0 -742
  146. package/dist-engine-src/src/schema/key.rs +0 -138
  147. package/dist-engine-src/src/schema/mod.rs +0 -20
  148. package/dist-engine-src/src/schema/seed.rs +0 -14
  149. package/dist-engine-src/src/schema/tests.rs +0 -780
  150. package/dist-engine-src/src/session/context.rs +0 -1059
  151. package/dist-engine-src/src/session/create_branch.rs +0 -94
  152. package/dist-engine-src/src/session/execute.rs +0 -681
  153. package/dist-engine-src/src/session/merge/analysis.rs +0 -108
  154. package/dist-engine-src/src/session/merge/branch.rs +0 -417
  155. package/dist-engine-src/src/session/merge/conflicts.rs +0 -63
  156. package/dist-engine-src/src/session/merge/mod.rs +0 -10
  157. package/dist-engine-src/src/session/merge/stats.rs +0 -61
  158. package/dist-engine-src/src/session/mod.rs +0 -30
  159. package/dist-engine-src/src/session/switch_branch.rs +0 -113
  160. package/dist-engine-src/src/session/transaction.rs +0 -557
  161. package/dist-engine-src/src/sql2/bind/classify.rs +0 -102
  162. package/dist-engine-src/src/sql2/bind/error.rs +0 -5
  163. package/dist-engine-src/src/sql2/bind/expr.rs +0 -29
  164. package/dist-engine-src/src/sql2/bind/mod.rs +0 -12
  165. package/dist-engine-src/src/sql2/bind/public_udf.rs +0 -306
  166. package/dist-engine-src/src/sql2/bind/read.rs +0 -65
  167. package/dist-engine-src/src/sql2/bind/statement.rs +0 -2236
  168. package/dist-engine-src/src/sql2/bind/table.rs +0 -273
  169. package/dist-engine-src/src/sql2/bind/write.rs +0 -86
  170. package/dist-engine-src/src/sql2/branch_scope.rs +0 -436
  171. package/dist-engine-src/src/sql2/catalog/capability.rs +0 -20
  172. package/dist-engine-src/src/sql2/catalog/entity_surface.rs +0 -296
  173. package/dist-engine-src/src/sql2/catalog/mod.rs +0 -15
  174. package/dist-engine-src/src/sql2/catalog/registry.rs +0 -556
  175. package/dist-engine-src/src/sql2/catalog/schema.rs +0 -88
  176. package/dist-engine-src/src/sql2/catalog/surface.rs +0 -41
  177. package/dist-engine-src/src/sql2/change_materialization.rs +0 -122
  178. package/dist-engine-src/src/sql2/context.rs +0 -317
  179. package/dist-engine-src/src/sql2/dml.rs +0 -148
  180. package/dist-engine-src/src/sql2/error.rs +0 -215
  181. package/dist-engine-src/src/sql2/exec/bound_public_write.rs +0 -1593
  182. package/dist-engine-src/src/sql2/exec/datafusion.rs +0 -5266
  183. package/dist-engine-src/src/sql2/exec/fast_write.rs +0 -82
  184. package/dist-engine-src/src/sql2/exec/mod.rs +0 -24
  185. package/dist-engine-src/src/sql2/exec/write.rs +0 -661
  186. package/dist-engine-src/src/sql2/filesystem_planner.rs +0 -1485
  187. package/dist-engine-src/src/sql2/filesystem_predicates.rs +0 -159
  188. package/dist-engine-src/src/sql2/filesystem_visibility.rs +0 -383
  189. package/dist-engine-src/src/sql2/history_projection.rs +0 -56
  190. package/dist-engine-src/src/sql2/history_route.rs +0 -661
  191. package/dist-engine-src/src/sql2/mod.rs +0 -52
  192. package/dist-engine-src/src/sql2/optimize/datafusion.rs +0 -1
  193. package/dist-engine-src/src/sql2/optimize/mod.rs +0 -2
  194. package/dist-engine-src/src/sql2/optimize/simple_write.rs +0 -116
  195. package/dist-engine-src/src/sql2/parse/mod.rs +0 -69
  196. package/dist-engine-src/src/sql2/parse/normalize.rs +0 -1
  197. package/dist-engine-src/src/sql2/plan/branch_scope.rs +0 -24
  198. package/dist-engine-src/src/sql2/plan/mod.rs +0 -5
  199. package/dist-engine-src/src/sql2/plan/predicate.rs +0 -22
  200. package/dist-engine-src/src/sql2/plan/write.rs +0 -147
  201. package/dist-engine-src/src/sql2/predicate_typecheck.rs +0 -504
  202. package/dist-engine-src/src/sql2/providers/branch.rs +0 -1206
  203. package/dist-engine-src/src/sql2/providers/change.rs +0 -445
  204. package/dist-engine-src/src/sql2/providers/directory.rs +0 -2422
  205. package/dist-engine-src/src/sql2/providers/directory_history.rs +0 -645
  206. package/dist-engine-src/src/sql2/providers/entity.rs +0 -1484
  207. package/dist-engine-src/src/sql2/providers/entity_history.rs +0 -452
  208. package/dist-engine-src/src/sql2/providers/file.rs +0 -3686
  209. package/dist-engine-src/src/sql2/providers/file_history.rs +0 -924
  210. package/dist-engine-src/src/sql2/providers/history.rs +0 -426
  211. package/dist-engine-src/src/sql2/providers/lix_state.rs +0 -2542
  212. package/dist-engine-src/src/sql2/providers/mod.rs +0 -508
  213. package/dist-engine-src/src/sql2/read_only.rs +0 -63
  214. package/dist-engine-src/src/sql2/record_batch.rs +0 -17
  215. package/dist-engine-src/src/sql2/result_metadata.rs +0 -29
  216. package/dist-engine-src/src/sql2/runtime.rs +0 -60
  217. package/dist-engine-src/src/sql2/session.rs +0 -83
  218. package/dist-engine-src/src/sql2/storage/constraints.rs +0 -1
  219. package/dist-engine-src/src/sql2/storage/mod.rs +0 -1
  220. package/dist-engine-src/src/sql2/test_support/differential.rs +0 -712
  221. package/dist-engine-src/src/sql2/test_support/generators.rs +0 -354
  222. package/dist-engine-src/src/sql2/test_support/mod.rs +0 -2
  223. package/dist-engine-src/src/sql2/udfs/common.rs +0 -295
  224. package/dist-engine-src/src/sql2/udfs/lix_active_branch_commit_id.rs +0 -53
  225. package/dist-engine-src/src/sql2/udfs/lix_empty_blob.rs +0 -47
  226. package/dist-engine-src/src/sql2/udfs/lix_json.rs +0 -100
  227. package/dist-engine-src/src/sql2/udfs/lix_json_get.rs +0 -99
  228. package/dist-engine-src/src/sql2/udfs/lix_json_get_text.rs +0 -99
  229. package/dist-engine-src/src/sql2/udfs/lix_text_decode.rs +0 -82
  230. package/dist-engine-src/src/sql2/udfs/lix_text_encode.rs +0 -85
  231. package/dist-engine-src/src/sql2/udfs/lix_timestamp.rs +0 -76
  232. package/dist-engine-src/src/sql2/udfs/lix_uuid_v7.rs +0 -76
  233. package/dist-engine-src/src/sql2/udfs/mod.rs +0 -86
  234. package/dist-engine-src/src/sql2/write_normalization.rs +0 -368
  235. package/dist-engine-src/src/storage/conformance.rs +0 -399
  236. package/dist-engine-src/src/storage/context.rs +0 -620
  237. package/dist-engine-src/src/storage/mod.rs +0 -52
  238. package/dist-engine-src/src/storage/point.rs +0 -440
  239. package/dist-engine-src/src/storage/read_scope.rs +0 -67
  240. package/dist-engine-src/src/storage/reader.rs +0 -867
  241. package/dist-engine-src/src/storage/scan.rs +0 -784
  242. package/dist-engine-src/src/storage/spaces.rs +0 -236
  243. package/dist-engine-src/src/storage/stats.rs +0 -80
  244. package/dist-engine-src/src/storage/write_set.rs +0 -962
  245. package/dist-engine-src/src/storage_bench.rs +0 -171
  246. package/dist-engine-src/src/test_support.rs +0 -450
  247. package/dist-engine-src/src/tracked_state/bench_support.rs +0 -394
  248. package/dist-engine-src/src/tracked_state/codec.rs +0 -1183
  249. package/dist-engine-src/src/tracked_state/commit_root_rebuild.rs +0 -358
  250. package/dist-engine-src/src/tracked_state/context.rs +0 -2801
  251. package/dist-engine-src/src/tracked_state/diff.rs +0 -2140
  252. package/dist-engine-src/src/tracked_state/merge.rs +0 -478
  253. package/dist-engine-src/src/tracked_state/mod.rs +0 -35
  254. package/dist-engine-src/src/tracked_state/row_materialization.rs +0 -275
  255. package/dist-engine-src/src/tracked_state/storage.rs +0 -427
  256. package/dist-engine-src/src/tracked_state/tree.rs +0 -3063
  257. package/dist-engine-src/src/tracked_state/types.rs +0 -238
  258. package/dist-engine-src/src/transaction/bench_support.rs +0 -407
  259. package/dist-engine-src/src/transaction/commit.rs +0 -1592
  260. package/dist-engine-src/src/transaction/context.rs +0 -1653
  261. package/dist-engine-src/src/transaction/mod.rs +0 -24
  262. package/dist-engine-src/src/transaction/normalization.rs +0 -877
  263. package/dist-engine-src/src/transaction/prep.rs +0 -37
  264. package/dist-engine-src/src/transaction/schema_resolver.rs +0 -163
  265. package/dist-engine-src/src/transaction/staging.rs +0 -1525
  266. package/dist-engine-src/src/transaction/types.rs +0 -403
  267. package/dist-engine-src/src/transaction/validation.rs +0 -5766
  268. package/dist-engine-src/src/untracked_state/codec.rs +0 -615
  269. package/dist-engine-src/src/untracked_state/context.rs +0 -98
  270. package/dist-engine-src/src/untracked_state/materialization.rs +0 -63
  271. package/dist-engine-src/src/untracked_state/mod.rs +0 -15
  272. package/dist-engine-src/src/untracked_state/storage.rs +0 -898
  273. package/dist-engine-src/src/untracked_state/types.rs +0 -146
  274. package/dist-engine-src/src/wasm/mod.rs +0 -60
@@ -1,347 +0,0 @@
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/branch 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 branch 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 branch id that has no matching branch ref.
130
- pub const CODE_BRANCH_NOT_FOUND: &'static str = "LIX_BRANCH_NOT_FOUND";
131
-
132
- /// A caller referenced a commit id that has no matching commit record.
133
- pub const CODE_COMMIT_NOT_FOUND: &'static str = "LIX_COMMIT_NOT_FOUND";
134
-
135
- /// A staged row's storage scope flags disagree, such as a global row not
136
- /// using the reserved global branch id.
137
- pub const CODE_INVALID_STORAGE_SCOPE: &'static str = "LIX_ERROR_INVALID_STORAGE_SCOPE";
138
-
139
- /// Merge graph analysis found multiple equally valid merge bases.
140
- pub const CODE_AMBIGUOUS_MERGE_BASE: &'static str = "LIX_AMBIGUOUS_MERGE_BASE";
141
-
142
- /// A merge request is well-formed but nonsensical for the commit graph,
143
- /// such as merging a branch into itself.
144
- pub const CODE_INVALID_MERGE: &'static str = "LIX_INVALID_MERGE";
145
-
146
- pub fn new(code: impl Into<String>, message: impl Into<String>) -> Self {
147
- Self {
148
- code: code.into(),
149
- message: message.into(),
150
- hint: None,
151
- details: None,
152
- }
153
- }
154
-
155
- pub fn unknown(message: impl Into<String>) -> Self {
156
- Self::new("LIX_ERROR_UNKNOWN", message)
157
- }
158
-
159
- pub fn branch_not_found(
160
- branch_id: impl Into<String>,
161
- operation: impl Into<String>,
162
- role: impl Into<String>,
163
- ) -> Self {
164
- let branch_id = branch_id.into();
165
- let operation = operation.into();
166
- let role = role.into();
167
- Self::new(
168
- Self::CODE_BRANCH_NOT_FOUND,
169
- format!("branch '{branch_id}' was not found"),
170
- )
171
- .with_details(json!({
172
- "branch_id": branch_id,
173
- "operation": operation,
174
- "role": role,
175
- }))
176
- }
177
-
178
- pub fn commit_not_found(
179
- commit_id: impl Into<String>,
180
- operation: impl Into<String>,
181
- role: impl Into<String>,
182
- ) -> Self {
183
- let commit_id = commit_id.into();
184
- let operation = operation.into();
185
- let role = role.into();
186
- Self::new(
187
- Self::CODE_COMMIT_NOT_FOUND,
188
- format!("commit '{commit_id}' was not found"),
189
- )
190
- .with_details(json!({
191
- "commit_id": commit_id,
192
- "operation": operation,
193
- "role": role,
194
- }))
195
- }
196
-
197
- pub fn ambiguous_merge_base(
198
- left_commit_id: impl Into<String>,
199
- right_commit_id: impl Into<String>,
200
- candidates: Vec<String>,
201
- ) -> Self {
202
- let left_commit_id = left_commit_id.into();
203
- let right_commit_id = right_commit_id.into();
204
- Self::new(
205
- Self::CODE_AMBIGUOUS_MERGE_BASE,
206
- format!("ambiguous merge base between '{left_commit_id}' and '{right_commit_id}'"),
207
- )
208
- .with_details(json!({
209
- "left_commit_id": left_commit_id,
210
- "right_commit_id": right_commit_id,
211
- "candidates": candidates,
212
- }))
213
- }
214
-
215
- pub fn invalid_self_merge(branch_id: impl Into<String>) -> Self {
216
- let branch_id = branch_id.into();
217
- Self::new(
218
- Self::CODE_INVALID_MERGE,
219
- format!("cannot merge branch '{branch_id}' into itself"),
220
- )
221
- .with_details(json!({
222
- "operation": "merge_branch",
223
- "target_branch_id": branch_id,
224
- "source_branch_id": branch_id,
225
- }))
226
- }
227
-
228
- /// Attach a hint to this error. Consumers render hints alongside the
229
- /// primary message (e.g. a CLI prints them as `hint: <text>`).
230
- ///
231
- /// ```
232
- /// use lix_engine::LixError;
233
- ///
234
- /// let err = LixError::new("CODE", "boom").with_hint("try this");
235
- /// assert_eq!(err.hint(), Some("try this"));
236
- /// ```
237
- pub fn with_hint(mut self, hint: impl Into<String>) -> Self {
238
- self.hint = Some(hint.into());
239
- self
240
- }
241
-
242
- /// Attach machine-readable details to this error.
243
- pub fn with_details(mut self, details: JsonValue) -> Self {
244
- self.details = Some(details);
245
- self
246
- }
247
-
248
- /// Return the attached hint, if any.
249
- ///
250
- /// Returns `None` when no hint was attached at the error's producer
251
- /// site. This is the accessor SDK consumers should prefer over
252
- /// reading the `hint` field directly — it returns `Option<&str>`,
253
- /// avoiding the need for `.as_deref()` at the call site.
254
- ///
255
- /// ```
256
- /// use lix_engine::LixError;
257
- ///
258
- /// let without_hint = LixError::new("CODE", "boom");
259
- /// assert_eq!(without_hint.hint(), None);
260
- ///
261
- /// let with_hint = LixError::new("CODE", "boom").with_hint("fix it");
262
- /// assert_eq!(with_hint.hint(), Some("fix it"));
263
- /// ```
264
- pub fn hint(&self) -> Option<&str> {
265
- self.hint.as_deref()
266
- }
267
-
268
- pub fn message_with_hint(&self) -> String {
269
- match self.hint() {
270
- Some(hint) => format!("{}\nhint: {hint}", self.message),
271
- None => self.message.clone(),
272
- }
273
- }
274
-
275
- pub fn format(&self) -> String {
276
- let mut s = format!("code: {}\nmessage: {}", self.code, self.message);
277
- if let Some(hint) = &self.hint {
278
- s.push_str(&format!("\nhint: {hint}"));
279
- }
280
- s
281
- }
282
- }
283
-
284
- impl From<crate::storage::StorageBackendError> for LixError {
285
- fn from(error: crate::storage::StorageBackendError) -> Self {
286
- Self::new(Self::CODE_STORAGE_ERROR, error.to_string())
287
- }
288
- }
289
-
290
- impl From<crate::storage::StorageWriteSetError> for LixError {
291
- fn from(error: crate::storage::StorageWriteSetError) -> Self {
292
- Self::new(Self::CODE_STORAGE_ERROR, error.to_string())
293
- }
294
- }
295
-
296
- impl std::fmt::Display for LixError {
297
- fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
298
- write!(f, "{}", self.format())
299
- }
300
- }
301
-
302
- impl std::error::Error for LixError {}
303
-
304
- #[cfg(test)]
305
- mod tests {
306
- use super::*;
307
-
308
- #[test]
309
- fn format_without_hint_omits_hint_line() {
310
- let err = LixError::new("LIX_ERROR_FOO", "something went wrong");
311
- assert_eq!(
312
- err.format(),
313
- "code: LIX_ERROR_FOO\nmessage: something went wrong"
314
- );
315
- assert!(err.hint.is_none());
316
- }
317
-
318
- #[test]
319
- fn format_with_hint_appends_hint_line() {
320
- let err = LixError::new("LIX_ERROR_FOO", "something went wrong").with_hint("try the fix");
321
- assert_eq!(
322
- err.format(),
323
- "code: LIX_ERROR_FOO\nmessage: something went wrong\nhint: try the fix"
324
- );
325
- }
326
-
327
- #[test]
328
- fn with_hint_is_chainable_and_replaces_prior_hint() {
329
- let err = LixError::new("LIX_ERROR_FOO", "desc")
330
- .with_hint("first")
331
- .with_hint("second");
332
- assert_eq!(err.hint.as_deref(), Some("second"));
333
- }
334
-
335
- #[test]
336
- fn new_defaults_hint_to_none() {
337
- let err = LixError::new("CODE", "desc");
338
- assert_eq!(err.hint, None);
339
- }
340
-
341
- #[test]
342
- fn unknown_defaults_hint_to_none() {
343
- let err = LixError::unknown("desc");
344
- assert_eq!(err.code, "LIX_ERROR_UNKNOWN");
345
- assert_eq!(err.hint, None);
346
- }
347
- }
@@ -1,3 +0,0 @@
1
- pub(crate) fn stable_content_fingerprint_hex(data: &[u8]) -> String {
2
- blake3::hash(data).to_hex().to_string()
3
- }