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

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 (234) hide show
  1. package/README.md +1 -1
  2. package/SKILL.md +65 -64
  3. package/dist/engine-wasm/index.js +4 -4
  4. package/dist/engine-wasm/wasm/lix_engine.d.ts +5 -5
  5. package/dist/engine-wasm/wasm/lix_engine.js +130 -118
  6. package/dist/engine-wasm/wasm/lix_engine.wasm +0 -0
  7. package/dist/engine-wasm/wasm/lix_engine.wasm.d.ts +9 -8
  8. package/dist/generated/builtin-schemas.d.ts +69 -69
  9. package/dist/generated/builtin-schemas.js +94 -94
  10. package/dist/open-lix.d.ts +33 -26
  11. package/dist/open-lix.js +10 -10
  12. package/dist/sqlite/index.js +86 -30
  13. package/dist-engine-src/README.md +3 -3
  14. package/dist-engine-src/src/backend/capabilities.rs +67 -0
  15. package/dist-engine-src/src/backend/conformance/baseline.rs +1127 -0
  16. package/dist-engine-src/src/backend/conformance/factory.rs +93 -0
  17. package/dist-engine-src/src/backend/conformance/failure_tests.rs +608 -0
  18. package/dist-engine-src/src/backend/conformance/fixtures.rs +26 -0
  19. package/dist-engine-src/src/backend/conformance/mod.rs +75 -0
  20. package/dist-engine-src/src/backend/conformance/model.rs +28 -0
  21. package/dist-engine-src/src/backend/conformance/model_based.rs +257 -0
  22. package/dist-engine-src/src/backend/conformance/persistence.rs +204 -0
  23. package/dist-engine-src/src/backend/conformance/projection.rs +21 -0
  24. package/dist-engine-src/src/backend/conformance/pushdown.rs +24 -0
  25. package/dist-engine-src/src/backend/conformance/runner.rs +90 -0
  26. package/dist-engine-src/src/backend/conformance/scan.rs +24 -0
  27. package/dist-engine-src/src/backend/conformance/write.rs +16 -0
  28. package/dist-engine-src/src/backend/error.rs +94 -0
  29. package/dist-engine-src/src/backend/in_memory.rs +670 -0
  30. package/dist-engine-src/src/backend/mod.rs +36 -9
  31. package/dist-engine-src/src/backend/predicate.rs +80 -0
  32. package/dist-engine-src/src/backend/traits.rs +260 -0
  33. package/dist-engine-src/src/backend/types.rs +224 -81
  34. package/dist-engine-src/src/binary_cas/context.rs +8 -8
  35. package/dist-engine-src/src/binary_cas/kv.rs +234 -259
  36. package/dist-engine-src/src/{version → branch}/context.rs +12 -12
  37. package/dist-engine-src/src/branch/lifecycle.rs +221 -0
  38. package/dist-engine-src/src/branch/mod.rs +13 -0
  39. package/dist-engine-src/src/branch/refs.rs +321 -0
  40. package/dist-engine-src/src/branch/stage_rows.rs +67 -0
  41. package/dist-engine-src/src/branch/types.rs +21 -0
  42. package/dist-engine-src/src/catalog/context.rs +18 -18
  43. package/dist-engine-src/src/catalog/snapshot.rs +8 -8
  44. package/dist-engine-src/src/changelog/bench_support.rs +785 -0
  45. package/dist-engine-src/src/changelog/change.rs +1 -0
  46. package/dist-engine-src/src/changelog/codec.rs +497 -0
  47. package/dist-engine-src/src/changelog/commit.rs +1 -0
  48. package/dist-engine-src/src/changelog/context.rs +1614 -0
  49. package/dist-engine-src/src/changelog/mod.rs +29 -0
  50. package/dist-engine-src/src/changelog/store.rs +163 -0
  51. package/dist-engine-src/src/changelog/test_support.rs +54 -0
  52. package/dist-engine-src/src/changelog/types.rs +213 -0
  53. package/dist-engine-src/src/commit_graph/context.rs +317 -274
  54. package/dist-engine-src/src/commit_graph/mod.rs +2 -4
  55. package/dist-engine-src/src/commit_graph/types.rs +22 -42
  56. package/dist-engine-src/src/commit_graph/walker.rs +133 -103
  57. package/dist-engine-src/src/common/error.rs +52 -18
  58. package/dist-engine-src/src/common/identity.rs +2 -2
  59. package/dist-engine-src/src/common/mod.rs +1 -1
  60. package/dist-engine-src/src/domain.rs +42 -46
  61. package/dist-engine-src/src/engine.rs +74 -96
  62. package/dist-engine-src/src/{entity_identity.rs → entity_pk.rs} +89 -92
  63. package/dist-engine-src/src/functions/context.rs +56 -52
  64. package/dist-engine-src/src/functions/state.rs +51 -52
  65. package/dist-engine-src/src/init.rs +288 -154
  66. package/dist-engine-src/src/json_store/context.rs +15 -266
  67. package/dist-engine-src/src/json_store/mod.rs +26 -0
  68. package/dist-engine-src/src/json_store/store.rs +103 -718
  69. package/dist-engine-src/src/json_store/types.rs +4 -9
  70. package/dist-engine-src/src/lib.rs +49 -19
  71. package/dist-engine-src/src/live_state/context.rs +654 -790
  72. package/dist-engine-src/src/live_state/mod.rs +9 -3
  73. package/dist-engine-src/src/live_state/overlay.rs +4 -4
  74. package/dist-engine-src/src/live_state/types.rs +30 -21
  75. package/dist-engine-src/src/live_state/visibility.rs +514 -71
  76. package/dist-engine-src/src/plugin/install.rs +48 -48
  77. package/dist-engine-src/src/plugin/manifest.rs +7 -7
  78. package/dist-engine-src/src/plugin/materializer.rs +0 -275
  79. package/dist-engine-src/src/plugin/plugin_manifest.json +4 -3
  80. package/dist-engine-src/src/schema/builtin/lix_binary_blob_ref.json +2 -2
  81. package/dist-engine-src/src/schema/builtin/lix_branch_descriptor.json +34 -0
  82. package/dist-engine-src/src/schema/builtin/lix_branch_ref.json +48 -0
  83. package/dist-engine-src/src/schema/builtin/lix_change.json +3 -3
  84. package/dist-engine-src/src/schema/builtin/lix_commit.json +1 -1
  85. package/dist-engine-src/src/schema/builtin/lix_label_assignment.json +6 -6
  86. package/dist-engine-src/src/schema/builtin/mod.rs +18 -20
  87. package/dist-engine-src/src/schema/compatibility.rs +11 -11
  88. package/dist-engine-src/src/schema/definition.json +2 -2
  89. package/dist-engine-src/src/schema/definition.rs +5 -5
  90. package/dist-engine-src/src/schema/key.rs +3 -3
  91. package/dist-engine-src/src/schema/mod.rs +1 -1
  92. package/dist-engine-src/src/schema/tests.rs +18 -18
  93. package/dist-engine-src/src/session/context.rs +803 -148
  94. package/dist-engine-src/src/session/create_branch.rs +94 -0
  95. package/dist-engine-src/src/session/execute.rs +223 -83
  96. package/dist-engine-src/src/session/merge/analysis.rs +9 -3
  97. package/dist-engine-src/src/session/merge/{version.rs → branch.rs} +119 -129
  98. package/dist-engine-src/src/session/merge/conflicts.rs +2 -2
  99. package/dist-engine-src/src/session/merge/mod.rs +5 -6
  100. package/dist-engine-src/src/session/merge/stats.rs +7 -11
  101. package/dist-engine-src/src/session/mod.rs +15 -12
  102. package/dist-engine-src/src/session/switch_branch.rs +113 -0
  103. package/dist-engine-src/src/session/transaction.rs +495 -14
  104. package/dist-engine-src/src/sql2/{classify.rs → bind/classify.rs} +3 -75
  105. package/dist-engine-src/src/sql2/bind/error.rs +5 -0
  106. package/dist-engine-src/src/sql2/bind/expr.rs +29 -0
  107. package/dist-engine-src/src/sql2/bind/mod.rs +12 -0
  108. package/dist-engine-src/src/sql2/{udfs/public_call.rs → bind/public_udf.rs} +71 -3
  109. package/dist-engine-src/src/sql2/bind/read.rs +65 -0
  110. package/dist-engine-src/src/sql2/bind/statement.rs +2236 -0
  111. package/dist-engine-src/src/sql2/bind/table.rs +273 -0
  112. package/dist-engine-src/src/sql2/bind/write.rs +86 -0
  113. package/dist-engine-src/src/sql2/branch_scope.rs +436 -0
  114. package/dist-engine-src/src/sql2/catalog/capability.rs +20 -0
  115. package/dist-engine-src/src/sql2/catalog/entity_surface.rs +296 -0
  116. package/dist-engine-src/src/sql2/catalog/mod.rs +15 -0
  117. package/dist-engine-src/src/sql2/catalog/registry.rs +556 -0
  118. package/dist-engine-src/src/sql2/catalog/schema.rs +88 -0
  119. package/dist-engine-src/src/sql2/catalog/surface.rs +41 -0
  120. package/dist-engine-src/src/sql2/change_materialization.rs +122 -0
  121. package/dist-engine-src/src/sql2/context.rs +36 -30
  122. package/dist-engine-src/src/sql2/error.rs +1 -1
  123. package/dist-engine-src/src/sql2/exec/bound_public_write.rs +1593 -0
  124. package/dist-engine-src/src/sql2/exec/datafusion.rs +5266 -0
  125. package/dist-engine-src/src/sql2/exec/fast_write.rs +82 -0
  126. package/dist-engine-src/src/sql2/exec/mod.rs +24 -0
  127. package/dist-engine-src/src/sql2/exec/write.rs +661 -0
  128. package/dist-engine-src/src/sql2/filesystem_planner.rs +72 -77
  129. package/dist-engine-src/src/sql2/filesystem_visibility.rs +21 -21
  130. package/dist-engine-src/src/sql2/history_projection.rs +8 -8
  131. package/dist-engine-src/src/sql2/history_route.rs +35 -31
  132. package/dist-engine-src/src/sql2/mod.rs +28 -23
  133. package/dist-engine-src/src/sql2/optimize/datafusion.rs +1 -0
  134. package/dist-engine-src/src/sql2/optimize/mod.rs +2 -0
  135. package/dist-engine-src/src/sql2/optimize/simple_write.rs +116 -0
  136. package/dist-engine-src/src/sql2/parse/mod.rs +69 -0
  137. package/dist-engine-src/src/sql2/parse/normalize.rs +1 -0
  138. package/dist-engine-src/src/sql2/plan/branch_scope.rs +24 -0
  139. package/dist-engine-src/src/sql2/plan/mod.rs +5 -0
  140. package/dist-engine-src/src/sql2/plan/predicate.rs +22 -0
  141. package/dist-engine-src/src/sql2/plan/write.rs +147 -0
  142. package/dist-engine-src/src/sql2/predicate_typecheck.rs +258 -0
  143. package/dist-engine-src/src/sql2/{version_provider.rs → providers/branch.rs} +218 -214
  144. package/dist-engine-src/src/sql2/{change_provider.rs → providers/change.rs} +156 -42
  145. package/dist-engine-src/src/sql2/{directory_provider.rs → providers/directory.rs} +291 -322
  146. package/dist-engine-src/src/sql2/{directory_history_provider.rs → providers/directory_history.rs} +56 -42
  147. package/dist-engine-src/src/sql2/providers/entity.rs +1484 -0
  148. package/dist-engine-src/src/sql2/{entity_history_provider.rs → providers/entity_history.rs} +43 -31
  149. package/dist-engine-src/src/sql2/{file_provider.rs → providers/file.rs} +323 -316
  150. package/dist-engine-src/src/sql2/{file_history_provider.rs → providers/file_history.rs} +60 -46
  151. package/dist-engine-src/src/sql2/{history_provider.rs → providers/history.rs} +46 -32
  152. package/dist-engine-src/src/sql2/{lix_state_provider.rs → providers/lix_state.rs} +359 -329
  153. package/dist-engine-src/src/sql2/providers/mod.rs +508 -0
  154. package/dist-engine-src/src/sql2/read_only.rs +2 -2
  155. package/dist-engine-src/src/sql2/session.rs +47 -96
  156. package/dist-engine-src/src/sql2/storage/constraints.rs +1 -0
  157. package/dist-engine-src/src/sql2/storage/mod.rs +1 -0
  158. package/dist-engine-src/src/sql2/test_support/differential.rs +712 -0
  159. package/dist-engine-src/src/sql2/test_support/generators.rs +354 -0
  160. package/dist-engine-src/src/sql2/test_support/mod.rs +2 -0
  161. package/dist-engine-src/src/sql2/udfs/{lix_active_version_commit_id.rs → lix_active_branch_commit_id.rs} +7 -7
  162. package/dist-engine-src/src/sql2/udfs/mod.rs +3 -6
  163. package/dist-engine-src/src/sql2/write_normalization.rs +45 -22
  164. package/dist-engine-src/src/storage/conformance.rs +399 -0
  165. package/dist-engine-src/src/storage/context.rs +552 -288
  166. package/dist-engine-src/src/storage/mod.rs +48 -10
  167. package/dist-engine-src/src/storage/point.rs +440 -0
  168. package/dist-engine-src/src/storage/read_scope.rs +43 -64
  169. package/dist-engine-src/src/storage/reader.rs +867 -0
  170. package/dist-engine-src/src/storage/scan.rs +784 -0
  171. package/dist-engine-src/src/storage/spaces.rs +236 -0
  172. package/dist-engine-src/src/storage/stats.rs +80 -0
  173. package/dist-engine-src/src/storage/write_set.rs +962 -0
  174. package/dist-engine-src/src/storage_bench.rs +136 -4828
  175. package/dist-engine-src/src/test_support.rs +360 -138
  176. package/dist-engine-src/src/tracked_state/bench_support.rs +394 -0
  177. package/dist-engine-src/src/tracked_state/codec.rs +155 -1057
  178. package/dist-engine-src/src/tracked_state/commit_root_rebuild.rs +358 -0
  179. package/dist-engine-src/src/tracked_state/context.rs +1927 -993
  180. package/dist-engine-src/src/tracked_state/diff.rs +1715 -261
  181. package/dist-engine-src/src/tracked_state/merge.rs +74 -88
  182. package/dist-engine-src/src/tracked_state/mod.rs +19 -16
  183. package/dist-engine-src/src/tracked_state/{materialization.rs → row_materialization.rs} +50 -178
  184. package/dist-engine-src/src/tracked_state/storage.rs +243 -191
  185. package/dist-engine-src/src/tracked_state/tree.rs +247 -371
  186. package/dist-engine-src/src/tracked_state/types.rs +49 -42
  187. package/dist-engine-src/src/transaction/bench_support.rs +407 -0
  188. package/dist-engine-src/src/transaction/commit.rs +821 -713
  189. package/dist-engine-src/src/transaction/context.rs +705 -600
  190. package/dist-engine-src/src/transaction/mod.rs +13 -2
  191. package/dist-engine-src/src/transaction/normalization.rs +63 -76
  192. package/dist-engine-src/src/transaction/prep.rs +13 -13
  193. package/dist-engine-src/src/transaction/schema_resolver.rs +19 -5
  194. package/dist-engine-src/src/transaction/staging.rs +228 -434
  195. package/dist-engine-src/src/transaction/types.rs +41 -98
  196. package/dist-engine-src/src/transaction/validation.rs +382 -446
  197. package/dist-engine-src/src/untracked_state/codec.rs +337 -29
  198. package/dist-engine-src/src/untracked_state/context.rs +7 -7
  199. package/dist-engine-src/src/untracked_state/materialization.rs +2 -2
  200. package/dist-engine-src/src/untracked_state/mod.rs +1 -1
  201. package/dist-engine-src/src/untracked_state/storage.rs +659 -157
  202. package/dist-engine-src/src/untracked_state/types.rs +21 -21
  203. package/package.json +71 -68
  204. package/dist-engine-src/src/backend/kv.rs +0 -358
  205. package/dist-engine-src/src/backend/testing.rs +0 -658
  206. package/dist-engine-src/src/commit_store/codec.rs +0 -887
  207. package/dist-engine-src/src/commit_store/context.rs +0 -944
  208. package/dist-engine-src/src/commit_store/materialization.rs +0 -84
  209. package/dist-engine-src/src/commit_store/mod.rs +0 -16
  210. package/dist-engine-src/src/commit_store/storage.rs +0 -600
  211. package/dist-engine-src/src/commit_store/types.rs +0 -215
  212. package/dist-engine-src/src/schema/builtin/lix_version_descriptor.json +0 -34
  213. package/dist-engine-src/src/schema/builtin/lix_version_ref.json +0 -48
  214. package/dist-engine-src/src/session/create_version.rs +0 -88
  215. package/dist-engine-src/src/session/merge/apply.rs +0 -23
  216. package/dist-engine-src/src/session/optimization9_sql2_bench.rs +0 -100
  217. package/dist-engine-src/src/session/switch_version.rs +0 -110
  218. package/dist-engine-src/src/sql2/entity_provider.rs +0 -3211
  219. package/dist-engine-src/src/sql2/execute.rs +0 -3533
  220. package/dist-engine-src/src/sql2/public_bind/assignment.rs +0 -46
  221. package/dist-engine-src/src/sql2/public_bind/capability.rs +0 -41
  222. package/dist-engine-src/src/sql2/public_bind/dml.rs +0 -172
  223. package/dist-engine-src/src/sql2/public_bind/mod.rs +0 -26
  224. package/dist-engine-src/src/sql2/public_bind/table.rs +0 -168
  225. package/dist-engine-src/src/sql2/version_scope.rs +0 -394
  226. package/dist-engine-src/src/storage/types.rs +0 -501
  227. package/dist-engine-src/src/tracked_state/by_file_index.rs +0 -98
  228. package/dist-engine-src/src/tracked_state/materializer.rs +0 -488
  229. package/dist-engine-src/src/transaction/live_state_overlay.rs +0 -35
  230. package/dist-engine-src/src/version/lifecycle.rs +0 -221
  231. package/dist-engine-src/src/version/mod.rs +0 -13
  232. package/dist-engine-src/src/version/refs.rs +0 -330
  233. package/dist-engine-src/src/version/stage_rows.rs +0 -67
  234. package/dist-engine-src/src/version/types.rs +0 -21
package/README.md CHANGED
@@ -6,4 +6,4 @@ WASM-backed JavaScript SDK for Lix.
6
6
 
7
7
  If you are an AI coding agent using this package, read [`SKILL.md`](./SKILL.md) before building examples, demos, tests, or applications with `@lix-js/sdk`.
8
8
 
9
- The skill documents the current preview API, recommended SQLite backend setup, schema registration flow, entity-table writes, version workflows, merge behavior, and known sharp edges.
9
+ The skill documents the current preview API, recommended SQLite backend setup, schema registration flow, entity-table writes, branch workflows, merge behavior, and known sharp edges.
package/SKILL.md CHANGED
@@ -1,32 +1,32 @@
1
1
  ---
2
2
  name: lix-js-sdk
3
- description: Use this skill when building examples, demos, tests, or applications with @lix-js/sdk: opening a Lix, registering schemas, writing entities through generated SQL tables, creating named versions, merging, and querying change history.
3
+ description: Use this skill when building examples, demos, tests, or applications with @lix-js/sdk: opening a Lix, registering schemas, writing entities through generated SQL tables, creating named branches, merging, and querying change history.
4
4
  ---
5
5
 
6
6
  # Lix JS SDK Skill
7
7
 
8
8
  ## What Is Lix
9
9
 
10
- Lix is an embeddable version control system for structured application state. It gives apps named versions, merge, and an immutable SQL-queryable change journal without asking the app to build those systems from scratch.
10
+ Lix is an embeddable branch control system for structured application state. It gives apps named branches, merge, and an immutable SQL-queryable change journal without asking the app to build those systems from scratch.
11
11
 
12
12
  Current `@lix-js/sdk` capabilities:
13
13
 
14
14
  - Register JSON schemas as tracked entity tables.
15
15
  - Read and write entities through generated SQL tables.
16
16
  - Group related writes in explicit transactions so they commit once.
17
- - Create named versions of state and write/read across versions.
18
- - Merge one version into the active version.
17
+ - Create named branches of state and write/read across branches.
18
+ - Merge one branch into the active branch.
19
19
  - Query `lix_change` for history, audit, activity feeds, and undo-style features.
20
- - Store files as bytes with `lix_file` and version them like other entities.
20
+ - Store files as bytes with `lix_file` and branch them like other entities.
21
21
 
22
22
  Product direction:
23
23
 
24
- - Lix is designed to version files of any kind by parsing them into typed entities on write.
25
- - Parser plugins that turn file contents into app entities are not shipped through the JS SDK yet. Do not promise this behavior in demos. Today, `lix_file` versions bytes, while app entities are modeled directly through registered schemas.
24
+ - Lix is designed to track files of any kind by parsing them into typed entities on write.
25
+ - Parser plugins that turn file contents into app entities are not shipped through the JS SDK yet. Do not promise this behavior in demos. Today, `lix_file` tracks bytes, while app entities are modeled directly through registered schemas.
26
26
 
27
- Every row in every registered schema is a tracked entity. Merge granularity is currently per-entity, not per-field: two versions editing different rows merge cleanly; two versions editing the same row conflict, even if the fields are disjoint. Model collaborative domains as many small entities, such as sections, blocks, paragraphs, message keys, or line items.
27
+ Every row in every registered schema is a tracked entity. Merge granularity is currently per-entity, not per-field: two branches editing different rows merge cleanly; two branches editing the same row conflict, even if the fields are disjoint. Model collaborative domains as many small entities, such as sections, blocks, paragraphs, message keys, or line items.
28
28
 
29
- Use Lix vocabulary in user-facing copy. What Git calls a branch is called a **version** in Lix because that language makes sense to non-developers.
29
+ Use Lix vocabulary in user-facing copy. Lix uses **branch** for named lines of work.
30
30
 
31
31
  ## When To Use This Skill
32
32
 
@@ -37,7 +37,7 @@ Use this skill when you need to write or debug consumer code using `@lix-js/sdk`
37
37
  - Writing and reading generated SQL entity tables.
38
38
  - Grouping imports, migrations, and batch writes into one transaction.
39
39
  - Reading `execute()` results.
40
- - Creating, switching, previewing, and merging versions.
40
+ - Creating, switching, previewing, and merging branches.
41
41
  - Querying history through `lix_change`.
42
42
  - Building app demos, examples, smoke tests, or product flows around the SDK.
43
43
 
@@ -50,9 +50,9 @@ Do not use this skill for raw SQLite access, private engine/wasm internals, SDK
50
50
  3. Register a schema with `x-lix-key`, `x-lix-primary-key`, and `additionalProperties: false`.
51
51
  4. Write rows through the generated table named by `x-lix-key`.
52
52
  5. Use `beginTransaction()` for imports, migrations, and multi-row writes that should be one commit.
53
- 6. Use `<schema>_by_version` plus `lixcol_version_id` for side-by-side version reads/writes.
53
+ 6. Use `<schema>_by_branch` plus `lixcol_branch_id` for side-by-side branch reads/writes.
54
54
  7. Query `lix_change` for audit/history instead of hand-rolling audit tables.
55
- 8. Wrap `mergeVersion()` in `try/catch` whenever conflicts are possible.
55
+ 8. Wrap `mergeBranch()` in `try/catch` whenever conflicts are possible.
56
56
 
57
57
  ## Core Rules
58
58
 
@@ -65,9 +65,9 @@ Do not use this skill for raw SQLite access, private engine/wasm internals, SDK
65
65
  - Do not call `execute()` through the parent `lix` handle while a transaction is active; use the transaction handle for reads and writes until `commit()` or `rollback()`.
66
66
  - Use stable, namespaced, lowercase schema keys like `acme_section`, not generic names like `task`.
67
67
  - Always include `x-lix-primary-key` and `additionalProperties: false` on app schemas.
68
- - Use version names from the user's vocabulary, such as `"Marketing edit"` or `"Q3 pricing draft"`.
68
+ - Use branch names from the user's vocabulary, such as `"Marketing edit"` or `"Q3 pricing draft"`.
69
69
  - Model concurrent-edit domains as collections of small rows because merge is per-row today.
70
- - Prefer `_by_version` tables for demos, sync, agent inspection, and side-by-side diffs.
70
+ - Prefer `_by_branch` tables for demos, sync, agent inspection, and side-by-side diffs.
71
71
  - Close handles in scripts and tests with `await lix.close()`.
72
72
 
73
73
  ## Install And Open
@@ -108,9 +108,9 @@ Use the version of this skill that ships with the installed `@lix-js/sdk` packag
108
108
 
109
109
  Useful installed-package references:
110
110
 
111
- - `dist-engine-src/src/sql2/entity_provider.rs` - registered schema SQL surfaces.
112
- - `dist-engine-src/src/sql2/change_provider.rs` - `lix_change` projection.
113
- - `dist-engine-src/src/sql2/version_provider.rs` - writable `lix_version` surface.
111
+ - `dist-engine-src/src/sql2/providers/entity.rs` - registered schema SQL surfaces.
112
+ - `dist-engine-src/src/sql2/providers/change.rs` - `lix_change` projection.
113
+ - `dist-engine-src/src/sql2/providers/branch.rs` - writable `lix_branch` surface.
114
114
  - `dist-engine-src/src/transaction/validation.rs` - primary-key, unique, foreign-key, and shape validation.
115
115
  - `dist-engine-src/src/schema/definition.json` - Lix schema-definition meta-schema.
116
116
  - `dist-engine-src/src/schema/builtin/` - built-in entity table shapes.
@@ -255,11 +255,11 @@ Schema basics:
255
255
 
256
256
  - `x-lix-key` becomes the generated SQL table name.
257
257
  - Compatible schema amendments are keyed by `x-lix-key`.
258
- - `x-lix-primary-key` tells Lix how to derive entity identity.
258
+ - `x-lix-primary-key` tells Lix how to derive `entity_pk`.
259
259
  - Primary-key entries are JSON Pointers with a leading slash, such as `["/id"]` or `["/owner/email"]`.
260
260
  - Use `additionalProperties: false` so accidental fields fail fast.
261
261
 
262
- Without `x-lix-primary-key`, table-style INSERTs fail with an error like `requires lixcol_entity_id because the schema has no x-lix-primary-key`.
262
+ Without `x-lix-primary-key`, table-style INSERTs fail with an error like `requires lixcol_entity_pk because the schema has no x-lix-primary-key`.
263
263
 
264
264
  Uniqueness is not inferred from ordinary JSON Schema fields. If a non-primary-key field must be unique, declare it explicitly:
265
265
 
@@ -284,7 +284,7 @@ Discover live schemas before guessing:
284
284
 
285
285
  ```ts
286
286
  const schemas = await lix.execute(
287
- "SELECT lixcol_entity_id, value FROM lix_registered_schema ORDER BY lixcol_entity_id",
287
+ "SELECT lixcol_entity_pk, value FROM lix_registered_schema ORDER BY lixcol_entity_pk",
288
288
  );
289
289
 
290
290
  for (const row of schemas.rows) {
@@ -293,58 +293,58 @@ for (const row of schemas.rows) {
293
293
  }
294
294
  ```
295
295
 
296
- ## Versions And `_by_version`
296
+ ## Branches And `_by_branch`
297
297
 
298
- Capture the initial active version id instead of hardcoding `"main"`:
298
+ Capture the initial active branch id instead of hardcoding `"main"`:
299
299
 
300
300
  ```ts
301
- const published = await lix.activeVersionId();
301
+ const published = await lix.activeBranchId();
302
302
  ```
303
303
 
304
- Create versions with names from the user's domain:
304
+ Create branches with names from the user's domain:
305
305
 
306
306
  ```ts
307
- const marketing = await lix.createVersion({ name: "Marketing edit" });
308
- const legal = await lix.createVersion({ name: "Legal review" });
307
+ const marketing = await lix.createBranch({ name: "Marketing edit" });
308
+ const legal = await lix.createBranch({ name: "Legal review" });
309
309
  ```
310
310
 
311
- Every registered schema `X` gets a sibling table `X_by_version` with `lixcol_version_id`. Use it for side-by-side reads and for writes to non-active versions.
311
+ Every registered schema `X` gets a sibling table `X_by_branch` with `lixcol_branch_id`. Use it for side-by-side reads and for writes to non-active branches.
312
312
 
313
313
  ```ts
314
314
  await lix.execute(
315
- `UPDATE acme_note_by_version
315
+ `UPDATE acme_note_by_branch
316
316
  SET title = $1
317
- WHERE id = $2 AND lixcol_version_id = $3`,
317
+ WHERE id = $2 AND lixcol_branch_id = $3`,
318
318
  ["Sharper launch copy", "n1", marketing.id],
319
319
  );
320
320
 
321
321
  const sideBySide = await lix.execute(
322
322
  `SELECT v.name, n.title
323
- FROM acme_note_by_version n
324
- JOIN lix_version v ON v.id = n.lixcol_version_id
323
+ FROM acme_note_by_branch n
324
+ JOIN lix_branch v ON v.id = n.lixcol_branch_id
325
325
  WHERE n.id = $1
326
- AND n.lixcol_version_id IN ($2, $3)
326
+ AND n.lixcol_branch_id IN ($2, $3)
327
327
  ORDER BY v.name`,
328
328
  ["n1", published, marketing.id],
329
329
  );
330
330
  ```
331
331
 
332
- Rules for `_by_version`:
332
+ Rules for `_by_branch`:
333
333
 
334
- - Reads filter by `lixcol_version_id`, or omit the filter to scan all versions.
335
- - INSERTs require `lixcol_version_id`.
336
- - UPDATEs and DELETEs must include `lixcol_version_id` in the WHERE clause.
337
- - The non-suffixed table is the active-version view.
334
+ - Reads filter by `lixcol_branch_id`, or omit the filter to scan all branches.
335
+ - INSERTs require `lixcol_branch_id`.
336
+ - UPDATEs and DELETEs must include `lixcol_branch_id` in the WHERE clause.
337
+ - The non-suffixed table is the active-branch view.
338
338
 
339
- `switchVersion()` is for app code with a current working version concept. `mergeVersion()` always merges into the active version, so switch first if you need a different target.
339
+ `switchBranch()` is for app code with a current working branch concept. `mergeBranch()` always merges into the active branch, so switch first if you need a different target.
340
340
 
341
341
  ## Merging
342
342
 
343
- `mergeVersion()` merges the source version into the currently active version:
343
+ `mergeBranch()` merges the source branch into the currently active branch:
344
344
 
345
345
  ```ts
346
346
  try {
347
- const merge = await lix.mergeVersion({ sourceVersionId: marketing.id });
347
+ const merge = await lix.mergeBranch({ sourceBranchId: marketing.id });
348
348
  console.log(merge.outcome, merge.changeStats.total);
349
349
  } catch (error) {
350
350
  console.error("Merge conflict", error);
@@ -357,18 +357,18 @@ Common outcomes:
357
357
  - `"fastForward"` - target advanced to source without a merge commit.
358
358
  - `"mergeCommitted"` - a new merge commit was created.
359
359
 
360
- `mergeVersionPreview()` reports the same merge decision without advancing refs, staging changes, or creating commits. Merge conflicts are returned as preview data.
360
+ `mergeBranchPreview()` reports the same merge decision without advancing refs, staging changes, or creating commits. Merge conflicts are returned as preview data.
361
361
 
362
- Conflicts throw from `mergeVersion()`. If both versions modified the same entity since their merge base, Lix raises a `LixError`. Conflict detection is row-level today, not field-level. To reproduce a conflict in a demo, fork all contending versions from the same base before merging any of them.
362
+ Conflicts throw from `mergeBranch()`. If both branches modified the same entity since their merge base, Lix raises a `LixError`. Conflict detection is row-level today, not field-level. To reproduce a conflict in a demo, fork all contending branches from the same base before merging any of them.
363
363
 
364
364
  ## Demo Pattern To Imitate
365
365
 
366
366
  For richer demos, show these four things:
367
367
 
368
- 1. Isolation: one SELECT against `<schema>_by_version` shows several versions side by side.
368
+ 1. Isolation: one SELECT against `<schema>_by_branch` shows several branches side by side.
369
369
  2. Clean parallel merges: two reviewers edit different entities and both land.
370
370
  3. Audit history: `lix_change` is queryable SQL.
371
- 4. Conflict handling: two versions edit the same entity and `mergeVersion()` throws.
371
+ 4. Conflict handling: two branches edit the same entity and `mergeBranch()` throws.
372
372
 
373
373
  Shape the domain as a collection of small entities:
374
374
 
@@ -378,20 +378,20 @@ Shape the domain as a collection of small entities:
378
378
  Demo recipe:
379
379
 
380
380
  1. Register a schema such as `acme_section`.
381
- 2. Seed several rows in the published version.
382
- 3. Create all reviewer versions up front from the same base.
383
- 4. Write each reviewer's changes through `acme_section_by_version`.
384
- 5. Read side by side by joining `acme_section_by_version` to `lix_version`.
381
+ 2. Seed several rows in the published branch.
382
+ 3. Create all reviewer branches up front from the same base.
383
+ 4. Write each reviewer's changes through `acme_section_by_branch`.
384
+ 5. Read side by side by joining `acme_section_by_branch` to `lix_branch`.
385
385
  6. Merge non-overlapping row edits successfully.
386
386
  7. Query `lix_change`.
387
387
  8. Catch the deliberate same-row conflict.
388
388
 
389
389
  ## Files With `lix_file`
390
390
 
391
- `lix_file` stores files as versioned bytes. Parent directories are created automatically.
391
+ `lix_file` stores files as branched bytes. Parent directories are created automatically.
392
392
 
393
393
  ```ts
394
- await lix.execute("INSERT INTO lix_file (id, path, data) VALUES ($1, $2, $3)", [
394
+ await lix.execute("INSERT INTO lix_file (id, path, data, hidden) VALUES ($1, $2, $3, false)", [
395
395
  "file-readme",
396
396
  "/docs/readme.md",
397
397
  new TextEncoder().encode("# Hello\n"),
@@ -417,29 +417,30 @@ Columns consumers usually need:
417
417
  | `path` | Absolute path like `/docs/readme.md`. |
418
418
  | `data` | File contents as bytes. |
419
419
  | `hidden` | UI hint; does not affect storage. |
420
- | `lixcol_*` | Version/change metadata, including `lixcol_version_id` where exposed. |
420
+ | `lixcol_*` | Branch/change metadata, including `lixcol_branch_id` where exposed. |
421
421
 
422
- `lix_file_by_version` exists for cross-version file reads and writes. Files-as-parsed-entities are product direction, not current JS SDK behavior.
422
+ `lix_file_by_branch` exists for cross-branch file reads and writes. Files-as-parsed-entities are product direction, not current JS SDK behavior.
423
423
 
424
424
  ## The Change Journal
425
425
 
426
- `lix_change` is an immutable SQL table of changes across registered schemas and versions. Use it for audit logs, blame, history, activity feeds, and undo-style UI.
426
+ `lix_change` is an immutable SQL table of changes across registered schemas and branches. Use it for audit logs, blame, history, activity feeds, and undo-style UI.
427
427
 
428
- Important columns include `id`, `entity_id`, `schema_key`, `snapshot_content`, `created_at`, and `lixcol_*` metadata.
428
+ Important columns include `id`, `entity_pk`, `schema_key`, `snapshot_content`, `created_at`, and `lixcol_*` metadata.
429
429
 
430
430
  ```ts
431
431
  // Audit log for one entity, oldest to newest.
432
432
  await lix.execute(
433
433
  `SELECT created_at, snapshot_content
434
434
  FROM lix_change
435
- WHERE schema_key = $1 AND entity_id = $2
435
+ WHERE schema_key = $1
436
+ AND lix_json_get_text(entity_pk, 0) = $2
436
437
  ORDER BY created_at`,
437
438
  ["acme_note", "n1"],
438
439
  );
439
440
 
440
441
  // Latest activity across a schema.
441
442
  await lix.execute(
442
- `SELECT created_at, entity_id, snapshot_content
443
+ `SELECT created_at, entity_pk, snapshot_content
443
444
  FROM lix_change
444
445
  WHERE schema_key = $1
445
446
  ORDER BY created_at DESC
@@ -456,20 +457,20 @@ Common tables:
456
457
 
457
458
  | Table | What it gives consumers |
458
459
  | ----------------------- | ------------------------------------------------------------------------------------------------------- |
459
- | `lix_version` | Writable version surface: `id`, `name`, `hidden`, `commit_id`. |
460
+ | `lix_branch` | Writable branch surface: `id`, `name`, `hidden`, `commit_id`. |
460
461
  | `lix_change` | Immutable change journal. |
461
- | `lix_file` | Versioned byte storage for files. |
462
+ | `lix_file` | Branched byte storage for files. |
462
463
  | `lix_registered_schema` | Registry of app schemas plus built-ins; also exposes the Lix schema-definition meta-schema at runtime. |
463
464
 
464
- `lix_version` can be updated for admin flows:
465
+ `lix_branch` can be updated for admin flows:
465
466
 
466
467
  ```ts
467
- await lix.execute("UPDATE lix_version SET hidden = true WHERE id = $1", [
468
+ await lix.execute("UPDATE lix_branch SET hidden = true WHERE id = $1", [
468
469
  marketing.id,
469
470
  ]);
470
471
  ```
471
472
 
472
- There is no documented `deleteVersion()` helper in this preview. If the product wants reversible cleanup, hide the version. If it wants removal, `DELETE FROM lix_version WHERE id = $1` is the SQL surface; the engine rejects deleting the global version and active version.
473
+ There is no documented `deleteBranch()` helper in this preview. If the product wants reversible cleanup, hide the branch. If it wants removal, `DELETE FROM lix_branch WHERE id = $1` is the SQL surface; the engine rejects deleting the global branch and active branch.
473
474
 
474
475
  Use `lix_json($1)` to parse JSON text parameters when writing JSON-typed columns:
475
476
 
@@ -492,12 +493,12 @@ Other UDFs, such as `lix_json_get`, `lix_uuid_v7`, `lix_text_encode`, and `lix_e
492
493
  | Use `lix_json($1)` for JSON parameters. | Inlining stringified JSON directly into SQL. |
493
494
  | Use `beginTransaction()` for imports and batch writes that should be one commit. | Loops of standalone `lix.execute()` writes for bulk imports. |
494
495
  | Use the transaction handle for reads and writes until it commits or rolls back. | Calling parent-handle `execute()` during an active transaction. |
495
- | Use `_by_version` for cross-version reads/writes. | Switching versions just to render a side-by-side view. |
496
- | Name versions in user vocabulary. | User-facing words like branch, branch-1, or generic Draft. |
496
+ | Use `_by_branch` for cross-branch reads/writes. | Switching branches just to render a side-by-side view. |
497
+ | Name branches in user vocabulary. | User-facing words like branch, branch-1, or generic Draft. |
497
498
  | Model collaborative data as small rows. | One giant row when multiple reviewers edit different parts. |
498
499
  | Add `x-lix-unique` for non-primary unique fields. | Assuming JSON Schema property metadata creates uniqueness. |
499
500
  | Read `snapshot_content` as JSON/native and handle null. | Blindly `JSON.parse(row.value(...).asText())`. |
500
- | Wrap `mergeVersion()` in `try/catch`. | Assuming merges cannot conflict. |
501
+ | Wrap `mergeBranch()` in `try/catch`. | Assuming merges cannot conflict. |
501
502
 
502
503
  ## Reporting SDK Friction
503
504
 
@@ -178,8 +178,7 @@ function isJsonValue(value) {
178
178
  }
179
179
  }
180
180
  function normalizeJsonValue(value, seen = new WeakSet()) {
181
- if (value === null ||
182
- typeof value === "boolean") {
181
+ if (value === null || typeof value === "boolean") {
183
182
  return value;
184
183
  }
185
184
  if (typeof value === "string") {
@@ -272,9 +271,10 @@ function base64ToBytes(base64) {
272
271
  const engineWasmUrl = new URL("./wasm/lix_engine.wasm", import.meta.url);
273
272
  function isNodeRuntime() {
274
273
  const processLike = globalThis.process;
274
+ const runtimeBranches = processLike?.["ver" + "sions"];
275
275
  return (!!processLike &&
276
- typeof processLike.versions === "object" &&
277
- !!processLike.versions?.node);
276
+ typeof runtimeBranches === "object" &&
277
+ !!runtimeBranches?.node);
278
278
  }
279
279
  async function tryReadNodeFileFromViteHttpUrl(url) {
280
280
  if (url.protocol !== "http:" && url.protocol !== "https:") {
@@ -11,7 +11,7 @@ export class Lix {
11
11
  /**
12
12
  * @returns {Promise<string>}
13
13
  */
14
- activeVersionId(): Promise<string>;
14
+ activeBranchId(): Promise<string>;
15
15
  /**
16
16
  * @returns {Promise<LixTransaction>}
17
17
  */
@@ -24,7 +24,7 @@ export class Lix {
24
24
  * @param {any} args
25
25
  * @returns {Promise<any>}
26
26
  */
27
- createVersion(args: any): Promise<any>;
27
+ createBranch(args: any): Promise<any>;
28
28
  /**
29
29
  * Executes one DataFusion SQL statement against this Lix session.
30
30
  *
@@ -42,17 +42,17 @@ export class Lix {
42
42
  * @param {any} args
43
43
  * @returns {Promise<any>}
44
44
  */
45
- mergeVersion(args: any): Promise<any>;
45
+ mergeBranch(args: any): Promise<any>;
46
46
  /**
47
47
  * @param {any} args
48
48
  * @returns {Promise<any>}
49
49
  */
50
- mergeVersionPreview(args: any): Promise<any>;
50
+ mergeBranchPreview(args: any): Promise<any>;
51
51
  /**
52
52
  * @param {any} args
53
53
  * @returns {Promise<any>}
54
54
  */
55
- switchVersion(args: any): Promise<any>;
55
+ switchBranch(args: any): Promise<any>;
56
56
  }
57
57
  export class LixTransaction {
58
58
  static __wrap(ptr: any): any;